2016 ACM/ICPC Asia Regional Qingdao Online(部分题解)

5878---I Count Two Three http://acm.hdu.edu.cn/showproblem.php?pid=5878

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1287    Accepted Submission(s): 604

Problem Description
I will show you the most popular board game in the Shanghai Ingress Resistance Team.
It all started several months ago.
We found out the home address of the enlightened agent Icount2three and decided to draw him out.
Millions of missiles were detonated, but some of them failed.

After the event, we analysed the laws of failed attacks.
It's interesting that the i-th attacks failed if and only if i can be rewritten as the form of 2a3b5c7d which a,b,c,d are non-negative integers.

At recent dinner parties, we call the integers with the form 2a3b5c7d "I Count Two Three Numbers".
A related board game with a given positive integer n from one agent, asks all participants the smallest "I Count Two Three Number" no smaller than n.

 
Input
The first line of input contains an integer t (1≤t≤500000), the number of test cases. t test cases follow. Each test case provides one integer n (1≤n≤109).
 
Output
For each test case, output one line with only one integer corresponding to the shortest "I Count Two Three Number" no smaller than n.
 
Sample Input
10
1
11
13
123
1234
12345
123456
1234567
12345678
123456789
 
Sample Output
1 12 14 125 1250 12348 123480 1234800 12348000 123480000
 
这题枚举一下四重循环打表,然后二分答案水过。。。
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cmath>
  5. #include<cstring>
  6. using namespace std;
  7.  
  8. int t,n,cnt;
  9. long long st[500005],p,r;
  10. long long p2[500005],p3[500005],p5[500005],p7[500005];
  11.  
  12. int main()
  13. {
  14. scanf("%d",&t);
  15. r=1;
  16. p2[0]=r;
  17. for(int i=1;i;i++)
  18. {
  19. if(r>1e9)break;
  20. r*=2;
  21. p2[i]=r;
  22. }
  23. r=1;
  24. p3[0]=r;
  25. for(int i=1;i;i++)
  26. {
  27. if(r>1e9)break;
  28. r*=3;
  29. p3[i]=r;
  30. }
  31. r=1;
  32. p5[0]=r;
  33. for(int i=1;i;i++)
  34. {
  35. if(r>1e9)break;
  36. r*=5;
  37. p5[i]=r;
  38. }
  39. r=1;
  40. p7[0]=r;
  41. for(int i=1;i;i++)
  42. {
  43. if(r>1e9)break;
  44. r*=7;
  45. p7[i]=r;
  46. }
  47. cnt=0;
  48. for(int i=0;i<=31;i++)
  49. {
  50. for(int j=0;j<=19;j++)
  51. {
  52. for(int k=0;k<=12;k++)
  53. {
  54. for(int v=0;v<=11;v++)
  55. {
  56. p=p2[i]*p3[j];
  57. if(p>1e9)break;
  58. st[++cnt]=p;
  59. if(p<1e9)
  60. {
  61. p*=p5[k];
  62. if(p>1e9)break;
  63. st[++cnt]=p;
  64. }
  65. else break;
  66. if(p<1e9)
  67. {
  68. p*=p7[v];
  69. if(p>1e9)break;
  70. st[++cnt]=p;
  71. }
  72. }
  73. }
  74. }
  75. }
  76. sort(st+1,st+cnt+1);
  77. while(t--)
  78. {
  79. scanf("%d",&n);
  80. printf("%lld\n",*lower_bound(st+1,st+cnt+1,n));
  81. }
  82. return 0;
  83. }

  

5879---Cure http://acm.hdu.edu.cn/showproblem.php?pid=5879

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1783    Accepted Submission(s): 568

Problem Description
Given an integer n, we only want to know the sum of 1/k2 where k from 1 to n.
 
Input
There are multiple cases.
For each test case, there is a single line, containing a single positive integer n. 
The input file is at most 1M.
 
Output
The required sum, rounded to the fifth digits after the decimal point.
 
