我感觉这道题挺神的~

假设 $a[i]=b[i]$,那么我们可以将 $a$ 降序排序,然后你发现只要你按照 $1,3,5......n$ 这么取一定是合法的.

而我们发现 $2$ 比取 $3$ 优,取 $4$ 还比取 $5$ 优.

所以,我们可以这样:

强制性取第一个元素,然后其余 $\frac{n}{2}$ 个元素每相邻两个依次考虑,不论拿哪个都是合法的.

这样做有什么好处呢?由于 $a$ 可以这样随便拿,于是每一次就取更大的 $b$ 就好了.

所以,我们按照 $a$ 从大到小排一个序,然后依次贪心选取 $b$ 即可.

code:

#include <bits/stdc++.h>
#define N 100020
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
struct node
{
int x,y,num;
}a[N];
int n,cnt,ans[N];
int cmp(node x,node y)
{
return x.x==y.x?x.y>y.y:x.x>y.x;
}
int main()
{
// setIO("input");
int i,j;
scanf("%d",&n);
for(i=1;i<=n;++i) scanf("%d",&a[i].x);
for(i=1;i<=n;++i) scanf("%d",&a[i].y);
for(i=1;i<=n;++i) a[i].num=i;
sort(a+1,a+1+n,cmp), ans[++cnt]=a[1].num;
for(i=2;i<=n;i+=2)
{
if(a[i].y>a[i+1].y) ans[++cnt]=a[i].num;
else ans[++cnt]=a[i+1].num;
}
printf("%d\n",cnt);
for(i=1;i<=cnt;++i) printf("%d ",ans[i]);
return 0;
}

  

CF798D Mike and distribution 贪心的更多相关文章

  1. CF798D Mike and distribution

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

  2. [CF798D]Mike and distribution_贪心

    Mike and distribution 题目链接:http://codeforces.com/problemset/problem/798/D 数据范围:略. 题解: 太难了吧这个题..... 这 ...

  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 798 D. Mike and distribution

    D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  6. #410div2D. Mike and distribution

    D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  7. D. Mike and distribution 首先学习了一个玄学的东西

    http://codeforces.com/contest/798/problem/D D. Mike and distribution time limit per test 2 seconds m ...

  8. CF410div2 D. Mike and distribution

    /* CF410div2 D. Mike and distribution http://codeforces.com/contest/798/problem/D 构造 题意:给出两个数列a,b,求选 ...

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

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

随机推荐

  1. ALV报表——选择屏幕变量赋值

    ABAP选择屏幕变量赋值 运行效果: 代码: *&---------------------------------------------------------------------* ...

  2. Arm-Linux 移植 mtd-utils 1.x

    有关文章:<mtd-utils 的 使用> 背景: 关于在公司的生产环境有关.不希望每次都在uboot下面做nand flash 的烧写:也觉得使用U盘升级的方法比较慢,而且有关的驱动不是 ...

  3. Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) (1208F,1208G,1208H)

    1208 F 大意:  给定序列$a$, 求$\text{$a_i$|$a_j$&$a_k$}(i<j<k)$的最大值 枚举$i$, 从高位到低位贪心, 那么问题就转化为给定$x$ ...

  4. Java8新特性 - 新时间和日期 API

    本地时间和时间戳 主要方法: now:静态方法,根据当前时间创建对象 of:静态方法,根据指定日期/时间创建对象 plusDays,plusWeeks,plusMonths,plusYears:向当前 ...

  5. VC 中的ATL ActiveX 和 MFC ActiveX 有什么区别

    原文转自 https://www.cnblogs.com/zhwl/archive/2012/11/29/2794509.html ATL是ActiveXTemplateLibrary的缩写,它是一套 ...

  6. Machine Learning Technologies(10月20日)

    Linear regression SVM(support vector machines) Advantages: ·Effective in high dimensional spaces. ·S ...

  7. 探究Java如何实现原子操作(atomic operation)

    1. 让我们首先了解下java 中 Volatile 关键字 Volatile可实现java内存模型当中的可见性, java内存模型的可见性: 可见性,是指线程之间的可见性,一个线程修改的状态对另一个 ...

  8. 六、select查询基础篇

    前言: DQL(Data QueryLanguage):数据查询语言,通俗点讲就是从数据库获取数据的,按照DQL的语法给数据库发送一条指令,数据库将按需求返回数据. 一.基本语法 select 查询的 ...

  9. VMware网络配置三种网络模式(桥接、NAT、Host-only)

    VMware网络配置三种网络模式(桥接.NAT.Host-only) 一.虚拟安装后三种网络模式显示 当安装好后,的“虚拟网络编辑器”中也存在三种模式,分别对应:桥接-VMnet0.Host-only ...

  10. javascript之ECMAScript:语法的操作标准

    一.如何书写一个javascript代码 javascript代码需要写在javascript标签中才会生效,而javascript标签可以写在任何地方,但考虑到规范化及页面的加载问题,最好是写在bo ...