The 2013 ACMICPC Asia Regional Chengdu

还有19天出发北京站,今年北京站的出题方是上交,去年他们出的成都现场的赛题,首先复盘一下。

去年的成都是我经历的第一次现场赛,也是近距离第一次见到了CLJ的真人,最后也是被虐惨了,那时候是声闻大神带着我们去的,也是在那次现场之后,深深地感受到了差距。现在我们进步了,只可惜选手都在发展,比赛也在发展,别人大概是进步得更多吧,上场西安赛站也只能遗憾。

没想到最后一场居然又能碰到开场第一次能够遇上的出题方,也是个奇妙的巧合吧。

 

【A】构造图

【B】模拟

【C】-_-///

【D】BFS(写的时候遇到一个大坑)

【E】计算几何

【F】构造生成树

【G】在线AC自动机

【H】签到题

【I】模拟(用STL中的set)

【J】数论

 

----------------------------------------------------

 

【A】 HDU 4781

Assignment For Princess

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) 

Special Judge

【Problem Description】
  Long long ago, in the Kingdom Far Far Away, there lived many little animals. And you are the beloved princess who is marrying the prince of a rich neighboring kingdom. The prince, who turns out to be a handsome guy, offered you a golden engagement ring that can run computer programs!
  The wedding will be held next summer because your father, the king, wants you to finish your university first.
  But you did’t even have a clue on your graduation project. Your terrible project was to construct a map for your kingdom. Your mother, the queen, wanted to make sure that you could graduate in time.
  Or your wedding would have to be delayed to the next winter. So she told you how your ancestors built the kingdom which is called the Roads Principle:
  1. Your kingdom consists of N castles and M directed roads.   
  2. There is at most one road between a pair of castles.   
  3. There won’t be any roads that start at one castle and lead to the same one.
  She hoped those may be helpful to your project. Then you asked your cousin Coach Pang (Yes, he is your troubling cousin, he always asks you to solve all kinds of problems even you are a princess.), the Minister of Traffic, about the castles and roads. Your cousin, sadly, doesn’t have a map of the kingdom. Though he said the technology isn’t well developed and it depends on your generation to contribute to the map, he told you the Travelers Guide, the way travelers describe the amazing road system:   
  1. No matter which castle you start with, you can arrive at any other castles.   
  2. Traveling on theM roads will take 1, 2, 3, ... ,M days respectively, no two roads need the same number of days.   
  3. You can take a round trip starting at any castle, visiting a sequence of castles, perhaps visiting some castles or traveling on some roads more than once, and finish your journey where you started.   
  4. The total amount of days spent on any round trip will be a multiple of three.   
  But after a month, you still couldn’t make any progress. So your brother, the future king, asked your university to assign you a simpler project. And here comes the new requirements. Construct a map that satisfies both the Roads Principle and the Travelers Guide when N and M is given.   
  There would probably be several solutions, but your project would be accepted as long as it meets the two requirements. Now the task is much easier, furthermore your fiance sent two assistants to help you.   
      Perhaps they could finish it within 5 hours and you can think of your sweet wedding now.
【Input】
  The first line contains only one integer T, which indicates the number of test cases.   For each test case, there is one line containing two integers N, M described above.(10 <= N <= 80, N+3 <= M <= N2/7 )
【Output】
  For each test case, first output a line “Case #x:”, where x is the case number (starting from 1).   
  Then output M lines for each test case. Each line contains three integers A, B, C separated by single space, which denotes a road from castle A to castle B and the road takes C days traveling.   
  Oh, one more thing about your project, remember to tell your mighty assistants that if they are certain that no map meets the requirements, print one line containing one integer -1 instead.   
  Note that you should not print any trailing spaces.
【Sample Input】
1
6 8

【Sample Output】

Case #1:
1 2 1
2 3 2
2 4 3
3 4 4
4 5 5
5 6 7
5 1 6
6 1 8

【Hint】
      The restrictions like N >= 10 will be too big for a sample. So the sample is just a simple case for the detailed formats of input and output,
and it may be helpful for a better understanding. Anyway it won’t appear in actual test cases.