Sample Input
1
2
4
8
15
 
Sample Output
1.00000
1.25000
1.42361
1.52742
1.58044
 

这题可以找规律发现到某一点往上至正无穷大,数值都不会变,然后就好做啦~只需要处理前几十万个。

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cmath>
  5. #include<cstring>
  6. #include<string>
  7. using namespace std;
  8.  
  9. string n;
  10. long double sum[400005];
  11.  
  12. int main()
  13. {
  14. sum[0]=(long double)0.0;
  15. for(int i=1;i<=400000;i++)
  16. {
  17. sum[i]=sum[i-1]+(long double)1.0/(long double)i/(long double)i;
  18. }
  19. while(cin>>n)
  20. {
  21. if(n[0]=='-')n[0]='0';
  22. long long p=0;
  23. bool f=0;
  24. for(int i=0;i<n.size();i++)
  25. {
  26. p=p*10+n[i]-48;
  27. if(p>400000)
  28. {
  29. printf("%.5f\n",(double)sum[400000]);
  30. f=1;
  31. break;
  32. }
  33. }
  34. if(f==0)
  35. {
  36. printf("%.5f\n",(double)sum[p]);
  37. }
  38. }
  39. return 0;
  40. }

  

5882---Balanced Game  http://acm.hdu.edu.cn/showproblem.php?pid=5882

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 435    Accepted Submission(s): 377

Problem Description
Rock-paper-scissors is a zero-sum hand game usually played between two people, in which each player simultaneously forms one of three shapes with an outstretched hand. These shapes are "rock", "paper", and "scissors". The game has only three possible outcomes other than a tie: a player who decides to play rock will beat another player who has chosen scissors ("rock crushes scissors") but will lose to one who has played paper ("paper covers rock"); a play of paper will lose to a play of scissors ("scissors cut paper"). If both players choose the same shape, the game is tied and is usually immediately replayed to break the tie.

Recently, there is a upgraded edition of this game: rock-paper-scissors-Spock-lizard, in which there are totally five shapes. The rule is simple: scissors cuts paper; paper covers rock; rock crushes lizard; lizard poisons Spock; Spock smashes scissors; scissors decapitates lizard; lizard eats paper; paper disproves Spock; Spock vaporizes rock; and as it always has, rock crushes scissors.

Both rock-paper-scissors and rock-paper-scissors-Spock-lizard are balanced games. Because there does not exist a strategy which is better than another. In other words, if one chooses shapes randomly, the possibility he or she wins is exactly 50% no matter how the other one plays (if there is a tie, repeat this game until someone wins). Given an integer N, representing the count of shapes in a game. You need to find out if there exist a rule to make this game balanced.

 
Input
The first line of input contains an integer t, the number of test cases. t test cases follow.
For each test case, there is only one line with an integer N (2≤N≤1000), as described above.

Here is the sample explanation.

In the first case, donate two shapes as A and B. There are only two kind of rules: A defeats B, or B defeats A. Obviously, in both situation, one shapes is better than another. Consequently, this game is not balanced.

In the second case, donate two shapes as A, B and C. If A defeats B, B defeats C, and C defeats A, this game is balanced. This is also the same as rock-paper-scissors.

In the third case, it is easy to set a rule according to that of rock-paper-scissors-Spock-lizard.

 
Output
For each test cases, output "Balanced" if there exist a rule to make the game balanced, otherwise output "Bad".
 
Sample Input
3
2
3
5
 
Sample Output
Bad
Balanced
Balanced
 
傻逼的无脑题,直接判断奇偶性!简单说下吧,一个点是偶数可以连其余奇数条边,不可能满足50%,即BAD,反之同理。
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cmath>
  5. #include<cstring>
  6. #include<string>
  7. using namespace std;
  8.  
  9. int t,n;
  10. int main()
  11. {
  12. scanf("%d",&t);
  13. while(t--)
  14. {
  15. scanf("%d",&n);
  16. if(n%2==0)cout<<"Bad"<<endl; else cout<<"Balanced"<<endl;
  17. }
  18. return 0;
  19. }

