Codeforces Round #410 (Div. 2)
Codeforces Round #410 (Div. 2)
A B略..A没判本来就是回文WA了一次gg
C.Mike and gcd problem
题意:一个序列每次可以把\(a_i, a_{i+1}\)换成\(a_i-a_{i+1},a_i+a_{i+1}\),最小次数使gcd不为1
题解:
玩一下发现:
- 奇数 奇数 \(\rightarrow\) 偶数 偶数
- 奇数 偶数 $ \rightarrow$ 奇数 奇数 \(\rightarrow\) 偶数 偶数
最后都变成偶数好像就是最优啊,贪心变就行了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=1e5+5;
inline int read(){
char c=getchar(); int x=0,f=1;
while(c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
return x*f;
}
int n, a[N], d;
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a%b);}
int main() {
// freopen("in", "r", stdin);
n=read(); d = a[1] = read();
for(int i=2; i<=n; i++) a[i] = read(), d = gcd(d, a[i]);
if(d > 1) {puts("YES\n0"); return 0;}
for(int i=1; i<=n; i++) a[i] = a[i] & 1;
int ans = 0;
for(int i=1; i<=n; i++) if(a[i]) {
if(a[i+1]) ans++, a[i] = a[i+1] = 0;
else ans += 2, a[i] = 0;
}
printf("YES\n%d", ans);
}
D.Mike and distribution
题意:选\(\lfloor \frac{n}{2} \rfloor+1\)个数满足\(2*S_a > sum_a\)和\(2*S_b>sum_b\)
题解:
竟然没想出贪心。注意两点
- b每相邻两个数选较大值,最后一定>一半
- 选\(\lfloor \frac{n}{2} \rfloor+1\)个数,a排序后即使每相邻两个数选了较小值,再选一个最大的a根据坐标轴投影证明也可以>一半
比赛时想过随机但是没写,没想到真的能过,很难构造唯一解
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
inline int read(){
char c=getchar();int x=0,f=1;
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*f;
}
int n, c[N];
struct meow{
int a, b, id;
operator < (const meow &r) const {return a > r.a;}
} a[N];
int main() {
//freopen("in", "r", stdin);
n=read();
for(int i=1; i<=n; i++) a[i].a = read();
for(int i=1; i<=n; i++) a[i].b = read(), a[i].id = i;
sort(a+1, a+1+n);
printf("%d\n", n/2+1);
for(int i=1+(n&1); i<n; i+=2) {
if(a[i].b > a[i+1].b) c[a[i].id] = 1;
else c[a[i+1].id] = 1;
}
if(n&1) c[a[1].id] = 1;
else c[a[1].id] = c[a[2].id] = 1;
for(int i=1; i<=n; i++) if(c[i]) printf("%d ", i);
}
Codeforces Round #410 (Div. 2)的更多相关文章
- Codeforces Round #410 (Div. 2)C. Mike and gcd problem
题目连接:http://codeforces.com/contest/798/problem/C C. Mike and gcd problem time limit per test 2 secon ...
- Codeforces Round #410 (Div. 2)(A,字符串,水坑,B,暴力枚举,C,思维题,D,区间贪心)
A. Mike and palindrome time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- Codeforces Round #410 (Div. 2)A B C D 暴力 暴力 思路 姿势/随机
A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #410 (Div. 2) A. Mike and palindrome
A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #410 (Div. 2) A
Description Mike has a string s consisting of only lowercase English letters. He wants to change exa ...
- Codeforces Round #410 (Div. 2) A. Mike and palindrome【判断能否只修改一个字符使其变成回文串】
A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #410 (Div. 2)D题
D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces Round #410 (Div. 2)C题
C. Mike and gcd problem time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces Round #410 (Div. 2) B
B. Mike and strings time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- 重新学习一次javascript;
每次有项目的时候,总觉得自己什么都不会做,然后做的时候又很简单,一会就做完了,啪啪打脸: 每次别人问的时候,我知道怎么做,但是不知道具体原理,觉得瞬间low了: 想要好好的吧基础掌握一下: 这几天空闲 ...
- bat判断当前目录是否是根目录
记录下,一遍查用. @echo offif "%~p0"=="\" (echo 在根目录) else echo 不在根目录pause
- laravel中数据库在哪个文件中配置
我们使用 mysql 数据库,修改 .env: DB_HOST=localhost DB_DATABASE=laravel DB_USERNAME=root DB_PASSWORD= 在mysql中创 ...
- destoon数据库表解释说明
----------------------------- 公司认证:vcompany 实名认证:vtarde ============================================ ...
- pip install在Windows下报错解决
报错: Traceback (most recent call last): File, in<module> load_entry_point('pip==1.4.1','console ...
- zTree中父节点禁用,子节点可以用
参考学习网址:http://www.treejs.cn/v3/main.php#_zTreeInfo zTree中父节点禁用,子节点可以用 axios.get('/base/unit/unittree ...
- MySQL 多版本并发控制(MVCC)
可以认为MVCC是行级锁的一个变种,但是它在很多情况下避免了加锁的操作,因此开销会很低.主要实现的是非阻塞的读操作,写操作也只是锁定必要的行.MVCC的实现是通过保存数据在某个时间点的快照来实现的,也 ...
- __new__、__init__、__call__三个特殊方法
用双下划线包围的特殊方法在Python中又被成为魔术方法,类似于C++等语言中的构造函数,这里我们就来详解Python中的__new__.__init__.__call__三个特殊方法: 1.__ne ...
- Azure VM 防止被入侵
伴随着开源Linux系统的逐渐盛行,在机器上线之前配置好安全策略至关重要,分享几点有关Azure Linux VM机器的安全建议如下: 1.禁止root账号登录虚拟机,并增加密码的复杂度(大小写字母, ...
- 流API--提取流+组合流
提取子流和组合流 1,limit(n)会返回一个包含n个元素的新流,如果原始流的长度小于n,则会返回原始的流.这个方法可用来裁剪指定长度的流. 2,skip(n)正好相反,它会丢弃掉前面的n个元素. ...