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. Java_hutool 发起请求

    //执行接口 String realUrl = "http://localhost:8091/SzeportCodeService/MSGService/encryptAES"; ...

  2. 019-020_STM32程序移植之_W5500连接noenet

    (一)本次实验是将数据通过W5500模块传输到onenet平台上面去 (二)显示内容,onenet平台数据变化曲线 (三)相关网站: 1.onenet网站:https://open.iot.10086 ...

  3. 快速了解AMD、CMD、CommonJS、ESM

    1.ES6 Module javascript在ES2015(ES6)中出现了语言层面的模块(module). ES6的模块既可以用于浏览器端,也可以用于服务器端(nodeJS). ES6模块是静态化 ...

  4. cc.Sprite组件

    1.精灵 精灵(Sprite)是Cocos系列的核心概念之一,是Cocos Creator最常用的显示图像的组件. 游戏中显示一个图片,我们就可以把这个叫做"精灵" sprite, ...

  5. Python互联网金融之用户增长的数据逻辑

    怎样看待和应用我们互联网金融中的数据? 怎样进行数据分析? 互联网金融数据分析的三个层面: (1)指标层面 建立指标体系,观察指标涨跌的情况 (2)行业框架 不同的行业对于各个指标的权重不同 复投率 ...

  6. QMessageBox改变大小

    创建一个QMessageBox: QMessageBox msgBox(this);msgBox.setWindowTitle(tr("MailBox Location"));ms ...

  7. django 2.2和mysql使用的常见问题

    可能是由于Django使用的MySQLdb库对Python3不支持,我们用采用了PyMySQL库来代替,导致出现各种坑,特别是执行以下2条命令的是时候: python manage.py makemi ...

  8. <iframe>和<frame>标签属性详解

    iframe>元素会创建包含另外一个文档的内联框架(即行内框架): 一.align 属性(不赞成) align属性规定iframe相对于周围元素的水平和垂直对齐方式,因为iframe元素是行内元 ...

  9. [Bayes] Maximum Likelihood estimates for text classification

    Naïve Bayes Classifier. We will use, specifically, the Bernoulli-Dirichlet model for text classifica ...

  10. python抽取指定url页面的title方法

    python抽取指定url页面的title方法 今天简单使用了一下python的re模块和lxml模块,分别利用的它们提供的正则表达式和xpath来解析页面源码从中提取所需的title,xpath在完 ...