Pahom on Water

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 772    Accepted Submission(s):
355

Problem Description
Pahom on Water is an interactive computer game inspired
by a short story of Leo Tolstoy about a poor man who, in his lust for land,
forfeits everything. The game's starting screen displays a number of circular
pads painted with colours from the visible light spectrum. More than one pad may
be painted with the same colour (defined by a certain frequency) except for the
two colours red and violet. The display contains only one red pad (the lowest
frequency of 400 THz) and one violet pad (the highest frequency of 789 THz). A
pad may intersect, or even contain another pad with a different colour but never
merely touch its boundary. The display also shows a figure representing Pahom
standing on the red pad.
The game's objective is to walk the figure of Pahom
from the red pad to the violet pad and return back to the red pad. The walk must
observe the following rules:
1.If pad α and pad β have a common intersection
and the frequency of the colour of pad α is strictly smaller than the frequency
of the colour of pad β, then Pahom figure can walk from α to β during the walk
from the red pad to the violet pad
2. If pad α and pad β have a common
intersection and the frequency of the colour of pad α is strictly greater than
the frequency of the colour of pad β, then Pahom figure can walk from α to β
during the walk from the violet pad to the red pad
3. A coloured pad, with
the exception of the red pad, disappears from display when the Pahom figure
walks away from it.
The developer of the game has programmed all the
whizzbang features of the game. All that is left is to ensure that Pahom has a
chance to succeed in each instance of the game (that is, there is at least one
valid walk from the red pad to the violet pad and then back again to the red
pad.) Your task is to write a program to check whether at least one valid path
exists in each instance of the game.
 
Input
The input starts with an integer K (1 <= K <= 50)
indicating the number of scenarios on a line by itself. The description for each
scenario starts with an integer N (2 <= N <= 300) indicating the number of
pads, on a line by itself, followed by N lines that describe the colors,
locations and sizes of the N pads. Each line contains the frequency, followed by
the x- and y-coordinates of the pad's center and then the radius. The frequency
is given as a real value with no more than three decimal places. The coordinates
and radius are given, in meters, as integers. All values are separated by a
single space. All integer values are in the range of -10,000 to 10,000
inclusive. In each scenario, all frequencies are in the range of 400.0 to 789.0
inclusive. Exactly one pad will have a frequency of “400.0” and exactly one pad
will have a frequency of “789.0”.
 
Output
The output for each scenario consists of a single line
that contains: Game is VALID, or Game is NOT VALID
 
Sample Input
2
2
400.0 0 0 4
789.0 7 0 2
4
400.0 0 0 4
789.0 7 0 2
500.35 5 0 2
500.32 5 0 3
 
Sample Output
Game is NOT VALID
Game is VALID
 
题意:一个电脑游戏,有各种颜色的光圈,题目要求你从红色光圈到紫色光圈再回到红色光圈(中间可已经经过其他颜色的光圈)光圈形状为圆形
要求:1、如果两个光圈相交,则可以从光谱大的走到光谱小的
2、紫色光圈和红色光圈可以走两次,别的颜色的只能走一次
问是否能够实现要求
题解:建立超级源点0,超级汇点n+1
1、紫色光圈连接源点权值为2
2、红色光圈连接汇点权值为2
3、其他颜色光圈  光谱大的连接到光谱小的,权值为1;
如果最大流为2则可以完成,
 
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<math.h>
  4. #include<queue>
  5. #include<stack>
  6. #include<algorithm>
  7. #define INF 0x7ffffff
  8. #define MAX 10010
  9. #define MAXM 100100
  10. #define eps 1e-5
  11. #define DD double
  12. using namespace std;
  13. DD pad[MAX],x[MAX],y[MAX],r[MAX];
  14. struct node
  15. {
  16. int from,to,cap,flow,next;
  17. }edge[MAXM];
  18. int vis[MAX],dis[MAX];
  19. int cur[MAX];
  20. int head[MAX],ans;
  21. void init()
  22. {
  23. ans=0;
  24. memset(head,-1,sizeof(head));
  25. }
  26. void add(int u,int v,int w)
  27. {
  28. edge[ans]={u,v,w,0,head[u]};
  29. head[u]=ans++;
  30. edge[ans]={v,u,0,0,head[v]};
  31. head[v]=ans++;
  32. }
  33. int judge(int i,int j)//判断两个光谱是否相交
  34. {
  35. if((sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))-r[i]-r[j])<0)
  36. return 1;
  37. return 0;
  38. }
  39. int bfs(int beg,int end)
  40. {
  41. memset(vis,0,sizeof(vis));
  42. memset(dis,-1,sizeof(dis));
  43. queue<int>q;
  44. while(!q.empty())
  45. q.pop();
  46. q.push(beg);
  47. vis[beg]=1;
  48. dis[beg]=0;
  49. while(!q.empty())
  50. {
  51. int u=q.front();
  52. q.pop();
  53. for(int i=head[u];i!=-1;i=edge[i].next)
  54. {
  55. node E=edge[i];
  56. if(!vis[E.to]&&E.cap>E.flow)
  57. {
  58. dis[E.to]=dis[u]+1;
  59. vis[E.to]=1;
  60. if(E.to==end) return 1;
  61. q.push(E.to);
  62. }
  63. }
  64. }
  65. return 0;
  66. }
  67. int dfs(int x,int a,int end)
  68. {
  69. if(a==0||x==end)
  70. return a;
  71. int flow=0,f;
  72. for(int &i=cur[x];i!=-1;i=edge[i].next)
  73. {
  74. node& E=edge[i];
  75. if(dis[E.to]==dis[x]+1&&(f=dfs(E.to,min(a,E.cap-E.flow),end))>0)
  76. {
  77. E.flow+=f;
  78. edge[i^1].flow-=f;
  79. flow+=f;
  80. a-=f;
  81. if(a==0) break;
  82. }
  83. }
  84. return flow;
  85. }
  86. int Maxflow(int beg,int end)
  87. {
  88. int flow=0;
  89. while(bfs(beg,end))
  90. {
  91. memcpy(cur,head,sizeof(head));
  92. flow+=dfs(beg,INF,end);
  93. }
  94. return flow;
  95. }
  96. int main()
  97. {
  98. int t,n,m,i,j;
  99. scanf("%d",&t);
  100. while(t--)
  101. {
  102. scanf("%d",&n);
  103. init();
  104. for(i=1;i<=n;i++)
  105. scanf("%lf%lf%lf%lf",&pad[i],&x[i],&y[i],&r[i]);
  106. for(i=1;i<=n;i++)
  107. {
  108. if(fabs(pad[i]-789.0)<=eps)//紫色光圈连接源点
  109. add(0,i,2);
  110. if(fabs(pad[i]-400.0)<=eps)//红则光谱连接汇点
  111. add(i,n+1,2);
  112. for(j=1;j<=n;j++)
  113. {
  114. if(i!=j)//判断到同一个光圈时跳过
  115. {
  116. if(judge(i,j)&&pad[i]>pad[j])//光圈相交且第一个的光普大
  117. {
  118. add(i,j,1);
  119. }
  120. }
  121. }
  122. }
  123. if(Maxflow(0,n+1)==2)
  124. printf("Game is VALID\n");
  125. else
  126. printf("Game is NOT VALID\n");
  127. }
  128. return 0;
  129. }

  

