CF798D Mike and distribution 贪心
我感觉这道题挺神的~
假设 $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 贪心的更多相关文章
- CF798D Mike and distribution
CF798D Mike and distribution 洛谷评测传送门 题目描述 Mike has always been thinking about the harshness of socia ...
- [CF798D]Mike and distribution_贪心
Mike and distribution 题目链接:http://codeforces.com/problemset/problem/798/D 数据范围:略. 题解: 太难了吧这个题..... 这 ...
- Codeforces 798D Mike and distribution - 贪心
Mike has always been thinking about the harshness of social inequality. He's so obsessed with it tha ...
- Codeforces 798D Mike and distribution(贪心或随机化)
题目链接 Mike and distribution 题目意思很简单,给出$a_{i}$和$b_{i}$,我们需要在这$n$个数中挑选最多$n/2+1$个,使得挑选出来的 $p_{1}$,$p_{2} ...
- codeforces 798 D. Mike and distribution
D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- #410div2D. Mike and distribution
D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- D. Mike and distribution 首先学习了一个玄学的东西
http://codeforces.com/contest/798/problem/D D. Mike and distribution time limit per test 2 seconds m ...
- CF410div2 D. Mike and distribution
/* CF410div2 D. Mike and distribution http://codeforces.com/contest/798/problem/D 构造 题意:给出两个数列a,b,求选 ...
- 【算法系列学习】codeforces D. Mike and distribution 二维贪心
http://codeforces.com/contest/798/problem/D http://blog.csdn.net/yasola/article/details/70477816 对于二 ...
随机推荐
- Python--递归函数实现:多维嵌套字典数据无限遍历
原创:多层嵌套字典无限遍历,实现当value值以特殊字符$开头,并且等于某项值时,用随机函数替换该参数 """处理前的字典{'patient': {'avatarPic' ...
- matplotlib笔记3
关于matplotlib的绘制图形的基本代码,我们可以参照下面的连接 https://matplotlib.org/gallery/index.html https://matplotlib.org/ ...
- vue项目过程的理解: main.js文件理解 router.js文件理解 以及组件 路由 等之间的关系
https://blog.csdn.net/qq_26229005/article/details/85040393 内容太多了,有空再整理
- Scratch 少儿编程之旅(四)— Scratch入门动画《小猫捉蝴蝶》(中)
本期内容概括: 了解Scratch的更多操作,用[无限循环]来更改“小猫”角色的代码: 添加[碰到边缘就反弹]积木块指令: 更改角色的旋转模式和造型,让”小猫”走路更生动: 两种[循环]语句的区别: ...
- Vector、ArrayList异同和HTTP请求异同的概括和区别
今天我所记录的是两个异同的概括: HTTP: 同步请求:提交请求->等待服务器处理->处理完毕返回给客户端 这个期间客户端浏览器只能处于等待状态,得到回应才可以执行下一步操作. 异步请求 ...
- windows Git Bash 无法运行python文件的解决方法(转)
https://blog.csdn.net/xie_0723/article/details/51958243
- NodeJS入门--环境搭建 IntelliJ IDEA
NodeJS入门–环境搭建 IntelliJ IDEA 本人也刚开始学习NodeJS,所以以此做个笔记,欢迎大家提出意见. 1.首先 下载安装NodeJS,下载安装IntelliJ IDEA 2.接下 ...
- springboot项目实用代码整理
// 判断JSONOBJECT是否为空 CommonUtils.checkJSONObjectIsEmpty(storeInfo) // 判断字符串是否为空," "也为空 Stri ...
- js按钮频繁提交解决方案:
1.封装js: /// 函数节流 xhz.canRun = true; xhz.Throttling = function () { if (!xhz.canRun) { layer.msg('处理中 ...
- 字节数组(byte[])与16进制字符串转换
/// <summary> /// 转换扩展类 /// </summary> public static class ConvertExtend { /// <summa ...