5883---The Best Pathhttp://acm.hdu.edu.cn/showproblem.php?pid=5883

Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 1155    Accepted Submission(s): 515

Problem Description
Alice is planning her travel route in a beautiful valley. In this valley, there are N lakes, and M rivers linking these lakes. Alice wants to start her trip from one lake, and enjoys the landscape by boat. That means she need to set up a path which go through every river exactly once. In addition, Alice has a specific number (a1,a2,...,an) for each lake. If the path she finds is P0→P1→...→Pt, the lucky number of this trip would be aP0XORaP1XOR...XORaPt. She want to make this number as large as possible. Can you help her?
 
Input
The first line of input contains an integer t, the number of test cases. t test cases follow.

For each test case, in the first line there are two positive integers N (N≤100000) and M (M≤500000), as described above. The i-th line of the next N lines contains an integer ai(∀i,0≤ai≤10000) representing the number of the i-th lake.

The i-th line of the next M lines contains two integers ui and vi representing the i-th river between the ui-th lake and vi-th lake. It is possible that ui=vi.

 
Output
For each test cases, output the largest lucky number. If it dose not have any path, output "Impossible".
 
Sample Input
2
3 2
3
4
5
1 2
2 3
4 3
1
2
3
4
1 2
2 3
2 4
 
Sample Output
2 Impossible

裸的一笔画问题,判欧拉回路与欧拉通路两种与连通性。

欧拉通路没啥好说的,首尾点固定,路线固定。

欧拉回路,即环。值是不定的,要求最大,即将必须通过的点XOR,再枚举开头初始点,与之前ans进行XOR,比最值。

不是一笔画即Impossible。

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cmath>
  5. #include<cstring>
  6. #include<string>
  7. #include<set>
  8. using namespace std;
  9.  
  10. int t,n,m,x,y,ans,p,cnt;
  11. int a[100005],sum[100005],par[100005];
  12.  
  13. int find(int x)
  14. {
  15. if(x==par[x])return x; else return par[x]=find(par[x]);
  16. }
  17.  
  18. void unionx(int x,int y)
  19. {
  20. x=find(x);
  21. y=find(y);
  22. if(x==y)return ;
  23. par[x]=y;
  24. }
  25.  
  26. int main()
  27. {
  28. scanf("%d",&t);
  29. while(t--)
  30. {
  31. for(int i=1;i<=n;i++)par[i]=i;
  32. scanf("%d%d",&n,&m);
  33. for(int i=1;i<=n;i++)scanf("%d",&a[i]);
  34. memset(sum,0,sizeof(sum));
  35. for(int i=1;i<=m;i++)
  36. {
  37. scanf("%d%d",&x,&y);
  38. unionx(x,y);
  39. sum[x]++;
  40. sum[y]++;
  41. }
  42. cnt=0;
  43. for(int i=1;i<=n;i++)
  44. {
  45. if(i==par[i] && sum[i]!=0)cnt++;
  46. }
  47. if(cnt>1)
  48. {
  49. cout<<"Impossible"<<endl;
  50. continue;
  51. }
  52. p=0;
  53. ans=0;
  54. for(int i=1;i<=n;i++)
  55. {
  56. if(sum[i]==0)continue;
  57. if(sum[i]%2==1)p++;
  58. ans^=(((sum[i]+1)/2)%2)*a[i];
  59. }
  60. if(p!=0 && p!=2)
  61. {
  62. cout<<"Impossible"<<endl;
  63. continue;
  64. }
  65. if(p==2)
  66. {
  67. printf("%d\n",ans);
  68. continue;
  69. }
  70. else
  71. {
  72. int anss=0;
  73. for(int i=1;i<=n;i++)
  74. {
  75. if(sum[i]==0)continue;
  76. anss=max(anss,ans^a[i]);
  77. }
  78. printf("%d\n",anss);
  79. }
  80. }
  81. return 0;
  82. }

  

