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. 1-7HSB色彩模式

    http://www.missyuan.com/thread-350721-1-1.html HSB色彩模式色相hue.饱和度saturation.明度brightness 在HSB模式中,S和B的取 ...

  2. 菜单栏伸缩(附jquery-1.12.1.js)

    Css: <style type="text/css"> .leftMenu { min-width:220px; width:268px; margin:40px a ...

  3. this关键字的用法小结

    1.this :指它所在函数所属对象的引用. 简单说:哪个对象调用this所在的函数,this就指哪个对象. 主要是为了区分:成员变量和局部变量 2.构造函数之间的调用用this关键字,如,this( ...

  4. 5 款最酷的 Linux 终端模拟器

    转载:https://cloud.tencent.com/developer/article/1040344 首先我要推荐的第一个终端是 Xiki. Xiki 是 Craig Muth 的智慧结晶,他 ...

  5. 解决IntelliJ无法导入maven包的问题

    使用如下的pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns=&quo ...

  6. Apache Flink - 分布式运行环境

    1.任务和操作链 下面的数据流图有5个子任务执行,因此有五个并行线程. 2.Job Managers, Task Managers, Clients Job Managers:协调分布式运行,他们安排 ...

  7. docker 命令 记录

    获取指定容器的ip docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_nam ...

  8. nginx - nginx下配置thinkphp5

    首先tp5的访问目录指向到webroot/public文件夹中.thinkphp的url访问:http://serverName/index.php(或者其它应用入口文件)/模块/控制器/操作/[参数 ...

  9. 调用subprocess 使用logging打印日志

    #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Henry 17607168727@163.com import sys import lo ...

  10. 执行git pull时提示Connection reset by 13.229.188.59 port 22

    问题如下图: 解决办法: 1. 2. 3. 4. 5. 6.