A. Roman and Browser

签到.

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n, k, a[];
  5.  
  6. int get(int b)
  7. {
  8. int vis[];
  9. memset(vis, , sizeof vis);
  10. int c = b;
  11. while (c <= n)
  12. {
  13. vis[c] = ;
  14. c += k;
  15. }
  16. c = b - k;
  17. while (c >= )
  18. {
  19. vis[c] = ;
  20. c -= k;
  21. }
  22. int l = , r = ;
  23. for (int i = ; i <= n; ++i) if (!vis[i])
  24. {
  25. if (a[i] == ) ++l;
  26. else ++r;
  27. }
  28. return abs(l - r);
  29. }
  30.  
  31. int main()
  32. {
  33. while (scanf("%d%d", &n, &k) != EOF)
  34. {
  35. for (int i = ; i <= n; ++i) scanf("%d", a + i);
  36. int res = ;
  37. for (int i = ; i <= n; ++i) res = max(res, get(i));
  38. printf("%d\n", res);
  39. }
  40. return ;
  41. }

B. Build a Contest

签到.

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define N 100010
  5. int n, m, a[N];
  6. int cnt[N];
  7.  
  8. int main()
  9. {
  10. while (scanf("%d%d", &n, &m) != EOF)
  11. {
  12. for (int i = ; i <= m; ++i) scanf("%d", a + i);
  13. int need = n;
  14. memset(cnt, , sizeof cnt);
  15. for (int i = ; i <= m; ++i)
  16. {
  17. if (cnt[a[i]] == )
  18. --need;
  19. ++cnt[a[i]];
  20. if (need) putchar('');
  21. else
  22. {
  23. putchar('');
  24. for (int j = ; j <= n; ++j)
  25. {
  26. --cnt[j];
  27. if (!cnt[j])
  28. ++need;
  29. }
  30. }
  31. }
  32. puts("");
  33. }
  34. return ;
  35. }

C. NN and the Optical Illusion

签到.

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const double eps = 1e-;
  5. const double PI = acos(-1.0);
  6.  
  7. int main()
  8. {
  9. int n; double r;
  10. while (scanf("%d%lf", &n, &r) != EOF)
  11. {
  12. double ang1 = 2.0 * PI / n;
  13. double ang2 = (PI - ang1) / ;
  14. double R = (r * sin(ang1) * 1.0) / ( * sin(ang2) - sin(ang1));
  15. printf("%.10f\n", R);
  16. }
  17. return ;
  18. }

D. Dasha and Chess

Upsolved.

题意:

你有一个白王,对方有$666$个黑王

你每次可以八个方向走一步,对方可以任意移动一个黑王的位置

在$2000步以内如果你和某个黑王同行同列,你就赢了$

$给出你必胜的方案$

思路:

先走到中间,再考虑黑王个数最少的那个角落,向它的反方向走就可以了

考虑最差的情况,四个角很平均都有$166个左右$

那么也就是说另外三个角的个数加起来至少是$500个,而从中间走到某一角落只需要499步$

所以一定可以包围一个

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define N 1010
  5. #define pii pair <int, int>
  6. #define x first
  7. #define y second
  8. int G[N][N], x, y, cnt[];
  9. pii cor[N];
  10.  
  11. void Move(int edx, int edy)
  12. {
  13. while (x != edx || y != edy)
  14. {
  15. if (x < edx && G[x + ][y] == ) ++x;
  16. else if (x > edx && G[x - ][y] == ) --x;
  17. if (y < edy && G[x][y + ] == ) ++y;
  18. else if (y > edy && G[x][y - ] == ) --y;
  19. printf("%d %d\n", x, y);
  20. fflush(stdout);
  21. int k, a, b;
  22. scanf("%d%d%d", &k, &a, &b);
  23. if (k == -) exit();
  24. G[cor[k].x][cor[k].y] = ;
  25. cor[k].x = a, cor[k].y = b;
  26. G[cor[k].x][cor[k].y] = ;
  27. }
  28. }
  29.  
  30. int main()
  31. {
  32. while (scanf("%d%d", &x, &y) != EOF)
  33. {
  34. memset(G, , sizeof G);
  35. for (int i = ; i <= ; ++i)
  36. {
  37. scanf("%d%d", &cor[i].x, &cor[i].y);
  38. G[cor[i].x][cor[i].y] = ;
  39. }
  40. Move(, );
  41. memset(cnt, , sizeof cnt);
  42. for (int i = ; i <= ; ++i)
  43. for (int j = ; j <= ; ++j)
  44. if (G[i][j])
  45. {
  46. if (i < x && j < y) ++cnt[];
  47. else if (i < x && j > y) ++cnt[];
  48. else if (i > x && j < y) ++cnt[];
  49. else ++cnt[];
  50. }
  51. if (cnt[] <= ) Move(, );
  52. else if (cnt[] <= ) Move(, );
  53. else if (cnt[] <= ) Move(, );
  54. else Move(, );
  55. }
  56. return ;
  57. }