【题意】
要求构造一张图,同时满足以下7个条件:
1.有n个点和m条有向边;
2.两点点之间无重边;
3.无自环;
4.整张图都是连通的;
5.m条边的长度分别为1、2、...、m;
6.从任意一点出发都能够回到出发点,点和边可多次经过。
7.每一次Travel走过的总长度都一定是3的倍数。
【分析】
前面几个条件都是对图的基本性质的保证。从一次Traval可重复经过点和边的性质+Travel总长度是3的倍数这两个条件入手,分析一下即所有有向环的总长都是3的倍数。
首先构造一个简单的回路,从1至n每两点依次连边,这样就用掉了1~n-1,第n条边放上n、n+1或者n+2使得第一个环总长为三的倍数。
接下来就是把剩下那些边放到图中去了,然后需要的是在放边的同时保持原有的图的性质不变。设下一条要放上去的边长为x,dist[i][j]表示点i与点j之间的路径长度,则(dist[i][j]+dist[j][i])%3==0,也即dist[i][j]%3+dist[j][i]%3==3。则对于x,找到两个点i、j使得dist[i][j]%3==x%3,则在i、j之间加上边x之后x就能够替代原来的长边,构成一个新的总长为3的倍数的有向环。依次解决完所有的剩余边即可。
 1 /* ***********************************************
 2 MYID    : Chen Fan
 3 LANG    : G++
 4 PROG    : HDU 4781
 5 ************************************************ */
 6 
 7 #include <iostream>
 8 #include <cstdio>
 9 #include <cstring>
10 
11 using namespace std;
12 
13 int mapl[81][81],dist[81][81];
14 bool use[81];
15 
16 int main()
17 {
18     int t,n,m;
19     scanf("%d",&t);
20     for (int tt=1;tt<=t;tt++)
21     {
22         printf("Case #%d:\n",tt);
23         scanf("%d%d",&n,&m);
24         int tot=0;
25         bool bq=false;
26         memset(mapl,0,sizeof(mapl));
27         memset(dist,-1,sizeof(dist));
28         
29         for (int i=1;i<n;i++)
30         {
31             tot+=i;
32             mapl[i][i+1]=i;
33             dist[i][i+1]=i;
34         }
35         
36         for (int i=n;i<n+3;i++)
37         if ((tot+i)%3==0)
38         {
39             mapl[n][1]=i;
40             dist[n][1]=i;
41             break;
42         }
43         
44         memset(use,0,sizeof(use));
45         use[mapl[n][1]]=true;
46         
47         for (int i=1;i<=n;i++)
48         for (int j=1;j<=n;j++)
49         if (i!=j)
50         for (int k=1;k<=n;k++)
51         if (i!=k&&j!=k)
52         if (dist[j][i]>0&&dist[i][k]>0)
53         if (dist[j][k]==-1) dist[j][k]=dist[j][i]+dist[i][k];
54         
55         for (int i=1;i<=n;i++)
56         for (int j=1;j<=n;j++) 
57         if (dist[i][j]>-1) dist[i][j]%=3;
58         
59         //for (int i=1;i<=n;i++)
60         //for (int j=1;j<=n;j++) printf("%d %d %d\n",i,j,dist[i][j]);
61         
62         for (int i=n;i<=m;i++)
63         {
64             if (!use[i])
65             {
66                 for (int j=1;j<=n;j++)
67                 for (int k=1;k<=n;k++)
68                 if (!use[i])
69                 if (mapl[j][k]==0&&mapl[k][j]==0&&dist[j][k]>-1&&dist[j][k]%3==i%3)
70                 {
71                     mapl[j][k]=i;
72                     use[i]=true;
73                 }
74             }
75             if (!use[i]) 
76             {
77                 printf("-1\n");
78                 bq=true;
79                 break;
80             }
81         }
82         
83         if (!bq)
84         for (int i=1;i<=n;i++)
85         for (int j=1;j<=n;j++)
86         if (mapl[i][j]>0) printf("%d %d %d\n",i,j,mapl[i][j]);
87     }
88     
89     return 0;
90 }
View Code

 

 
 
【D】 HDU 4784

