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 ...
随机推荐
- divmod()
divmod() 接收两个数值,然后以元组的形式返回这两个数值的商和余数 In [1]: divmod(5, 2) Out[1]: (2, 1) In [2]: divmod(10, 7) Out[2 ...
- Sphinx以及coreseek的安装及使用 .No1
检索结构php -> sphinx -> mysql非结构化数据又叫全文数据,非固定长度字段例如文章标题搜索这类适用sphinx 全文数据搜索:顺序扫描 : 如like查找索引扫描 : 把 ...
- coreseek/sphinx CentOS6.4下安装
一.在CentOS6.4下安装coreseek之前需要预先安装以下软件 1.打开终端 输入 su 获取管理员权限 2.输入命令 yum install make gcc g++ gcc-c++ lib ...
- 【Android N 7.1.1】 ActivityManagerService 获取cpu状态
void updateCpuStatsNow() { synchronized (mProcessCpuTracker) { mProcessCpuMutexFree.set(false); fina ...
- ios UITableView默认选中第一行
NSIndexPath *ip = [NSIndexPath indexPathForRow:0inSection:0]; [titleTableViewselectRowAtIndexPath:ip ...
- 170504、MongoDB和MySQL对比(译)
一.概要 几十年来,关系型数据库已经成为企业应用程序的基础,自从MySQL在1995年发布以来,它已经成为一种受欢迎并且廉价的选择.然而随着近年来数据量和数据的不断激增,非关系数据库技术如MongoD ...
- Windows下Git免密码pull&push
Windows下Git在使用http方式的时候clone,pull,push需要输入用户名及密码,通过以下设置可以免密码 在用户文件夹创建文件.git-credentials内容如下 https:// ...
- 关于#ifndef以及#ifndef WIN32
一般用法是这样的: 这里可以定义如下: #define XXXXX #ifdef XXXXX 这里做一些操作,这些操作只有在XXXX已经被define的情况下才会执行到.一般还可能有else,如 #e ...
- SQL---->mySQl卸载for mac
因为装的时候弄坏了 先来学习下怎么卸载吧,如下输入终端就好了 cd ~/ sudo rm /usr/local/mysql sudo rm -rf /usr/local/mysql* sudo rm ...
- Python大数据:jieba 中文分词,词频统计
# -*- coding: UTF-8 -*- import sys import numpy as np import pandas as pd import jieba import jieba. ...