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. 自制ZigBee协议分析仪

    关键词  ZigBee  Sniffer 协议  分析仪  自制  CC2530  CC2531 在开发ZigBee / Bluetooth的过程,难免会要用到Sniffer工具,Packet Sni ...

  2. gettype

    取得变量的类型. 语法: string gettype(mixed var); 返回值: 字符串 函数种类: PHP 系统功能 内容说明 本函数用来取得变量的类型.返回的类型字符串可能为下列字符串其中 ...

  3. 遇到安装app不识别的情况

    一般->blokfile->证书设定设置

  4. intent详解(一)

    摘录自:http://blog.csdn.net/harvic880925/article/details/38399723 前言:通过重新翻看Android入门书籍,才发现原来自己露掉了那么多基础知 ...

  5. Jpa 本地方式实现数据的持久化【千锋】

    Jpa本身支持多种方式的对象持久化,比如数据库方式,还有一种方式就是本地文件的方式,本文来讲解以本地方式实现的数据持久化,具体的资源大家可以参阅一下网站:http://www.objectdb.com ...

  6. Java的栈和队列

    package com.ipmotor.sm.db;import java.util.LinkedList;import java.util.Queue;import java.util.Stack; ...

  7. webpack+vuecli打包生成资源相对引用路径与背景图片的正确引用

    资源相对引用路径 问题描述 一般情况下,通过webpack+vuecli默认打包的css.js等资源,路径都是绝对的. 但当部署到带有文件夹的项目中,这种绝对路径就会出现问题,因为把配置的static ...

  8. python_18_反射

    什么是反射? -- 通过输入字符串来获取和修改 类(属性+方法),用字符串来映射内存对象,用于人机交互 反射有哪几种方法? -- getattr()                   --获取字符串 ...

  9. 剑指offfer:二维数组中的查找

    题目:在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成这样一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. 例如: 1    2  ...

  10. 自己写的日志框架--linkinLog4j--日志框架的必要性

    OK,在开始研究Log4j的源码之前,我们先来自己模拟一个日志工具,名字就叫linkinlog4j好了. 在软件开发过程中,出现bug总是在所难免:事实上,以我个人经验,即使在实际开发阶段,fix b ...