[关闭]
@2368860385 2018-07-04T03:43:55.000000Z 字数 3574 阅读 231

1003——Codeforces Round #494 (Div. 3)

http://codeforces.com/contest/1003

codeforces

2018.7.3参加(ABCD)
2018.7.4整理(E)


A:

模拟,求出最长的一段相同的数的个数。

B:

构造,先构造一个类似01010或者10101的字符串,假设x=6,就是0101010,哪个多,哪个放在前面。然后把剩余的数放到对应的位置,连起来。详见代码。

C:

n^2求前缀和,取max

D:

统计2^t的硬币有多少个,t=0,1,2...
因为要求最少的硬币,所以从大的往小的开始取,将b二进制分解后,从高位往低位扫,假设第i位 位1,说明需要一个2^(i-1)的硬币,查看有没有,没有就分解陈两个2^(i-2)的硬币,查看有没有。以此类推。

E:

构造,先构造一条链,然后往链上加点。(好像化学上的同分异构。。。)


A:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. inline int read() {
  5. int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
  6. for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f;
  7. }
  8. int a[1090];
  9. int main () {
  10. int n = read();
  11. for (int i=1; i<=n; ++i) {
  12. a[i] = read();
  13. }
  14. sort(a+1,a+n+1);
  15. int ans = 0,cnt = 0;
  16. a[0] = -1;
  17. for (int i=1; i<=n; ++i) {
  18. if (a[i] == a[i-1]) cnt++;
  19. else {
  20. ans = max(ans,cnt+1);
  21. cnt = 0;
  22. }
  23. }
  24. ans = max(ans,cnt+1); // 漏写一句,卡了5分钟。。。
  25. cout << ans;
  26. return 0;
  27. }

B:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. inline int read() {
  5. int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
  6. for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f;
  7. }
  8. int s[1000];
  9. void work(int a,int b,int c,int x) {
  10. for (int i=1; i<=x+1; ++i) {
  11. if (i & 1) s[i] = c,a--;
  12. else s[i] = (!c),b--;
  13. }/*
  14. if (x & 1) s[x+1] = (!c),b--;
  15. else s[x+1] = c,a--;
  16. */
  17. for (int i=1; i<=x+1; ++i) {
  18. if (s[i] == c) {
  19. cout << c;
  20. while (a>0) cout << c,a--;
  21. }
  22. else {
  23. cout << (!c);
  24. while (b>0) cout << (!c),b--; // 写成cout<<(!b);卡了13分钟。。。
  25. }
  26. }
  27. }
  28. int main () {
  29. int a,b,x;
  30. cin >> a >> b >> x;
  31. if (a > b) work(a,b,0,x);
  32. else work(b,a,1,x);
  33. return 0;
  34. }

C:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. inline int read() {
  5. int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
  6. for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f;
  7. }
  8. int a[5005],sum[5005];
  9. int main () {
  10. int n = read(),k = read();
  11. for (int i=1; i<=n; ++i) a[i] = read(),sum[i] = a[i] + sum[i-1];
  12. double ans = 0;
  13. for (int i=1; i<=n; ++i) {
  14. for (int j=(i+k-1); j<=n; ++j) {
  15. double t1 = 1.0 * (sum[j] - sum[i-1]);
  16. double t2 = 1.0 * (j - i + 1);
  17. ans = max(ans, (t1/t2));
  18. }
  19. }
  20. printf("%.10lf",ans);
  21. return 0;
  22. }

D:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. inline int read() {
  5. int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
  6. for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f;
  7. }
  8. const int N = 200010;
  9. int a[N],c[100];
  10. void solve() {
  11. int b = read(),ans = 0,cnt = 0;
  12. for (int i=30; i>=0; --i) {
  13. if ((b >> i) & 1) cnt ++;
  14. if (cnt > 0) {
  15. if (c[i] >= cnt) ans += cnt,cnt = 0;
  16. else {
  17. cnt -= c[i];
  18. ans += c[i];
  19. cnt *= 2;
  20. }
  21. }
  22. }
  23. if (cnt) puts("-1");
  24. else cout << ans << "\n";
  25. }
  26. int main () {
  27. int n = read(),m = read();
  28. for (int i=1; i<=n; ++i) {
  29. a[i] = read();
  30. int t = log2(a[i]);
  31. c[t]++;
  32. }
  33. while (m--) solve();
  34. return 0;
  35. }
  36. /*
  37. 4 1
  38. 8 2 2 2
  39. 14
  40. */

E:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. inline int read() {
  5. int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
  6. for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f;
  7. }
  8. const int N = 500100;
  9. int n,d,k,tn;
  10. int g[N];
  11. void dfs(int u,int cur,int mx,int cnt) { // 点,当前深度,最大深度,儿子节点
  12. if (cur == mx) return;
  13. int id;
  14. for (int i=1; i<=cnt; ++i) {
  15. ++tn;
  16. g[tn] = u;
  17. if (tn == n) {
  18. puts("YES");
  19. for (int i=2; i<=n; ++i)
  20. printf("%d %d\n",i,g[i]);
  21. exit(0);
  22. }
  23. dfs(tn,cur+1,mx,k-1);
  24. }
  25. }
  26. int main () {
  27. n = read(),d = read(),k = read(); // d-zhijing k-dushu
  28. if (d+1 > n) {puts("NO");return 0;}
  29. if (n == 1) {
  30. if (d==0) printf("YES");
  31. else printf("NO");
  32. return 0;
  33. }
  34. if (n==2) {
  35. if (d == 1 && k >= 1) printf("YES\n2 1");
  36. else puts("NO");
  37. return 0;
  38. }
  39. if (k < 2) {puts("NO");return 0;}
  40. for (int i=1; i<=d; ++i) g[i+1] = i;
  41. tn = d + 1;
  42. if (tn == n) { // 没在这判断。。卡到比赛结束。。。也没A
  43. puts("YES");
  44. for (int i=2; i<=n; ++i)
  45. printf("%d %d\n",i,g[i]);
  46. return 0;
  47. }
  48. if (d & 1) {
  49. int t = (d + 1) / 2;
  50. for (int i=2; i<=t; ++i) dfs(i,1,i,k-2);
  51. for (int i=t+1; i<=d; ++i) dfs(i,1,(d+1-i+1),k-2);
  52. }
  53. else {
  54. int t = d / 2 + 1;
  55. for (int i=2; i<=t; ++i) dfs(i,1,i,k-2);
  56. for (int i=t+1; i<=d; ++i) dfs(i,1,(d+1-i+1),k-2);
  57. }
  58. if (tn == n) {
  59. puts("YES");
  60. for (int i=2; i<=n; ++i)
  61. printf("%d %d\n",i,g[i]);
  62. }
  63. else if (tn < n) puts("NO");
  64. return 0;
  65. }
  66. /*
  67. 17 5 4
  68. */

总结:

敲代码经常出错。。。
集中注意力敲代码,养足精力打比赛!

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注