先只看了几道通过率高的题A了,剩余的题如果还有A的,且心情好的话再补上。。。

毕竟之前两天辣么的题目都没挂上来。原因。。。文化课掉出年级250外了。。。

2016 ACM/ICPC Asia Regional Qingdao Online(2016ACM青岛网络赛部分题解)的更多相关文章

  1. 2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分

    I Count Two Three Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  2. HDU 5889 Barricade 【BFS+最小割 网络流】(2016 ACM/ICPC Asia Regional Qingdao Online)

    Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  3. 【2016 ACM/ICPC Asia Regional Qingdao Online】

    [ HDU 5878 ] I Count Two Three 考虑极端,1e9就是2的30次方,3的17次方,5的12次方,7的10次方. 而且,不超过1e9的乘积不过5000多个,于是预处理出来,然 ...

  4. hdu 5878 I Count Two Three (2016 ACM/ICPC Asia Regional Qingdao Online 1001)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5878 题目大意: 给出一个数n ,求一个数X, X>=n. X 满足一个条件 X= 2^a*3^ ...

  5. Hdu OJ 5884-Sort (2016 ACM/ICPC Asia Regional Qingdao Online)(二分+优化哈夫曼)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5884 题目大意:有n个有序的序列,对于第i个序列有ai个元素. 现在有一个程序每次能够归并k个序列, ...

  6. 2016 ACM/ICPC Asia Regional Qingdao Online HDU5889

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5889 解法:http://blog.csdn.net/u013532224/article/details ...

  7. 2016 ACM/ICPC Asia Regional Qingdao Online HDU5883

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5883 解法:先判断是不是欧拉路,然后枚举 #pragma comment(linker, "/S ...

  8. 2016 ACM/ICPC Asia Regional Qingdao Online HDU5882

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5882 解法:一个点必须出度和入度相同就满足题意,所以加上本身就是判断奇偶性 #include<std ...

  9. 2016 ACM/ICPC Asia Regional Qingdao Online HDU5879

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5879 解法:我们知道到某个极限之后结果相同,所以找到那个极限,其他保存之后输出就好了 #include&l ...

随机推荐

  1. 【poj解题】1028

    stack的应用 #include<iostream> #include<stack> #include<stdio.h> #include<stdlib.h ...

  2. 推荐!国外程序员整理的Java资源大全

    http://www.importnew.com/14429.html 本文由 ImportNew - 唐尤华 翻译自 github akullpp.欢迎加入翻译小组.转载请见文末要求. 构建 这里搜 ...

  3. deb安装了些啥?

    http://www.cyberciti.biz/faq/view-contents-of-deb-file/

  4. 导出WAS已部署的ear包的几种方法

    可以通过下面几种办法将部署好的工程导出为一个ear包. 1.最简单的,通过was的控制台导出: 首先登录控制台,进入"企业应用程序"管理页面,选中要导出的工程,点击"导出 ...

  5. jpg转bmp(使用libjpeg)

    源: jpg转bmp(使用libjpeg) [转]JPEG压缩原理 bmp转jpg(使用libjpeg)

  6. 360路由器设置网段ip

    路由器设置->高级设置->修改路由器地址

  7. UILabel常用属性小结

    标签常用的属性: (1)frame属性:设置标签的位置与大小. frame = CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat heig ...

  8. 最基本的SQL语法/语句

    DDL—数据定义语言(Create,Alter,Drop,DECLARE) DML—数据操纵语言(Select,Delete,Update,Insert) DCL—数据控制语言(GRANT,REVOK ...

  9. sql 里的 IF ELSE 语句用法

      IF ELSE 语句 IF ELSE 是最基本的编程语句结构之一几乎每一种编程语言都支持这种结构而 它在用于对从数据库返回的数据进行检查是非常有用的TRANSACT-SQL 使用IF ELSE 的 ...

  10. BZOJ2698染色

    2698: 染色 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 223  Solved: 150[Submit][Status][Discuss] De ...