Dinner Coming Soon

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)
【Problem Description】
  Coach Pang loves his boyfriend Uncle Yang very much. Today is Uncle Yang’s birthday, Coach Pang wants to have a romantic candlelit dinner at Uncle Yang’s house and he has to arrive there in T minutes.   
  There are N houses in their city numbered from 1 to N. Coach Pang lives in house 1 while Uncle Yang lives in house N. The houses are connected byM directed roads. It takes some time and usually a fee to pass one road. Coach Pang wants to reach Uncle Yang’s house before the dinner starts with as much money as possible.   
  But the matter is not so simple. Coach Pang decides to do some salt trade on the way to Uncle Yang’s house. The host of each house offers a price of a bag of salt, so Coach Pang can make a profit from the price differences. Each time when Coach Pang arrives at a house (except the house 1 and the house N). He can buy one bag of salt, sell one bag of salt or do nothing. Coach Pang can carry at most B bags of salt with him, and he carries no salt when he leaves his house. The trading is so efficient that the time cost of trading can be ignored.   
  However, the problem is more complicated than imagine. Coach Pang has a handheld device that can perform a journey around K parallel universes numbered from 0 to K-1. Coach Pang lives in the universe 0. When Coach Pang uses the device in universe i, he will be transported to the same place and the same time of universe (i+1) modK. The host of the house at the same place in different universe may offer a different price of salt. Luckily, the time cost and fee of the city roads are uniform among the K universes. The journey between universes costs no time but Coach Pang has to stand still watching the ads on the device for one minute every time before the device works. Remember, Coach Pang should never visit house 1 or house N in a universe other than universe 0, because the situation might become uncontrollable if he bumps into himself or his boyfriend in another universe.   
  The time is running out. Coach Pang asks you to tell him whether he can arrive at Uncle Yang’s house in time, and how much money Coach Pang can have at most when the dinner starts. Coach Pang has R yuan at the start, and will end his journey immediately once he arrives at Uncle Yang’s house. He must arrive at Uncle Yang’s house in T minutes, and he can’t have negative amount of money anywhere anytime. Please help him!
【Input】
  The first line of the input is an integer C representing the number of test cases.   
  For each test case, the first line will contain 6 integers N, M, B, K, R, T, as described above.   
  (2 <= N <= 100, 0 <= M <= 200, 1 <= B <= 4, 2 <= K <= 5, 0 <= R <= 105, 0 <= T <= 200)   
  The following K lines contain N integers each, indicating the price pij (0 <= i < K, 1 <= j <= N) for a bag of salt offered by the host of house j in the universe i. The price of house 1 and house N will be marked as -1.(1 <= pij <= 100)   
  Then M lines follow, each contains 4 integers a, b, t and m, indicating that there is a road from house a to house b that costs t minutes of time and m yuan of money. (1 <= a,b <= N,  a<> b, 1 <= t <=15, 0 <= m <= 100)
【Output】
  For each test case, output one line containing “Case #x: y”, where x is the case number (starting from 1) and y is the most money Coach Pang can have if he can have dinner with Uncle Yang on time.   
  Print "Forever Alone" otherwise.
【Sample Input】
2
3 2 1 2 10 6
-1 1 -1
-1 5 -1
1 2 1 0
2 3 1 1
2 2 1 2 5 5
-1 -1
-1 -1
1 2 10 2
1 2 2 10

【Sample Output】

Case #1: 17
Case #2: Forever Alone

【题意】

给出一张有向图,主人公需要在时间T之内从编号为1的点走到编号为n的点。图中存在一个货币系统,主人公在初始状态的时候身上有R单位的货币,在图中除了1和n之外的所有点都可以买进或者卖出一包盐,每一个点的盐价不同,因此主人公可以通过这种方式在不同的位置进行盐的买卖赚取收益。图中的每一条有向边都有两个代价,时间花费和货币花费,而且除此之外这张图中还有K个“平行世界”,分别标记为0~K-1,在每个不同的平行世界中每个点的盐价也不同,主人公可以花费1单位时间从第i个平行世界的某个点中跳跃到第(i+1)%K个平行世界的同一个点上,唯一的限制是1点和n点只能从第0个平行世界中进入,且一旦到达第n点,这次遍历就结束了。