E. Andrew and Taxi

Upsolved.

题意:

给出一张有向图,求改变一些边使得它没有环

改变一条边的花费是它的边权,要使得最大花费最小

输出最大花费和需要改变的边数

再输出相应的边

思路:

先二分答案,每次check的时候检查一下边权大于limit的边组成的图是否有环

如果有环,那么一定不行,如果没有环,那么一定可以

对于剩下的边,方向自定,拓扑序小的连向拓扑序大的

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define N 100010
  5. int n, m;
  6. struct Graph
  7. {
  8. struct node
  9. {
  10. int to, nx, w, id;
  11. node() {}
  12. node (int to, int nx, int w, int id) : to(to), nx(nx), w(w), id(id) {}
  13. }a[N << ];
  14. int head[N], pos;
  15. void init()
  16. {
  17. memset(head, , sizeof head);
  18. pos = ;
  19. }
  20. void add(int u, int v, int w, int id)
  21. {
  22. a[++pos] = node(v, head[u], w, id); head[u] = pos;
  23. }
  24. }G;
  25. #define erp(u) for (int it = G.head[u], v = G.a[it].to, w = G.a[it].w, id = G.a[it].id; it; it = G.a[it].nx, v = G.a[it].to, w = G.a[it].w, id = G.a[it].id)
  26.  
  27. int degree[N], ord[N];
  28. bool check(int x)
  29. {
  30. memset(degree, , sizeof degree);
  31. for (int i = ; i <= n; ++i) erp(i) if (w > x)
  32. ++degree[v];
  33. int cnt = ;
  34. queue <int> q;
  35. for (int i = ; i <= n; ++i) if (!degree[i])
  36. q.push(i);
  37. while (!q.empty())
  38. {
  39. ++cnt;
  40. int u = q.front(); q.pop();
  41. ord[u] = cnt;
  42. erp(u) if (w > x && --degree[v] == )
  43. q.push(v);
  44. }
  45. return cnt >= n;
  46. }
  47.  
  48. int main()
  49. {
  50. while (scanf("%d%d", &n, &m) != EOF)
  51. {
  52. G.init();
  53. for (int i = , u, v, w; i <= m; ++i)
  54. {
  55. scanf("%d%d%d", &u, &v, &w);
  56. G.add(u, v, w, i);
  57. }
  58. int l = , r = (int)1e9, res = -;
  59. while (r - l >= )
  60. {
  61. int mid = (l + r) >> ;
  62. if (check(mid))
  63. {
  64. res = mid;
  65. r = mid - ;
  66. }
  67. else
  68. l = mid + ;
  69. }
  70. vector <int> vec;
  71. check(res);
  72. for (int i = ; i <= n; ++i) erp(i) if (w <= res && ord[i] > ord[v]) vec.push_back(id);
  73. printf("%d %d\n", res, (int)vec.size());
  74. for (int i = , len = vec.size(); i < len; ++i) printf("%d%c", vec[i], " \n"[i == len - ]);
  75. }
  76. return ;
  77. }

F. Ivan and Burgers

Upsolved.

题意:

询问区间任意数异或最大值

思路:

维护前缀线性基,但是要注意将$位置id大的数更换基底$

$因为这样这些基底被用户更新答案的概率就更高$

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define N 500010
  5. int n, q, c[N];
  6. int pos[N][], p[N][];
  7.  
  8. void work(int x)
  9. {
  10. for (int i = ; i <= ; ++i)
  11. {
  12. pos[x][i] = pos[x - ][i];
  13. p[x][i] = p[x - ][i];
  14. }
  15. int tmp = c[x];
  16. int id = x;
  17. for (int i = ; i >= ; --i)
  18. {
  19. if ((tmp >> i) & )
  20. {
  21. if (!p[x][i])
  22. {
  23. p[x][i] = tmp;
  24. pos[x][i] = id;
  25. return;
  26. }
  27. if (pos[x][i] < id)
  28. {
  29. swap(tmp, p[x][i]);
  30. swap(id, pos[x][i]);
  31. }
  32. tmp ^= p[x][i];
  33. }
  34. }
  35. }
  36.  
  37. int ask(int l, int r)
  38. {
  39. int res = ;
  40. for (int i = ; i >= ; --i) if (pos[r][i] >= l && (res ^ p[r][i]) > res)
  41. res ^= p[r][i];
  42. return res;
  43. }
  44.  
  45. int main()
  46. {
  47. while (scanf("%d", &n) != EOF)
  48. {
  49. for (int i = ; i <= n; ++i) scanf("%d", c + i);
  50. for (int i = ; i < ; ++i) pos[][i] = p[][i] = ;
  51. for (int i = ; i <= n; ++i) work(i);
  52. scanf("%d", &q);
  53. for (int qq = , l, r; qq <= q; ++qq)
  54. {
  55. scanf("%d%d", &l, &r);
  56. printf("%d\n", ask(l, r));
  57. }
  58.  
  59. }
  60. return ;
  61. }

