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_贪心的更多相关文章

  1. CF798D Mike and distribution 贪心

    我感觉这道题挺神的~ 假设 $a[i]=b[i]$,那么我们可以将 $a$ 降序排序,然后你发现只要你按照 $1,3,5......n$ 这么取一定是合法的. 而我们发现 $2$ 比取 $3$ 优,取 ...

  2. CF798D Mike and distribution

    CF798D Mike and distribution 洛谷评测传送门 题目描述 Mike has always been thinking about the harshness of socia ...

  3. Codeforces 798D Mike and distribution - 贪心

    Mike has always been thinking about the harshness of social inequality. He's so obsessed with it tha ...

  4. Codeforces 798D Mike and distribution(贪心或随机化)

    题目链接 Mike and distribution 题目意思很简单,给出$a_{i}$和$b_{i}$,我们需要在这$n$个数中挑选最多$n/2+1$个,使得挑选出来的 $p_{1}$,$p_{2} ...

  5. 【算法系列学习】codeforces D. Mike and distribution 二维贪心

    http://codeforces.com/contest/798/problem/D http://blog.csdn.net/yasola/article/details/70477816 对于二 ...

  6. Mike and distribution CodeForces - 798D (贪心+思维)

    题目链接 TAG: 这是我近期做过最棒的一道贪心思维题,不容易想到,想到就出乎意料. 题意:给定两个含有N个正整数的数组a和b,让你输出一个数字k ,要求k不大于n/2+1,并且输出k个整数,范围为1 ...

  7. codeforces 798 D. Mike and distribution(贪心+思维)

    题目链接:http://codeforces.com/contest/798/problem/D 题意:给出两串长度为n的数组a,b,然后要求长度小于等于n/2+1的p数组是的以p为下表a1-ap的和 ...

  8. codeforces 798 C. Mike and gcd problem(贪心+思维+数论)

    题目链接:http://codeforces.com/contest/798/problem/C 题意:给出一串数字,问如果这串数字的gcd大于1,如果不是那么有这样的操作,删除ai, ai + 1 ...

  9. 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 ...

随机推荐

  1. luoguP3366 【模板】最小生成树 x

    P3366 [模板]最小生成树 2.4K通过 6.3K提交 题目提供者HansBug 标签 云端↑ 生成树 难度 普及- 时空限制 1s / 128MB 题目描述 如题,给出一个无向图,求出最小生成树 ...

  2. csps模拟73-74

    模拟73: T1:哔-------------------- sb模拟,然而一个小细节打炸了,不想解释(吐嘈大样例没有右移)... #include<iostream> #include& ...

  3. 一、docker安装CentOS7

    一.安装步骤 前提条件 Docker运行在CentOS7上,要求系统64位.系统内核版本为3.10以上. Docker是一个进程,一启动就两个进程,一个服务,一个守护进程.占用资源就非常少,启动速度非 ...

  4. Ubuntu start:未知任务:mysql

    在Ubuntu环境下,下载安装mysql但是到最后启动的时候却显示这一句话: start :未知任务:mysql 很纳闷,明明按照教程一步一步写的.后来才想起来,万能的方法,在前面加权限 sudo s ...

  5. Spring Cloud Eureka(七):DiscoveryClient 源码分析

    1.本节概要 上一节文章主要介绍了Eureka Client 的服务注册的流程,没有对服务治理进行介绍,本文目的就是从源码角度来学习服务实例的治理机制,主要包括以下内容: 服务注册(register) ...

  6. CF1217A

    CF1217A 题意: 配exp点经验给力量str和智力int,求有多少种分配情况使str比int高 解法: 打表找规律,没了. CODE; #include <bits/stdc++.h> ...

  7. 自定义镜像mycentos

    1.编写 1).Hub默认CentOS镜像是什么情况 2).编写Dockerfile文件 2.构建 3.运行

  8. PyTricks-Differebt ways to test multiple flags at once in

    x, y, z = 0, 1, 0 if x == 1 or y == 1 or z == 1: print('passed') if 1 in (x, y, z): print('passed') ...

  9. Linux设备驱动程序 之 工作队列

    工作队列可以把工作推后,交给一个内核线程去执行–这个下半部分总是会在进程上下文中执行:通过工作队列执行的代码占尽进程上下文的优势:最重要的是工作队列允许重新调度甚至睡眠: 在工作队列和软中断/task ...

  10. centos7 设置 防火墙 开机自启

    CentOS 7.0默认使用的是firewall作为防火墙,之前版本是使用iptables. 1.设置firewall开机启动 systemctl enable firewalld 2.禁止firew ...