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的更多相关文章

  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. 使用loadrunner进行压力测试遇到的问题总结

    本人整理了一个LR使用过程中遇到的各种问题的总结文档,有需要可以加QQ群169974486下载. 一.无法生成虚拟用户,运行报错:CCI compilation error -vuser_init.c ...

  2. python处理文本文件

    在测试任务过程中都或多或少遇到自己处理文本文件的情况. 举个栗子: 客户端测试从异常日志中收集有用信息. 后端测试需要创建各种规则的压力的词表. ... 这里给大家分享一个使用python脚本处理文本 ...

  3. NUC131的系统管理

    系统复位系统复位可以由如下的任何一种中断实现,这些复位中断标志可以通过寄存器RSTSRC读取. 上电复位 nRESET引脚低电平复位 看门狗复位 低压复位 欠压检测器复位 CPU 复位 ...

  4. Android 使用WebView显示网页

    构建WebView就可以显示Web信息.因为我觉得这里会讲述很多方式来实现WebView,所以我决定为每一种方式创建一个对应的Activity,MainActivity通过Button可以点击进入对应 ...

  5. Kconfig和Makefile的修改

    Kconfig文件的作用 内核源码树的目录下都有两个文件Kconfig(2.4版本是Config.in)和Makefile.分布到各目录的Kconfig构成了一个分布式的内核配置数据库,每个Kconf ...

  6. nginx 重复提交 重复请求问题

    我遇到的奇葩问题. 后台使用的是nginx + tomcat 前端页面确实只发送了一个ajax请求到后台. 后台却接收到了两条请求! 百度了一下,说是因为nginx负载均衡,一个请求超时后会重复发送一 ...

  7. JS选中清空

    var inputArray = document.getElementsByTagName("input"); var strArray = []; ; i < input ...

  8. Java三方---->pdf框架之IText的使用

    在企业的信息系统中,报表处理一直占比较重要的作用t.通过在服务器端使用Jsp或JavaBean生成PDF报表,客户端采用超链接显示或下载得到生成的报表,这样就很好的解决了B/S系统的报表处理问题.今天 ...

  9. Java中迭代器实现的原理

    一. 引言 迭代这个名词对于熟悉Java的人来说绝对不陌生.我们常常使用JDK提供的迭代接口进行java collection的遍历: Iterator it = list.iterator();wh ...

  10. poj3349 Snowflake Snow Snowflakes【HASH】

    Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 49991   Accep ...