现在,最终的问题就是主人公从1点出发走到n点,身上最多可能持有多少单位的货币。
【分析】

写这道题的时候代码遭遇神坑啊!!!!

 

首先构图非常简单,相对于一般的图,本题只是把普通的单一代价有向边再加上一个代价,平行世界的跳转只是从i跳到(i+1)%k,且花费只有1单位时间。对于图中每一个点的情况,很容易能够想到状态转移方程式,用f(i,j,k,l)表示当前在第i点,花费了j时间,手上持有k包盐,目前在平行世界k的最大持有货币数。出现的位置状态转移只有两种:沿着有向边走向下一个点或者进行平行世界跳转。位置转移完成之后,接下来发生的价值转移有三种,不作任何操作、买入一包盐或者卖出一包盐。大致的方程是这样的,这里省略了一些转移条件:

f(i,j,k,l)=max{ f(p,j+edge[i,p].time,k,l),
f(p,j+edge[i,p].time,k+1,l)-price[l][p],
f(p,j+edge[i,p].time,k-1,l)+price[l][p],
f(i,j+1,k,(l+1)%K),
f(i,j+1,k+1,(l+1)%K)-price[(l+1)%K][i],
f(i,j+1,k-1,(l+1)%K)+price[(l+1)%K][i] }

最直接的想法是使用SPFA作为整体的DP框架,虽然整体数据范围不太大,但是这里反复进出队列的话,超时的可能性非常大。这里DP遇到的最大问题是后效性,关于这一点,我们可以看到状态递推的方向是花费时间增加的方向。普通的SPFA不能保证后面加入队列的状态时间一定是递增的,因此需要反复多次进出队列,所以在这里使用一个花费时间递增的优先队列来替换掉SPFA中的普通队列,保证状态按照花费时间递增的顺序来扩展,就能解决DP的后效性问题,记录一下加入过队列的点不用再次加入即可节省下来大量的时间。

 

