Codeforces Round #532 (Div. 2) Solution
A. Roman and Browser
签到.
- #include <bits/stdc++.h>
- using namespace std;
- int n, k, a[];
- int get(int b)
- {
- int vis[];
- memset(vis, , sizeof vis);
- int c = b;
- while (c <= n)
- {
- vis[c] = ;
- c += k;
- }
- c = b - k;
- while (c >= )
- {
- vis[c] = ;
- c -= k;
- }
- int l = , r = ;
- for (int i = ; i <= n; ++i) if (!vis[i])
- {
- if (a[i] == ) ++l;
- else ++r;
- }
- return abs(l - r);
- }
- int main()
- {
- while (scanf("%d%d", &n, &k) != EOF)
- {
- for (int i = ; i <= n; ++i) scanf("%d", a + i);
- int res = ;
- for (int i = ; i <= n; ++i) res = max(res, get(i));
- printf("%d\n", res);
- }
- return ;
- }
B. Build a Contest
签到.
- #include <bits/stdc++.h>
- using namespace std;
- #define N 100010
- int n, m, a[N];
- int cnt[N];
- int main()
- {
- while (scanf("%d%d", &n, &m) != EOF)
- {
- for (int i = ; i <= m; ++i) scanf("%d", a + i);
- int need = n;
- memset(cnt, , sizeof cnt);
- for (int i = ; i <= m; ++i)
- {
- if (cnt[a[i]] == )
- --need;
- ++cnt[a[i]];
- if (need) putchar('');
- else
- {
- putchar('');
- for (int j = ; j <= n; ++j)
- {
- --cnt[j];
- if (!cnt[j])
- ++need;
- }
- }
- }
- puts("");
- }
- return ;
- }
C. NN and the Optical Illusion
签到.
- #include <bits/stdc++.h>
- using namespace std;
- const double eps = 1e-;
- const double PI = acos(-1.0);
- int main()
- {
- int n; double r;
- while (scanf("%d%lf", &n, &r) != EOF)
- {
- double ang1 = 2.0 * PI / n;
- double ang2 = (PI - ang1) / ;
- double R = (r * sin(ang1) * 1.0) / ( * sin(ang2) - sin(ang1));
- printf("%.10f\n", R);
- }
- return ;
- }
D. Dasha and Chess
Upsolved.
题意:
你有一个白王,对方有$666$个黑王
你每次可以八个方向走一步,对方可以任意移动一个黑王的位置
在$2000步以内如果你和某个黑王同行同列,你就赢了$
$给出你必胜的方案$
思路:
先走到中间,再考虑黑王个数最少的那个角落,向它的反方向走就可以了
考虑最差的情况,四个角很平均都有$166个左右$
那么也就是说另外三个角的个数加起来至少是$500个,而从中间走到某一角落只需要499步$
所以一定可以包围一个
- #include <bits/stdc++.h>
- using namespace std;
- #define N 1010
- #define pii pair <int, int>
- #define x first
- #define y second
- int G[N][N], x, y, cnt[];
- pii cor[N];
- void Move(int edx, int edy)
- {
- while (x != edx || y != edy)
- {
- if (x < edx && G[x + ][y] == ) ++x;
- else if (x > edx && G[x - ][y] == ) --x;
- if (y < edy && G[x][y + ] == ) ++y;
- else if (y > edy && G[x][y - ] == ) --y;
- printf("%d %d\n", x, y);
- fflush(stdout);
- int k, a, b;
- scanf("%d%d%d", &k, &a, &b);
- if (k == -) exit();
- G[cor[k].x][cor[k].y] = ;
- cor[k].x = a, cor[k].y = b;
- G[cor[k].x][cor[k].y] = ;
- }
- }
- int main()
- {
- while (scanf("%d%d", &x, &y) != EOF)
- {
- memset(G, , sizeof G);
- for (int i = ; i <= ; ++i)
- {
- scanf("%d%d", &cor[i].x, &cor[i].y);
- G[cor[i].x][cor[i].y] = ;
- }
- Move(, );
- memset(cnt, , sizeof cnt);
- for (int i = ; i <= ; ++i)
- for (int j = ; j <= ; ++j)
- if (G[i][j])
- {
- if (i < x && j < y) ++cnt[];
- else if (i < x && j > y) ++cnt[];
- else if (i > x && j < y) ++cnt[];
- else ++cnt[];
- }
- if (cnt[] <= ) Move(, );
- else if (cnt[] <= ) Move(, );
- else if (cnt[] <= ) Move(, );
- else Move(, );
- }
- return ;
- }
E. Andrew and Taxi
Upsolved.
题意:
给出一张有向图,求改变一些边使得它没有环
改变一条边的花费是它的边权,要使得最大花费最小
输出最大花费和需要改变的边数
再输出相应的边
思路:
先二分答案,每次check的时候检查一下边权大于limit的边组成的图是否有环
如果有环,那么一定不行,如果没有环,那么一定可以
对于剩下的边,方向自定,拓扑序小的连向拓扑序大的
- #include <bits/stdc++.h>
- using namespace std;
- #define N 100010
- int n, m;
- struct Graph
- {
- struct node
- {
- int to, nx, w, id;
- node() {}
- node (int to, int nx, int w, int id) : to(to), nx(nx), w(w), id(id) {}
- }a[N << ];
- int head[N], pos;
- void init()
- {
- memset(head, , sizeof head);
- pos = ;
- }
- void add(int u, int v, int w, int id)
- {
- a[++pos] = node(v, head[u], w, id); head[u] = pos;
- }
- }G;
- #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)
- int degree[N], ord[N];
- bool check(int x)
- {
- memset(degree, , sizeof degree);
- for (int i = ; i <= n; ++i) erp(i) if (w > x)
- ++degree[v];
- int cnt = ;
- queue <int> q;
- for (int i = ; i <= n; ++i) if (!degree[i])
- q.push(i);
- while (!q.empty())
- {
- ++cnt;
- int u = q.front(); q.pop();
- ord[u] = cnt;
- erp(u) if (w > x && --degree[v] == )
- q.push(v);
- }
- return cnt >= n;
- }
- int main()
- {
- while (scanf("%d%d", &n, &m) != EOF)
- {
- G.init();
- for (int i = , u, v, w; i <= m; ++i)
- {
- scanf("%d%d%d", &u, &v, &w);
- G.add(u, v, w, i);
- }
- int l = , r = (int)1e9, res = -;
- while (r - l >= )
- {
- int mid = (l + r) >> ;
- if (check(mid))
- {
- res = mid;
- r = mid - ;
- }
- else
- l = mid + ;
- }
- vector <int> vec;
- check(res);
- for (int i = ; i <= n; ++i) erp(i) if (w <= res && ord[i] > ord[v]) vec.push_back(id);
- printf("%d %d\n", res, (int)vec.size());
- for (int i = , len = vec.size(); i < len; ++i) printf("%d%c", vec[i], " \n"[i == len - ]);
- }
- return ;
- }
F. Ivan and Burgers
Upsolved.
题意:
询问区间任意数异或最大值
思路:
维护前缀线性基,但是要注意将$位置id大的数更换基底$
$因为这样这些基底被用户更新答案的概率就更高$
- #include <bits/stdc++.h>
- using namespace std;
- #define N 500010
- int n, q, c[N];
- int pos[N][], p[N][];
- void work(int x)
- {
- for (int i = ; i <= ; ++i)
- {
- pos[x][i] = pos[x - ][i];
- p[x][i] = p[x - ][i];
- }
- int tmp = c[x];
- int id = x;
- for (int i = ; i >= ; --i)
- {
- if ((tmp >> i) & )
- {
- if (!p[x][i])
- {
- p[x][i] = tmp;
- pos[x][i] = id;
- return;
- }
- if (pos[x][i] < id)
- {
- swap(tmp, p[x][i]);
- swap(id, pos[x][i]);
- }
- tmp ^= p[x][i];
- }
- }
- }
- int ask(int l, int r)
- {
- int res = ;
- for (int i = ; i >= ; --i) if (pos[r][i] >= l && (res ^ p[r][i]) > res)
- res ^= p[r][i];
- return res;
- }
- int main()
- {
- while (scanf("%d", &n) != EOF)
- {
- for (int i = ; i <= n; ++i) scanf("%d", c + i);
- for (int i = ; i < ; ++i) pos[][i] = p[][i] = ;
- for (int i = ; i <= n; ++i) work(i);
- scanf("%d", &q);
- for (int qq = , l, r; qq <= q; ++qq)
- {
- scanf("%d%d", &l, &r);
- printf("%d\n", ask(l, r));
- }
- }
- return ;
- }
Codeforces Round #532 (Div. 2) Solution的更多相关文章
- Codeforces Round #532 (Div. 2)
Codeforces Round #532 (Div. 2) A - Roman and Browser #include<bits/stdc++.h> #include<iostr ...
- Codeforces Round #532 (Div. 2) 题解
Codeforces Round #532 (Div. 2) 题目总链接:https://codeforces.com/contest/1100 A. Roman and Browser 题意: 给出 ...
- Codeforces Round #466 (Div. 2) Solution
从这里开始 题目列表 小结 Problem A Points on the line Problem B Our Tanya is Crying Out Loud Problem C Phone Nu ...
- 老年OIer的Python实践记—— Codeforces Round #555 (Div. 3) solution
对没错下面的代码全部是python 3(除了E的那个multiset) 题目链接:https://codeforces.com/contest/1157 A. Reachable Numbers 按位 ...
- Codeforces Round #532 (Div. 2) F 线性基(新坑) + 贪心 + 离线处理
https://codeforces.com/contest/1100/problem/F 题意 一个有n个数组c[],q次询问,每次询问一个区间的子集最大异或和 题解 单问区间子集最大异或和,线性基 ...
- Codeforces Round #545 (Div. 1) Solution
人生第一场Div. 1 结果因为想D想太久不晓得Floyd判环法.C不会拆点.E想了个奇奇怪怪的set+堆+一堆乱七八糟的标记的贼难写的做法滚粗了qwq靠手速上分qwqqq A. Skyscraper ...
- Codeforces Round 500 (Div 2) Solution
从这里开始 题目地址 瞎扯 Problem A Piles With Stones Problem B And Problem C Photo of The Sky Problem D Chemica ...
- Codeforces Round #532 (Div. 2):F. Ivan and Burgers(贪心+异或基)
F. Ivan and Burgers 题目链接:https://codeforces.com/contest/1100/problem/F 题意: 给出n个数,然后有多个询问,每次回答询问所给出的区 ...
- Codeforces Round #532 (Div. 2)- B(思维)
Arkady coordinates rounds on some not really famous competitive programming platform. Each round fea ...
随机推荐
- python2.0_s12_day13_javascript&Dom&jQuery
今天主要内容:JavaScriptDomjQuery http://www.cnblogs.com/wupeiqi/articles/5369773.html 今天主要内容大致了解:javascrip ...
- Oracle函数的使用
日期转换to_date insert into test (birthday,name) values (to_date('2016-03-12','yyyy-mm-dd'),'zy'); to_ch ...
- CentOs 设置静态IP 方法[测试没问题]
首先关闭VMware的DHCP: Edit->Virtual Network Editor 选择VMnet8,去掉Use local DHCP service to distribute IP ...
- js正则函数match、exec、test、search、replace、split使用介绍集合,学习正则表达式的朋友可以参考下。
match 方法 使用正则表达式模式对字符串执行查找,并将包含查找的结果作为数组返回. stringObj.match(rgExp) 参数 stringObj 必选项.对其进行查找的 String 对 ...
- 通过身份证分析出生年月日、性别、年龄的SQL语句
),) ) ),)<>'X' ) ) )<>'X' ),)),)),)) ),)),)),)) ) as int)) where [出生日期]<>'' #字符串格式 ...
- 简单的网络爬虫程序(Web Crawlers)
程序比较简单,但是能体现基本原理. package com.wxisme.webcrawlers; import java.io.*; import java.net.*; /** * Web Cra ...
- 搭建FastDFS
---恢复内容开始--- FastDFS是用c语言编写的一款开源的分布式文件系统.FastDFS为互联网量身定制,充分考虑了冗余备份.负载均衡.线性扩容等机制,并注重高可用.高性能等指标,使用Fast ...
- JZOJ.5287【NOIP2017模拟8.16】最短路
Description
- PHP获取POST的原始数据的方法
一般我们都用$_POST或$_REQUEST两个预定义变量来接收POST提交的数据.但如果提交的数据没有变量名,而是直接的字符串,则需要使用其他的方式来接收. 方法一: 使用全局变量$GLOBALS[ ...
- Dell、IBM服务器配置远程管理卡
author: headsen chen date: 2018-10-09 14:12:32 1,IBM的服务器: 需要在bios里边进行配置,具体配置如下: , 开机画面过完之后,按F1进入bio ...