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 ...
随机推荐
- Ceisum官方教程1 -- 开始
原文地址:https://cesium.com/docs/tutorials/getting-started/ 学会使用全球地形.影像.3d tile(模型切片).地理编码创建一个Cesium程序. ...
- JS的闭包问题
1.什么是“闭包” 是一个拥有许多变量和绑定了这些变量的环境的表达式(通常是一个函数),因而这些变量也是该表达式的一部分. 2.闭包的应用场景 (1)保护变量的安全实现JS私有属性和私有方法 (2)在 ...
- LINUX对超级用户和普通用户的理解
什么是超级用户 在所有Linux系统中,系统都是通过UID来区分用户权限级别的,而UID为0的用户被系统约定为是具有超级权限.超级用户具有在系统约定的最高权限满园内操作,所以说超级用户可以完成系统管理 ...
- 【Java爬虫】爬取南通大学教务处成绩
没使用自动登录,所以获取是比较麻烦.. 1.http://jwgl.ntu.edu.cn/cjcx 进入官网,进行账号密码登录 2.点击全部成绩查询(也一定要点进去,不然cookie不会返回值) ...
- Leetcode458.Poor Pigs可怜的小猪
有1000只水桶,其中有且只有一桶装的含有毒药,其余装的都是水.它们从外观看起来都一样.如果小猪喝了毒药,它会在15分钟内死去. 问题来了,如果需要你在一小时内,弄清楚哪只水桶含有毒药,你最少需要多少 ...
- Redis源码解析:25集群(一)握手、心跳消息以及下线检测
Redis集群是Redis提供的分布式数据库方案,通过分片来进行数据共享,并提供复制和故障转移功能. 一:初始化 1:数据结构 在源码中,通过server.cluster记录整个集群当前的状态,比如集 ...
- Spring MVC中获取当前项目的路径
Spring MVC中获取当前项目的路径 在web.xml中加入以下内容 <!--获取项目路径--> <context-param> <param-name>web ...
- js &&操作符解析
转载自:http://www.cnblogs.com/huchaoheng/p/4066473.html 前几天看到一个函数,百思不得其解,今天早上醒来看了本js的书,正好讲到操作符的用法,给大家分享 ...
- 移植thinkPHP的dump()函数
由于公司的开发机没有开xdebug拓展,导致var_dump()在浏览器上看很不方便. 因此,加入从thinkphp搬过来的dump()函数. function dump($var, $echo=tr ...
- 使用Charles在iOS6上进行抓包
抓取Web页面的网络请求很容易,Chrome和Firefox都很容易做到.iOS APP如何抓包呢?其实也很容易,我比较喜欢使用 Charles. 我用的是Mac电脑,首先建立一个热点,然后让iOS设 ...