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 ...
随机推荐
-
STP的作用和操作
STP的作用 STP通过阻塞端口来消除环路,并能够实现链路备份的目的 STP的操作 选举一个根桥 比较交换机的桥ID,越小越优先 桥ID 是8个字节,2个字节的优先级+6个字节的MAC地址 2.每个 ...
-
[转载] YouCompleteMe
原文: http://blog.marchtea.com/archives/161#rd?sukey=fc78a68049a14bb2ba33c15948d34749e1eb616df07efe977 ...
-
qt编写一个只能运行单个实例的程序,不用Windows API
QtSingleApplicationhttp://code.qt.io/cgit/qt-solutions/qt-solutions.git/tree/qtsingleapplication 已打开 ...
-
02-4. BCD解密(10)
BCD数是用一个字节来表达两位十进制的数,每四个比特表示一位.所以如果一个BCD数的十六进制是0x12,它表达的就是十进制的12.但是小明没学过BCD,把所有的BCD数都当作二进制数转换成十进制输出了 ...
-
power designer的安装
PowerDesigner的安装 原由:新学期要开概要设计(软件设计与体系结构)这门课,老师推荐了两个CASE工具. Rational Rose Power Designer 本来想找rose的资源, ...
-
codis
总体架构 192.168.199.223(zookeeper.codis-proxy.codis-dashborad:18080.codis-fe:18090.codis-server) 192.16 ...
-
手写自己的ThreadLocal(线程局部变量)
ThreadLocal对象通常用于防止对可变的单实例变量或全局变量进行共享. 精简版: public class MyThreadLocal<T> { private Map<Thr ...
-
浅谈javascript函数,变量声明及作用域
javascript函数跟变量的声明.作用域这些概念网上都已经讲烂了. 这里写个博客,也相当于做个笔记. 变量声明 首先看个例子: var globalVar = "gv"; fu ...
-
CoolViewPager:即刻刷新,自定义边缘效果颜色,双向自动循环,内置垂直切换效果,想要的都在这里
这两天在GitHub上传了一个自定义ViewPager:CoolViewPager,具有以下功能特征: 支持水平及垂直方向循环滚动 支持自动滚动 支持自动滚动方向.滚动时间.间隔时间的设置 支持调用n ...
-
1.1 由C++Builder 6.0 通向OpenGL(1)
http://book.51cto.com/art/201104/255588.htm 第1章 架好通向OpenGL的桥 本章主要是为以后进行的OpenGL编程进行一些铺垫工作.主要内容有:Open ...