Codeforces Round #532 (Div. 2) Solution的更多相关文章

  1. Codeforces Round #532 (Div. 2)

    Codeforces Round #532 (Div. 2) A - Roman and Browser #include<bits/stdc++.h> #include<iostr ...

  2. Codeforces Round #532 (Div. 2) 题解

    Codeforces Round #532 (Div. 2) 题目总链接:https://codeforces.com/contest/1100 A. Roman and Browser 题意: 给出 ...

  3. Codeforces Round #466 (Div. 2) Solution

    从这里开始 题目列表 小结 Problem A Points on the line Problem B Our Tanya is Crying Out Loud Problem C Phone Nu ...

  4. 老年OIer的Python实践记—— Codeforces Round #555 (Div. 3) solution

    对没错下面的代码全部是python 3(除了E的那个multiset) 题目链接:https://codeforces.com/contest/1157 A. Reachable Numbers 按位 ...

  5. Codeforces Round #532 (Div. 2) F 线性基(新坑) + 贪心 + 离线处理

    https://codeforces.com/contest/1100/problem/F 题意 一个有n个数组c[],q次询问,每次询问一个区间的子集最大异或和 题解 单问区间子集最大异或和,线性基 ...

  6. Codeforces Round #545 (Div. 1) Solution

    人生第一场Div. 1 结果因为想D想太久不晓得Floyd判环法.C不会拆点.E想了个奇奇怪怪的set+堆+一堆乱七八糟的标记的贼难写的做法滚粗了qwq靠手速上分qwqqq A. Skyscraper ...

  7. Codeforces Round 500 (Div 2) Solution

    从这里开始 题目地址 瞎扯 Problem A Piles With Stones Problem B And Problem C Photo of The Sky Problem D Chemica ...

  8. Codeforces Round #532 (Div. 2):F. Ivan and Burgers(贪心+异或基)

    F. Ivan and Burgers 题目链接:https://codeforces.com/contest/1100/problem/F 题意: 给出n个数,然后有多个询问,每次回答询问所给出的区 ...

  9. Codeforces Round #532 (Div. 2)- B(思维)

    Arkady coordinates rounds on some not really famous competitive programming platform. Each round fea ...

随机推荐

  1. python2.0_s12_day13_javascript&Dom&jQuery

    今天主要内容:JavaScriptDomjQuery http://www.cnblogs.com/wupeiqi/articles/5369773.html 今天主要内容大致了解:javascrip ...

  2. Oracle函数的使用

    日期转换to_date insert into test (birthday,name) values (to_date('2016-03-12','yyyy-mm-dd'),'zy'); to_ch ...

  3. CentOs 设置静态IP 方法[测试没问题]

    首先关闭VMware的DHCP: Edit->Virtual Network Editor 选择VMnet8,去掉Use local DHCP service to distribute IP ...

  4. js正则函数match、exec、test、search、replace、split使用介绍集合,学习正则表达式的朋友可以参考下。

    match 方法 使用正则表达式模式对字符串执行查找,并将包含查找的结果作为数组返回. stringObj.match(rgExp) 参数 stringObj 必选项.对其进行查找的 String 对 ...

  5. 通过身份证分析出生年月日、性别、年龄的SQL语句

    ),) ) ),)<>'X' ) ) )<>'X' ),)),)),)) ),)),)),)) ) as int)) where [出生日期]<>'' #字符串格式 ...

  6. 简单的网络爬虫程序(Web Crawlers)

    程序比较简单,但是能体现基本原理. package com.wxisme.webcrawlers; import java.io.*; import java.net.*; /** * Web Cra ...

  7. 搭建FastDFS

    ---恢复内容开始--- FastDFS是用c语言编写的一款开源的分布式文件系统.FastDFS为互联网量身定制,充分考虑了冗余备份.负载均衡.线性扩容等机制,并注重高可用.高性能等指标,使用Fast ...

  8. JZOJ.5287【NOIP2017模拟8.16】最短路

    Description

  9. PHP获取POST的原始数据的方法

    一般我们都用$_POST或$_REQUEST两个预定义变量来接收POST提交的数据.但如果提交的数据没有变量名,而是直接的字符串,则需要使用其他的方式来接收. 方法一: 使用全局变量$GLOBALS[ ...

  10. Dell、IBM服务器配置远程管理卡

    author: headsen  chen date: 2018-10-09 14:12:32 1,IBM的服务器: 需要在bios里边进行配置,具体配置如下: , 开机画面过完之后,按F1进入bio ...