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

题解:

玩一下发现:

  1. 奇数 奇数 \(\rightarrow\) 偶数 偶数
  2. 奇数 偶数 $ \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\)

题解:

竟然没想出贪心。注意两点

  1. b每相邻两个数选较大值,最后一定>一半
  2. 选\(\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)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. Codeforces Round #410 (Div. 2) A

    Description Mike has a string s consisting of only lowercase English letters. He wants to change exa ...

  6. 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 ...

  7. Codeforces Round #410 (Div. 2)D题

    D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  8. 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 ...

  9. Codeforces Round #410 (Div. 2) B

    B. Mike and strings time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. 深入设计电子计算器(一)——CPU框架及指令集设计

    版权申明:本文为博主窗户(Colin Cai)原创,欢迎转帖.如要转贴,必须注明原文网址 http://www.cnblogs.com/Colin-Cai/p/8278418.html 作者:窗户 Q ...

  2. HTML5 Canvas 数据持久化存储之属性列表

    属性列表想必大家都不会陌生,正常用 HTML5 来做的属性列表大概就是用下拉菜单之类的,而且很多情况下,下拉列表还不够好看,怎么办?我试着用 HT for Web 来实现属性栏点击按钮弹出多功能选框, ...

  3. [国嵌攻略][098][Linux内核简介]

    Linux系统架构 1.用户空间:应用程序.C函数库 2.内核空间:系统调用接口.内核.体系结构相关代码 Linux系统利用处理器不同的工作模式,使用其中的两个级别分别来运行Linux内核与应用程序, ...

  4. 从零开始学习前端开发 — 14、CSS3变形基础

    一.css3变形: transform:rotate(旋转)|scale(缩放)|skew(倾斜)|translate(位移); 注:当多种变形方式综合在一起时,用空格隔开 1.旋转 a) rotat ...

  5. How to find missing USB Records?

    In my previously article "EnCase missed some USB activities in the evidence files", I ment ...

  6. 如何用SVN版本控制器将提交的文件还原到以前的版本

    工具/原料 SVN乌龟软件和相关的文件 方法/步骤 在相关的文件中右击鼠标,按右图进行选择 在弹出框的地方点击我标记的地方,查看下曾经提交过的版本文件 在弹出框的地方,上面就是有版本号,下面就是我们文 ...

  7. 这个时间格式2017-09-26-T04:00:00Z php识别不出来

    这应该不对吧 这是什么格式?看起来不标准,一般不都是传 2017-09-26 04:00:00 这种吗?不行用正则筛吧.echo date('Y-m-d H:i:s',date_create_from ...

  8. SecurityException

    摘录自http://www.cnblogs.com/haorenjie/archive/2012/09/12/2682655.html public boolean checkNetwork() { ...

  9. myeclipse10不用打开myeclipse configuration center安装插件的方法

    我使用myeclipse10,网上找了一大堆的插件安装方法,全部都是要通过help->myeclipse configuration center进行安装 不用打开myeclipse  conf ...

  10. oracle01

    01-基本的查询语句 A:一些命令 sqlplus sys/sys@192.168.22.220:1521/orcl as sysdba; conn scott/123456@192.168.22.2 ...