[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服务类- HistoryService服务类
转自:https://www.cnblogs.com/liuqing576598117/p/11164027.html 一共个方法15个方法 用于查询历史工作流信息1.创建查询(7个方法)//创建一个 ...
- Activiti服务类- FormService服务类
转自:https://www.cnblogs.com/liuqing576598117/p/9814953.html 1.获取//通过流程定义ID获取表单字段集合StartFormData start ...
- Start Failed, Internal error: recovering IDE to the working state after the critical startup error
Start Failed, Internal error: recovering IDE to the working state after the critical startup error F ...
- 下载文件设置header的filename要用ISO8859-1编码的原因
很多情况下,我们在写程序的时候都会把代码设置为UTF-8的编码,可以在下载文件设置filename的时候却有违常理,竟然设置编码格式为ISO8859-1,代码如下(如是英文的话就不需要这样处理了): ...
- 编写测试类实现并发访问固定URL(亲测能用!!!)
1.类目录 2.LatchTest.java类 package com.test; import java.util.concurrent.CountDownLatch; public class L ...
- fixed 失效
1. 父元素设置 transform 属性后, 会导致 position: fixed 失效. 2. 设置以下属性也会影响 fixed 属性. -webkit-perspective: 1000; - ...
- 2019.6.28 校内测试 T2 【音乐会】二重变革
看到这个题之后,一个很暴力很直接的想法就是贴上题目中的代码然后交上去走人,但是很显然这是会TLE+MLE的,想想谁会这么傻把主要代码给你QwQ~: 其实这段代码是想告诉你一件事:用序列中的大数减去小数 ...
- HDU 1114 Piggy-Bank ——(完全背包)
差不多是一个裸的完全背包,只是要求满容量的最小值而已.那么dp值全部初始化为inf,并且初始化一下dp[0]即可.代码如下: #include <stdio.h> #include < ...
- sql语句 基本
1.sql不区分大小写,一般结尾要加分号: 2.select 列,列,列 from 表 3.distinct ,返回列中不同的值.需要哪个列不同,关键词哪个列 4.where子句,select 列 f ...
- linux提权方法(不断总结更新)
目录 1.suid提权 2.rbash绕过 3.git提权 4.Linux Kernel 4.4.x (Ubuntu 16.04) - 'double-fdput()' bpf(BPF_PROG_LO ...