写代码的时候因为一点失误被坑了好久......吸取的教训是:DP中后续的六种状态的值必须从原始状态出发!其实这个原本是非常直观的,写到图论的结构里面之后因为代码太多了,居然简单地就直接从1往2、3写,从4往5、6写了。

  1 /* ***********************************************
  2 MYID    : Chen Fan
  3 LANG    : G++
  4 PROG    : HDU4784
  5 ************************************************ */
  6 
  7 #include <iostream>
  8 #include <cstdio>
  9 #include <cstring>
 10 #include <algorithm>
 11 #include <queue>
 12 
 13 using namespace std;
 14 
 15 typedef struct nod{
 16     int a,b,c,d;
 17 } node;
 18 
 19 int start[110],num[110];
 20 int p[10][110];
 21 int n,m,b,k,r,tim;
 22 node edge[210];
 23 
 24 typedef struct qnod
 25 {
 26     int s,t,b,k;
 27     friend bool operator < (qnod a,qnod b)
 28     {
 29         return a.t>b.t;
 30     }
 31 } qnode;
 32 
 33 int f[110][210][10][10];
 34 
 35 bool op(node a,node b)
 36 {
 37     return a.a<b.a;
 38 }
 39 
 40 int main()
 41 {
 42     freopen("test.txt","r",stdin);
 43 
 44     int t;
 45     scanf("%d",&t);
 46     for (int tt=1;tt<=t;tt++)
 47     {
 48         scanf("%d%d%d%d%d%d",&n,&m,&b,&k,&r,&tim);
 49         for (int i=0;i<k;i++)
 50         for (int j=1;j<=n;j++) scanf("%d",&p[i][j]);
 51         for (int i=1;i<=m;i++) scanf("%d%d%d%d",&edge[i].a,&edge[i].b,&edge[i].c,&edge[i].d);
 52         sort(&edge[1],&edge[m+1],op);
 53 
 54         int o=0;
 55         memset(num,0,sizeof(num));
 56         for (int i=1;i<=m;i++)
 57         {
 58             if (o!=edge[i].a)
 59             {
 60                 o=edge[i].a;
 61                 start[o]=i;
 62             }
 63             num[o]++;
 64         }
 65 
 66         printf("Case #%d: ",tt);
 67 
 68         priority_queue<qnode> q;
 69         while (!q.empty()) q.pop();
 70         memset(f,-1,sizeof(f));
 71 
 72         qnode st;
 73         st.s=1;st.t=0;st.b=0;st.k=0;
 74         f[1][0][0][0]=r;
 75         q.push(st);
 76 
 77         int ans=-1;
 78         while (!q.empty())
 79         {
 80             qnode now=q.top();
 81             q.pop();
 82 
 83             for (int i=0;i<num[now.s];i++)
 84             {
 85                 qnode next;
 86                 int mm=f[now.s][now.t][now.b][now.k]-edge[start[now.s]+i].d;
 87                 next.t=now.t+edge[start[now.s]+i].c;
 88                 if (mm<0||next.t>tim) continue;
 89                 next.s=edge[start[now.s]+i].b;
 90                 next.b=now.b;
 91                 next.k=now.k;
 92 
 93                 if (next.s==1&&next.k!=0) continue;
 94                 if (next.s==n)
 95                 {
 96                     if (next.k!=0) continue;
 97                     if (ans<mm) ans=mm;
 98                 } else 
 99                 {
100                     if (f[next.s][next.t][next.b][next.k]<0) q.push(next);
101                     if (f[next.s][next.t][next.b][next.k]<mm) f[next.s][next.t][next.b][next.k]=mm;
102 
103                     if (next.s==1) continue;
104                     if (next.b<b&&f[next.s][next.t][next.b][next.k]>=p[next.k][next.s])
105                     {
106                         qnode temp=next;
107                         temp.b++;
108                         mm=f[now.s][now.t][now.b][now.k]-edge[start[now.s]+i].d-p[next.k][next.s]; //!!!!!
109                         if (f[temp.s][temp.t][temp.b][temp.k]<0) q.push(temp);
110                         if (f[temp.s][temp.t][temp.b][temp.k]<mm) f[temp.s][temp.t][temp.b][temp.k]=mm;
111                     }
112 
113                     if (next.b>0)
114                     {
115                         qnode temp=next;
116                         temp.b--;
117                         mm=f[now.s][now.t][now.b][now.k]-edge[start[now.s]+i].d+p[next.k][next.s];
118                         if (f[temp.s][temp.t][temp.b][temp.k]<0) q.push(temp);
119                         if (f[temp.s][temp.t][temp.b][temp.k]<mm) f[temp.s][temp.t][temp.b][temp.k]=mm;
120                     }
121                 }
122             }
123             if (now.s==1) continue;
124             qnode next=now;
125             int mm=f[now.s][now.t][now.b][now.k];
126             next.k=(next.k+1)%k;
127             next.t++;
128             if (next.t>tim) continue;
129             
130             if (f[next.s][next.t][next.b][next.k]<0) q.push(next);
131             if (f[next.s][next.t][next.b][next.k]<mm) f[next.s][next.t][next.b][next.k]=mm;
132             
133             if (next.b<b&&f[next.s][next.t][next.b][next.k]>=p[next.k][next.s])
134             {
135                 qnode temp=next;
136                 temp.b++;
137                 mm=f[now.s][now.t][now.b][now.k]-p[next.k][next.s];
138                 if (f[temp.s][temp.t][temp.b][temp.k]<0) q.push(temp);
139                 if (f[temp.s][temp.t][temp.b][temp.k]<mm) f[temp.s][temp.t][temp.b][temp.k]=mm;
140             }
141 
142             if (next.b>0)
143             {
144                 qnode temp=next;
145                 temp.b--;
146                 mm=f[now.s][now.t][now.b][now.k]+p[next.k][next.s];
147                 if (f[temp.s][temp.t][temp.b][temp.k]<0) q.push(temp);
148                 if (f[temp.s][temp.t][temp.b][temp.k]<mm) f[temp.s][temp.t][temp.b][temp.k]=mm;
149             }
150         }
151 
152         if (ans<0) printf("Forever Alone\n");
153         else printf("%d\n",ans);
154     }
155 
156     return 0;
157 }
View Code

 

 

 

【F】 HDU 4786

