您的位置:首页 > 其它

The 2013 ACMICPC Asia Regional Chengdu

2014-10-27 09:21 363 查看
还有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

[align=left]【Problem Description】[/align]
  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.

[align=left]【Input】[/align]
  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 )
[align=left]【Output】[/align]
  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.
[align=left]【Sample Input】[/align]

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的倍数的有向环。依次解决完所有的剩余边即可。

/* ***********************************************
MYID    : Chen Fan
LANG    : G++
PROG    : HDU4786
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <bitset>

typedef struct nod
{
int a,b,color;
} node;

node edge[200010];

using namespace std;

bool op(node a,node b)
{
return a.color<b.color;
}

int n,m;

int father[100010];

int getfather(int x)
{
if (father[x]!=x) father[x]=getfather(father[x]);
return father[x];
}

void link(int x,int y)
{
father[getfather(x)]=getfather(y);
}

int kruskal1()
{
for (int i=1;i<=n;i++) father[i]=i;
int num=0,tot=0;
for (int i=1;i<=m;i++)
if (getfather(edge[i].a)!=getfather(edge[i].b))
{
link(edge[i].a,edge[i].b);
if (edge[i].color) num++;
tot++;
}
if (tot!=n-1) return -1;
else return num;
}

int kruskal2()
{
for (int i=1;i<=n;i++) father[i]=i;
int num=0,tot=0;
for (int i=m;i>=1;i--)
if (getfather(edge[i].a)!=getfather(edge[i].b))
{
link(edge[i].a,edge[i].b);
if (edge[i].color) num++;
tot++;
}
if (tot!=n-1) return -1;
else return num;
}

int main()
{
int tot=0;
bitset<100010>fbn;
fbn.reset();
int a=1,b=1,c;
fbn[1]=1;
while (1)
{
c=a+b;
if (c>=100010) break;
fbn[c]=1;
a=b;
b=c;
}

int t;
scanf("%d",&t);
for (int tt=1;tt<=t;tt++)
{
scanf("%d%d",&n,&m);

for (int i=1;i<=m;i++) scanf("%d%d%d",&edge[i].a,&edge[i].b,&edge[i].color);

printf("Case #%d: ",tt);

sort(&edge[1],&edge[m+1],op);
int b1=kruskal1();

if (b1<0)
{
printf("No\n");
continue;
}

int b2=kruskal2();

bool done=false;
for (int i=b1;i<=b2;i++)
if (fbn[i])
{
done=true;
break;
}

if (done) printf("Yes\n");
else printf("No\n");
}

return 0;
}


View Code

【H】 HDU 4788

Hard Disk Drive

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

[align=left]【Problem Description】[/align]
  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”.
[align=left]【Input】[/align]
  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.
[align=left]【Output】[/align]
  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.
[align=left]【Sample Input】[/align]

2
100[MB]
1


【Sample Output】

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


【Hint】



【分析】

签到题

【J】 HDU 4790

Just Random

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


[align=left]【Problem Description】[/align]
  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.
[align=left]【Input】[/align]
  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).
[align=left]【Output】[/align]
  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).
[align=left]【Sample Input】[/align]

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的概率。

【分析】
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