[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 ...
随机推荐
- SessionState,默認mode應該是"InProc"
在ASP.NET的sessionState的三種屬性 http://www.dotblogs.com.tw/boei/archive/2010/07/06/16414.aspx需要在另外的config ...
- ueditor实现ctrl+v粘贴word图片并上传
图片的复制无非有两种方法,一种是图片直接上传到服务器,另外一种转换成二进制流的base64码 目前限chrome浏览器使用,但是项目要求需要支持所有的浏览器,包括Windows和macOS系统.没有办 ...
- [Luogu] 借教室
https://www.luogu.org/problemnew/show/P1083 二分第i天不满足 前缀和 + 差分判断 #include <iostream> #include & ...
- Linux之创建多个子进程
/*** fork_test.c ***/ #include<stdio.h> #include<stdlib.h> #include<unistd.h> int ...
- 存在日期类型的JSON数据,进行SpringMVC参数绑定时存在的问题和解决方案
这篇文章已经过时了. 请参考比较合适的前后端交互方式. 首先是发送AJAX请求的html页面 <!DOCTYPE html> <html> <head> <m ...
- 学院管理系统(mysql版)
需求 用户角色,讲师\学员, 用户登陆后根据角色不同,能做的事情不同,分别如下 讲师视图 管理班级,可创建班级,根据学员qq号把学员加入班级 可创建指定班级的上课纪录,注意一节上课纪录对应多条学员的上 ...
- 基于Ryu REST API的VLAN实现
目录 0.预备知识 1.实验内容 2.编写脚本addflow.sh一步实现流表下发 3.使用api查看流表 4.实验结果 0.预备知识 ryu控制器的API文档:ryu.app.ofctl_rest ...
- elasticsearch java client
1.集群名相同,且机器处于同一局域网同一网段,es会自动去发现其他的节点.2.集群不在同一局域网同一网段时,只需要在 elasticsearch.yml 中配置目标机器和端口即可discovery.z ...
- python 进程池和任务量变化测试
今天闲,测试了下concurrent.futures 模块中的ThreadPoolExecutor,ProcessPoolExecutor. 对开不同的数量的进程池和任务量时,所耗时间. from c ...
- 利用 force index优化sql语句性能
[转自:https://blog.csdn.net/bruce128/article/details/46777567]并进行总结 今天写了一个统计sql,在一个近亿条数据的表上执行,200s都查不出 ...