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. WEB 小案例 -- 网上书城(一)

    距离上次写博客有两周了吧,最多的原因就是自己期末考试了,上课没听就只能在期末狠狠的复习了,毕竟已经挂科了.当然还是因为自己懒吧!!!废话不多说开始我们今天的正题,网上书城! 一. 新建数据表(MySQ ...

  2. Spring Boot实战:静态资源处理

    前两章我们分享了Spring boot对Restful 的支持,不过Restful的接口通常仅仅返回数据.而做web开发的时候,我们往往会有很多静态资源,如html.图片.css等.那如何向前端返回静 ...

  3. JXLS 2.4.0系列教程(三)——嵌套循环是怎么做到的

    注:本文代码在第一篇文章基础上修改而成,请务必先阅读第一篇文章. http://www.cnblogs.com/foxlee1024/p/7616987.html 本文也不会过多的讲解模板中遍历表达式 ...

  4. 常用Windows DOS命令项目部署经常用到

    img { max-width: 100% } 前两天部署.netcore项目,首先是生产环境域名访问不了,再到.netcore项目IIS部署502.5,在到莫名其妙的500,在排查项目部署问题的时候 ...

  5. 关于Set对象(ES6)

    今天初次接触ES6,发现确实挺神奇的,许多用以前方法去实现需要一大串代码的,用ES6竟然几句就搞定了. 这里我要说的是Set对象.Set对象是ES6中新增的类型,可以自动排除重复项,生成Set对象后, ...

  6. mysql数据库备份及还原

    数据库备份代码: package com.gd.test; import java.io.BufferedReader; import java.io.FileOutputStream; import ...

  7. Node.js/Vue环境搭配安装

    http://blog.sina.com.cn/s/blog_497ff1a70102x0sw.html 第一次接触Node.js,想创建自己的服务就须配置好Node.js环境 安装Node.js 下 ...

  8. win7系统如何在防火墙里开放端口

    用到的端口需要在防火墙里开放,win7的比XP的要复杂一些,此方法同样适用于server2008系统 方法/步骤 1 依次点击"开始"-"控制面板"-" ...

  9. 你知道织梦后台安装插件时为什么会出现这个Character postion 686, 'item'&n

    https://zhidao.baidu.com/question/589525064.html?qbl=relate_question_3&word=Tag Character postio ...

  10. 织梦中data文件夹是存放什么内容的

    dede(织梦)的data文件夹下的文件及文件夹也不少,我们来一个一个的介绍下. 1. admin文件夹 admin文件夹 管理员用到的文件夹,一般是后台的配置文件. 第一个文件,idc.txt 配置 ...