[CF798D]Mike and distribution_贪心
Mike and distribution
题目链接:http://codeforces.com/problemset/problem/798/D
数据范围:略。
题解:
太难了吧这个题.....
这种贪心根本就不咋会....接下来刷一段时间Atcoder看看好了.....
就是想到先把所有的对按照$a$排序。
然后刨除第一个外,相邻的两个分组。
第一个数单独一组,剩下的两两一组选$b$值较大的那对即可。
证明:
首先,因为我们按照$a$排序,所以上一组的选取的$a$一定不比当前组剩下的$a$小,故此$a$数列满足条件。
紧接着,因为后面的每一组中,$b$值我们选择的是较大者,故此$b$数列满足条件。
证毕。
代码:
#include <bits/stdc++.h>
#define setIO(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define N 1000010
using namespace std;
char *p1, *p2, buf[100000];
#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++ )
int rd() {
int x = 0;
char c = nc();
while (c < 48) {
c = nc();
}
while (c > 47) {
x = (((x << 2) + x) << 1) + (c ^ 48), c = nc();
}
return x;
}
struct Node {
int x, y, id;
}a[N];
inline bool cmp(const Node &a, const Node &b) {
return a.x > b.x;
}
int main() {
// setIO("game");
int n = rd();
for (int i = 1; i <= n; i ++ ) {
a[i].x = rd(), a[i].id = i;
}
for (int i = 1; i <= n; i ++ ) {
a[i].y = rd();
}
sort(a + 1, a + n + 1, cmp);
printf("%d\n%d ", n / 2 + 1, a[1].id);
for (int i = 2; i <= n; i += 2) {
if (a[i].y > a[i + 1].y) {
printf("%d ", a[i].id);
}
else {
printf("%d ", a[i + 1].id);
}
}
return 0;
}
[CF798D]Mike and distribution_贪心的更多相关文章
- CF798D Mike and distribution 贪心
我感觉这道题挺神的~ 假设 $a[i]=b[i]$,那么我们可以将 $a$ 降序排序,然后你发现只要你按照 $1,3,5......n$ 这么取一定是合法的. 而我们发现 $2$ 比取 $3$ 优,取 ...
- CF798D Mike and distribution
CF798D Mike and distribution 洛谷评测传送门 题目描述 Mike has always been thinking about the harshness of socia ...
- Codeforces 798D Mike and distribution - 贪心
Mike has always been thinking about the harshness of social inequality. He's so obsessed with it tha ...
- Codeforces 798D Mike and distribution(贪心或随机化)
题目链接 Mike and distribution 题目意思很简单,给出$a_{i}$和$b_{i}$,我们需要在这$n$个数中挑选最多$n/2+1$个,使得挑选出来的 $p_{1}$,$p_{2} ...
- 【算法系列学习】codeforces D. Mike and distribution 二维贪心
http://codeforces.com/contest/798/problem/D http://blog.csdn.net/yasola/article/details/70477816 对于二 ...
- Mike and distribution CodeForces - 798D (贪心+思维)
题目链接 TAG: 这是我近期做过最棒的一道贪心思维题,不容易想到,想到就出乎意料. 题意:给定两个含有N个正整数的数组a和b,让你输出一个数字k ,要求k不大于n/2+1,并且输出k个整数,范围为1 ...
- codeforces 798 D. Mike and distribution(贪心+思维)
题目链接:http://codeforces.com/contest/798/problem/D 题意:给出两串长度为n的数组a,b,然后要求长度小于等于n/2+1的p数组是的以p为下表a1-ap的和 ...
- codeforces 798 C. Mike and gcd problem(贪心+思维+数论)
题目链接:http://codeforces.com/contest/798/problem/C 题意:给出一串数字,问如果这串数字的gcd大于1,如果不是那么有这样的操作,删除ai, ai + 1 ...
- CodeForce-798C Mike and gcd problem(贪心)
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., b ...
随机推荐
- Activiti服务类- FormService服务类
转自:https://www.cnblogs.com/liuqing576598117/p/9814953.html 1.获取//通过流程定义ID获取表单字段集合StartFormData start ...
- myeclipse打开jsp后死掉,或变卡的问题
很多小伙伴在myeclipse下打开jsp会特别卡,甚至会卡死掉,我也遇到过很多次这种情况,下面分享一下解决方法: 1,打开 Window -> Preferences -> Genera ...
- Web应用运行原理
web应用启动做了什么? 读取web.xml文件 - web.xml常用配置参数: 1).context-param(上下文参数)2).listener(监听器配置参数)3).filter(过滤器 ...
- 什么是CSR
CSR的全称是Certificate Signing Request. 是我们在申请Https证书是向CA所提供的一杯申请书.其内部储存了我们申请证书所需要的基本信息.它是一个经过Base64编码的纯 ...
- AcWing:244. 谜一样的牛(树状数组 + 二分)
有n头奶牛,已知它们的身高为 1~n 且各不相同,但不知道每头奶牛的具体身高. 现在这n头奶牛站成一列,已知第i头牛前面有AiAi头牛比它低,求每头奶牛的身高. 输入格式 第1行:输入整数n. 第2. ...
- poj 1458 Common Subsequence ——(LCS)
虽然以前可能接触过最长公共子序列,但是正规的写应该还是第一次吧. 直接贴代码就好了吧: #include <stdio.h> #include <algorithm> #inc ...
- Js中Array常用方法小结
说起Array的方法,不免让人皱一下眉头,下面我们从增删改查角度依次来总结. 1.增 push: 将传入的参数 ,插入数组的尾部,并返回新数组的长度.不管传入参数为一个值还是一个数组,都作为插入数组的 ...
- 计算机中buffer和cache的理解
Linux中Buffer和Cache的区别 Cache 和 Buffer的区别 作者:知乎用户链接:https://www.zhihu.com/question/26190832/answer/323 ...
- AtomicInteger原理
AtomicInteger的原理 java的并发原子包里面提供了很多可以进行原子操作的类,比如: AtomicInteger AtomicBoolean AtomicLong AtomicRefere ...
- MySQL 慢查询日志介绍
转: MySQL 慢查询日志介绍 2018年08月23日 08:47:40 曾梦想仗剑走天涯XX 阅读数 1104 一. 慢查询介绍 MySQL的慢查询日志是MySQL提供的一种日志记录,它用来记 ...