CF789D Mike and distribution
一道人类智慧题。。。。
这道题目可以转化为在a,b中的选出一些位置,使得这些位置处的值加起来大于没有选的位置的值
我们按照a的权值排序,选择第一个元素,其与元素两两分组,每组选择b更大的那一个
很显然这样对于数组b是满足要求的,然后我们发现第i组的a权值肯定大于第i+1组的没有选的位置的权值,
在加上我们选择了第一个元素,所以a数组也是满足要求的
# include<iostream>
# include<cstdio>
# include<cmath>
# include<cstring>
# include<algorithm>
using namespace std;
const int mn = 1e5 + ;
int n,m,ans[mn],tot;
struct node{int a,b,pos;};
node da[mn];
bool cmp(node x,node y)
{
return x.a>y.a;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&da[i].a),da[i].pos=i;
for(int i=;i<=n;i++)
scanf("%d",&da[i].b);
sort(da+,da++n,cmp);
ans[++tot]=da[].pos;
for(int i=;i<=n;i+=)
{
if(i==n)
{
ans[++tot]=da[i].pos;
break;
}
if(da[i].b>da[i+].b) ans[++tot]=da[i].pos;
else ans[++tot]=da[i+].pos;
}
printf("%d\n",tot);
for(int i=;i<=tot;i++)
printf("%d ",ans[i]);
return ;
}
CF789D Mike and distribution的更多相关文章
- 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 ...
- Codeforces 798D Mike and distribution(贪心或随机化)
题目链接 Mike and distribution 题目意思很简单,给出$a_{i}$和$b_{i}$,我们需要在这$n$个数中挑选最多$n/2+1$个,使得挑选出来的 $p_{1}$,$p_{2} ...
- CF410div2 D. Mike and distribution
/* CF410div2 D. Mike and distribution http://codeforces.com/contest/798/problem/D 构造 题意:给出两个数列a,b,求选 ...
- CF798D Mike and distribution
CF798D Mike and distribution 洛谷评测传送门 题目描述 Mike has always been thinking about the harshness of socia ...
- Codeforces 798D Mike and distribution - 贪心
Mike has always been thinking about the harshness of social inequality. He's so obsessed with it tha ...
- 【算法系列学习】codeforces D. Mike and distribution 二维贪心
http://codeforces.com/contest/798/problem/D http://blog.csdn.net/yasola/article/details/70477816 对于二 ...
- Mike and distribution CodeForces - 798D (贪心+思维)
题目链接 TAG: 这是我近期做过最棒的一道贪心思维题,不容易想到,想到就出乎意料. 题意:给定两个含有N个正整数的数组a和b,让你输出一个数字k ,要求k不大于n/2+1,并且输出k个整数,范围为1 ...
随机推荐
- 工控安全入门(七)—— plc的网络
上一篇我们详细分析了bootram和Vxworks的基本启动流程,这篇文章中我们把视线转到plc的网络部分,同时来复现我们第一个.第二个工控安全漏洞. VxWorks的网络设备驱动 一般我们说有三种设 ...
- 机器学习二 逻辑回归作业、逻辑回归(Logistic Regression)
机器学习二 逻辑回归作业 作业在这,http://speech.ee.ntu.edu.tw/~tlkagk/courses/ML_2016/Lecture/hw2.pdf 是区分spam的. 57 ...
- Eureka自我保护机制、健康检查的作用、actuator模块监控
在上一篇文章微服务入门之服务的注册以及服务之间的调用中,我们基本实现了服务之间的调用,今天我们来了解一下Eureka自我保护机制以及健康检查. Eureka自我保护机制 接着以上篇文章建立的三个工程为 ...
- Codeforces 467D
题目链接 D. Fedor and Essay time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Linux 下用Win共享
让win能访问到 linux 的smb 共享: linux 安装 samba: apt-get install samba #然后 vim /etc/samba/smb.conf #找到securit ...
- 这些Excel学会了,你做账的效率将大大提高
这些Excel学会了,你做账的效率将大大提高 这些功能学会了,工作效率将大大提高. 1.excel的快速访问工具栏: 我的快速访问工具栏由左到右主要是"保存"."新建&q ...
- java-异常处理2
一 编译时异常和运行时异常的区别 java认为如果你的程序有问题,你应该让调用者知道. 例如:面包,长毛了.用户去买了,用户可能会挂 .应该在面包上贴上标签(异常). java 如果在函数内抛出Exc ...
- composer本地安装文档 - CSDN博客
1.下载下图2个文件 2.将上图2个文件放到php根目录下与php.exe再同一目录 3.在composer.bat写 4.配置环境变量(将php目录复制到环境变量里) 5.将php.ini配置文件的 ...
- LUOGU P2587 [ZJOI2008]泡泡堂
传送门 解题思路 刚开始先写了个田忌赛马的贪心,就是要是打不过就拿最弱的送死,30分...后来瞄了眼题解,发现这样是错的,比如说这样的数据 : 3 3 2 3 1 如果用田忌赛马的话,让2-3 3-1 ...
- Faster RCNN算法训练代码解析(3)
四个层的forward函数分析: RoIDataLayer:读数据,随机打乱等 AnchorTargetLayer:输出所有anchors(这里分析这个) ProposalLayer:用产生的anch ...