Fibonacci Tree

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

【Problem Description】
  Coach Pang is interested in Fibonacci numbers while Uncle Yang wants him to do some research on Spanning Tree. So Coach Pang decides to solve the following problem:   Consider a bidirectional graph G with N vertices and M edges. All edges are painted into either white or black. Can we find a Spanning Tree with some positive Fibonacci number of white edges? (Fibonacci number is defined as 1, 2, 3, 5, 8, ... )
【Input】
  The first line of the input contains an integer T, the number of test cases.   For each test case, the first line contains two integers N(1 <= N <= 105) and M(0 <= M <= 105).   Then M lines follow, each contains three integers u, v (1 <= u,v <= N,  u<> v) and c (0 <= c <= 1), indicating an edge between u and v with a color c (1 for white and 0 for black).
【Output】
  For each test case, output a line “Case #x: s”. x is the case number and s is either “Yes” or “No” (without quotes) representing the answer to the problem.
【Sample Input】
2
4 4
1 2 1
2 3 1
3 4 1
1 4 0
5 6
1 2 1
1 3 1
1 4 1
1 5 1
3 5 1
4 2 1

【Sample Output】

Case #1: Yes
Case #2: No

【题意】

给出一张无向图,图中每一条边都有黑或者白两种颜色。询问是否可以从这张图中找到这样一个生成树,使得白边的条数为一个斐波那契数。

【分析】

考虑使用Kruskal构造最小生成树的方法,如果把颜色作为边权值,则可以构造出白边优先或者黑边优先的生成树。

白边优先树是尽可能多的取白边,能得到最多的使生成树成立的白边数,黑边优先树则是尽可能多的取黑边,得到最少的使生成树成立的白边数。从白边优先树出发的话,如果我们取掉一条白边,添加一条黑边,则构成的新图一定还是一棵树。即根据这个原理,可以构造出白边数介于最少白边数和最大白边数之间的所有生成树。接下来只要判断一下介于这两个数之间是不是存在斐波那契数即可。

  1 /* ***********************************************
  2 MYID    : Chen Fan
  3 LANG    : G++
  4 PROG    : HDU4786
  5 ************************************************ */
  6 
  7 #include <iostream>
  8 #include <cstdio>
  9 #include <cstring>
 10 #include <algorithm>
 11 #include <bitset>
 12 
 13 typedef struct nod
 14 {
 15     int a,b,color;
 16 } node;
 17 
 18 node edge[200010];
 19 
 20 using namespace std;
 21 
 22 bool op(node a,node b)
 23 {
 24     return a.color<b.color;
 25 }
 26 
 27 int n,m;
 28 
 29 int father[100010];
 30 
 31 int getfather(int x)
 32 {
 33     if (father[x]!=x) father[x]=getfather(father[x]);
 34     return father[x];
 35 }
 36 
 37 void link(int x,int y)
 38 {
 39     father[getfather(x)]=getfather(y);
 40 } 
 41 
 42 int kruskal1()
 43 {
 44     for (int i=1;i<=n;i++) father[i]=i;
 45     int num=0,tot=0;
 46     for (int i=1;i<=m;i++)
 47     if (getfather(edge[i].a)!=getfather(edge[i].b))
 48     {
 49         link(edge[i].a,edge[i].b);
 50         if (edge[i].color) num++;
 51         tot++;
 52     }
 53     if (tot!=n-1) return -1;
 54     else return num;
 55 }
 56 
 57 int kruskal2()
 58 {
 59     for (int i=1;i<=n;i++) father[i]=i;
 60     int num=0,tot=0;
 61     for (int i=m;i>=1;i--)
 62     if (getfather(edge[i].a)!=getfather(edge[i].b))
 63     {
 64         link(edge[i].a,edge[i].b);
 65         if (edge[i].color) num++;
 66         tot++;
 67     }
 68     if (tot!=n-1) return -1;
 69     else return num;
 70 }
 71 
 72 int main()
 73 {
 74     int tot=0;
 75     bitset<100010>fbn;
 76     fbn.reset();
 77     int a=1,b=1,c;
 78     fbn[1]=1;
 79     while (1)
 80     {
 81         c=a+b;
 82         if (c>=100010) break;
 83         fbn[c]=1;
 84         a=b;
 85         b=c;
 86     }
 87 
 88     int t;
 89     scanf("%d",&t);
 90     for (int tt=1;tt<=t;tt++)
 91     {
 92         scanf("%d%d",&n,&m);
 93 
 94         for (int i=1;i<=m;i++) scanf("%d%d%d",&edge[i].a,&edge[i].b,&edge[i].color);
 95 
 96         printf("Case #%d: ",tt);
 97 
 98         sort(&edge[1],&edge[m+1],op);
 99         int b1=kruskal1();
100 
101         if (b1<0) 
102         {
103             printf("No\n");
104             continue;
105         }
106 
107         int b2=kruskal2();
108 
109         bool done=false;
110         for (int i=b1;i<=b2;i++)
111         if (fbn[i])
112         {
113             done=true;
114             break;
115         }
116 
117         if (done) printf("Yes\n");
118         else printf("No\n");
119     }
120 
121     return 0;
122 }
View Code

 