hdoj 4183 Pahom on Water的更多相关文章

  1. HDU 4183 Pahom on Water(最大流SAP)

    Pahom on Water Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  2. 【HDOJ】4183 Pahom on Water

    就是一个网络流.red结点容量为2,查看最大流量是否大于等于2.对于条件2,把边反向加入建图.条件1,边正向加入建图. /* 4183 */ #include <iostream> #in ...

  3. HDU 4183 Pahom on Water(最大流)

    https://vjudge.net/problem/HDU-4183 题意: 这道题目的英文实在是很难理解啊. 给出n个圆,每个圆有频率,x.y轴和半径r4个属性,每次将频率为400的圆作为起点,频 ...

  4. Pahom on Water(最大流)

    Pahom on Water Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  5. HDOJ 4974 A simple water problem

    A simple water problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  6. HDU4183 Pahom on Water(来回走最大流,一个点只经过一次)

    题意: 有n个圆,每个圆的中心和半径和一个频率都给定,只有一个频率最高的789为紫色,只有一个最低的400为红色,规则如下: 1.当两个圆严格相交时,且人是从红色到紫色的方向运动时可以由低频率向高频率 ...

  7. hdu 4183 EK最大流算法

    欢迎参加——每周六晚的BestCoder(有米!) Pahom on Water Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327 ...

  8. hdu 4183(网络流)

    Pahom on Water Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  9. HDOJ 4009 Transfer water 最小树形图

    Transfer water Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) T ...

随机推荐

  1. H2O与Java线程同步

    Java 5以前的线程同步采用syncronized和wait,notify,notifyAll来实现,比较粗糙.之后有了Lock和Condition.ReentrantLock的简单lock,unl ...

  2. ANDROID_MARS学习笔记_S01原始版_009_SQLite

    一.代码1.xml(1)activity_main.xml <?xml version="1.0" encoding="utf-8"?> <L ...

  3. 【Linux安全】防止 root 用户远程登录

    防止 root 用户远程登录,在终端输入以下命令: vim /etc/ssh/sshd_config 修改如下行为:no PermitRootLogin no 如图所示:

  4. XML和JSON 序列化以及DataTable转JSON

    using System.IO; using System.Text; using System.Xml.Serialization; using System.Xml; using System.R ...

  5. webstore+nodejs

    新建一个普通的project. 编写如下代码: var http=require('http'); http.createServer(function(req,res){ res.writeHead ...

  6. APP-PER-50022: Oracle Human Resources could not retrieve a value for the User Type profile option.

    Symptoms ----------------------- AP > Setup > Organizations Show Error tips: APP-PER-50022: Or ...

  7. Using innodb_large_prefix to avoid ERROR #1071,Specified key was too long; max key length is 1000 bytes

    Using innodb_large_prefix to avoid ERROR 1071        单列索引限制上面有提到单列索引限制767,起因是256×3-1.这个3是字符最大占用空间(ut ...

  8. hadoop异常: 到目前为止解决的最牛逼的一个异常(java.io.IOException: Incompatible clusterIDs)

    (注意: 本人用的版本为hadoop2.2.0, 旧的版本和此版本的解决方法不同) 异常为: 9 (storage id DS-2102177634-172.16.102.203-50010-1384 ...

  9. 为什么你的 phpinfo() 无法显示

    一.问题描述 编写了一个php文件test.php,代码如下: <?php echo phpinfo(); ?> 浏览器访问了一下,却返回了 NULL. 二.问题定位及解决 网上查了下,大 ...

  10. c#桥接模式(bridge结构模式)

    桥接模式(bridge结构模式)c#简单例子 在前面的玩家中每增加一个行为,就必须在每个玩家中都增加,通过桥接模式将行为提取出来了,减少变化 ? 1 2 3 4 5 6 7 8 9 10 11 12 ...