我感觉这道题挺神的~

假设 $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. 网络地址转换(NAT)

    NAT是解决ipv4地址短缺的方案之一 NAT是将位于子网中的主机与外网连通,子网中所有的主机都可以通过路由器的网络地址转换访问外网.对于外网来说该路由器相当于一台完整的主机,子网内所有主机对外网的访 ...

  2. 基于thymeleaf实现简单登录

    1.引入thymeleaf.静态资源等依赖 <dependency> <groupId>org.springframework.boot</groupId> < ...

  3. stdmap 用 at() 取值,如果 key 不存在,不好意思,程序崩溃。QMap 用 value()取值,如果 key 不存在,不会崩溃,你还可以指定默认值

    我觉得 Qt6 最应该升级的是容器类 stdmap 在遍历的时候,同时获取 key 与 value 非常方便: for(auto& var:map){    qDebug()<<v ...

  4. 通过 Kubeadm 安装 K8S 与高可用,版本1.13.4

    环境介绍: CentOS: 7.6 Docker: 18.06.1-ce Kubernetes: 1.13.4 Kuberadm: 1.13.4 Kuberlet: 1.13.4 Kuberctl: ...

  5. C#简单工厂案例

    using System; namespace Application { class JianDanGongChang { static void Main(string[] args) { Fac ...

  6. C# 用Redis实现的分布式锁

    Redis实现分布式锁(悲观锁/乐观锁) 对锁的概念和应用场景在此就不阐述了,网上搜索有很多解释,只是我搜索到的使用C#利用Redis的SetNX命令实现的锁虽然能用,但是都不太适合我需要的场景. 基 ...

  7. css中哪些属性会脱离文档流

    一共有三个属性会使元素脱离文档流: (1)浮动 (2)绝对定位 (3)固定定位 元素脱离文档流会导致父元素高度塌陷,要修复高度塌陷问题,可以将子元素与父元素放在同一个BFC中

  8. HTTP协议超级详解

    HTTP协议简介 超文本传输协议(英文:HyperText Transfer Protocol,缩写:HTTP)是一种用于分布式.协作式和超媒体信息系统的应用层协议.HTTP是万维网的数据通信的基础. ...

  9. Java 之 字符流

    一.字符流 当使用字节读取文本文件时,可能会有一个小问题,就是遇到中文字符时,可能不会显示完整的字符,那是因为一个中文字符可能占用多个字节存储.所以 Java 提供了一些字符类,以字符为单位读写数据, ...

  10. 如何避免Linux操作系统客户端登陆超时-linux命令之TMOUT=

    工作中经常遇到使用ssh,telnet工具登陆Linux操作系统时,出现的超时问题,怎么处理呢? 添加下面命令: TMOUNT=