我感觉这道题挺神的~

假设 $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. 机器学习-EM算法笔记

    EM算法也称期望最大化(Expectation-Maximum,简称EM)算法,它是一个基础算法,是很多机器学习领域算法的基础,比如隐式马尔科夫算法(HMM), LDA主题模型的变分推断,混合高斯模型 ...

  2. CH09 开机自动烧录QSPI

    版本信息: 版本 REV2018 时间 05/22/2018       XILINX ZYNQ LINUX篇 基于米联MZ7X系列                       电子版自学资料   常 ...

  3. 深夜扒一扒Android的发展史

    说道,Android的发展史,我们就不得不先来了解一下手机的发展史 Android之前的时代 1831年英国的法拉第发现了电磁感应现象,麦克斯韦进一步用数学公式阐述了法拉第等人的研究成果,并把电磁感应 ...

  4. PowerBuilder学习笔记之2PowerScript语言(三)

    教材地址:https://wenku.baidu.com/view/1e82d26925c52cc58ad6be05.html?sxts=1565679996440 2.6嵌入式SQL语句 2.6.1 ...

  5. GXOI/GZOI2019部分题解

    D1T1:与或和 对每位处理,问题变成所有内部不包含0/1的矩阵的个数,单调栈维护即可. #include<cstdio> #include<algorithm> #inclu ...

  6. redis主从中断异常处理

    线上预警主从中断: 查看线上复制信息: # Replication role:slave master_host:master_host master_port:6379 master_link_st ...

  7. linux环境,hidraw设备自动加载时默认权限的设置方法

    在linux系统中,hidraw设备会自动加载并设置默认权限,但系统的默认只允许root用户访问,普通用户是不允许读写. 设置的方法是修改udev的配置,配置路径是/etc/udev/rules.d/ ...

  8. html+css+javascript网页制作技巧总结1

    (一)div.元素居中中显示方法: 1.宽度要有实际值或百分比值 2.margin:0px auto; 文本内容居中显示的方法: 1.text-align:center; 2.line-height: ...

  9. Matplotlib pyplot中title() xlabel() ylabel()无法显示中文(即显示方框乱码)的解决办法

    有趣的事,Python永远不会缺席! 如需转发,请注明出处:小婷儿的python https://www.cnblogs.com/xxtalhr/p/11020246.html 一.无法正常显示原因 ...

  10. 修改Linux命令:ls为例

    Linux命令可以被修改,用于启动一些不起眼的程序. 操作方法如下: whereis ls cd /usr/bin mv ls ls_bak vim ls 新建的ls文件中 chmod +x ls c ...