【H】 HDU 4788

Hard Disk Drive

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

【Problem Description】
  Yesterday your dear cousin Coach Pang gave you a new 100MB hard disk drive (HDD) as a gift because you will get married next year.   But you turned on your computer and the operating system (OS) told you the HDD is about 95MB. The 5MB of space is missing. It is known that the HDD manufacturers have a different capacity measurement. The manufacturers think 1 “kilo” is 1000 but the OS thinks that is 1024. There are several descriptions of the size of an HDD. They are byte, kilobyte, megabyte, gigabyte, terabyte, petabyte, exabyte, zetabyte and yottabyte. Each one equals a “kilo” of the previous one. For example 1 gigabyte is 1 “kilo” megabytes.   Now you know the size of a hard disk represented by manufacturers and you want to calculate the percentage of the “missing part”.
【Input】
  The first line contains an integer T, which indicates the number of test cases.   For each test case, there is one line contains a string in format “number[unit]” where number is a positive integer within [1, 1000] and unit is the description of size which could be “B”, “KB”, “MB”, “GB”, “TB”, “PB”, “EB”, “ZB”, “YB” in short respectively.
【Output】
  For each test case, output one line “Case #x: y”, where x is the case number (starting from 1) and y is the percentage of the “missing part”. The answer should be rounded to two digits after the decimal point.
【Sample Input】
2
100[MB]
1[B]

 【Sample Output】

Case #1: 4.63%
Case #2: 0.00%

【Hint】

 

【分析】 

签到题

 

【J】 HDU 4790

Just Random

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

【Problem Description】
  Coach Pang and Uncle Yang both love numbers. Every morning they play a game with number together. In each game the following will be done:   
1. Coach Pang randomly choose a integer x in [a, b] with equal probability.   
2. Uncle Yang randomly choose a integer y in [c, d] with equal probability.   
3. If (x + y) mod p = m, they will go out and have a nice day together.   
4. Otherwise, they will do homework that day.   
      For given a, b, c, d, p and m, Coach Pang wants to know the probability that they will go out.
【Input】
  The first line of the input contains an integer T denoting the number of test cases.   For each test case, there is one line containing six integers a, b, c, d, p and m(0 <= a <= b <= 109, 0 <=c <= d <= 109, 0 <= m < p <= 109).
【Output】
  For each test case output a single line "Case #x: y". x is the case number and y is a fraction with numerator and denominator separated by a slash ('/') as the probability that they will go out. The fraction should be presented in the simplest form (with the smallest denominator), but always with a denominator (even if it is the unit).
【Sample Input】
4
0 5 0 5 3 0
0 999999 0 999999 1000000 0
0 3 0 3 8 7
3 3 4 4 7 0

【Sample Output】

Case #1: 1/3
Case #2: 1/1000000
Case #3: 0/1
Case #4: 1/1

【题意】

给定两个区间,每次分别从这两个区间中取出一个数求和,问有多少种组合的和是能够对p取模之后等于m的概率。

【分析】

posted @ 2014-10-27 09:21  辰帆  阅读(490)  评论(2编辑  收藏  举报