题目连接

一道人类智慧题。。。。

这道题目可以转化为在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的更多相关文章

  1. codeforces 798 D. Mike and distribution

    D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  2. #410div2D. Mike and distribution

    D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  3. D. Mike and distribution 首先学习了一个玄学的东西

    http://codeforces.com/contest/798/problem/D D. Mike and distribution time limit per test 2 seconds m ...

  4. Codeforces 798D Mike and distribution(贪心或随机化)

    题目链接 Mike and distribution 题目意思很简单,给出$a_{i}$和$b_{i}$,我们需要在这$n$个数中挑选最多$n/2+1$个,使得挑选出来的 $p_{1}$,$p_{2} ...

  5. CF410div2 D. Mike and distribution

    /* CF410div2 D. Mike and distribution http://codeforces.com/contest/798/problem/D 构造 题意:给出两个数列a,b,求选 ...

  6. CF798D Mike and distribution

    CF798D Mike and distribution 洛谷评测传送门 题目描述 Mike has always been thinking about the harshness of socia ...

  7. Codeforces 798D Mike and distribution - 贪心

    Mike has always been thinking about the harshness of social inequality. He's so obsessed with it tha ...

  8. 【算法系列学习】codeforces D. Mike and distribution 二维贪心

    http://codeforces.com/contest/798/problem/D http://blog.csdn.net/yasola/article/details/70477816 对于二 ...

  9. Mike and distribution CodeForces - 798D (贪心+思维)

    题目链接 TAG: 这是我近期做过最棒的一道贪心思维题,不容易想到,想到就出乎意料. 题意:给定两个含有N个正整数的数组a和b,让你输出一个数字k ,要求k不大于n/2+1,并且输出k个整数,范围为1 ...

随机推荐

  1. ArcGIS 10.2 for Server 集群部署

    ArcGIS 10.2 for Server 具有很灵活的体系结构,而 ArcGIS 10.2  forServer site 可以包含一台或多台安装 GIS Server 的机器,这些参与ArcGI ...

  2. 【Redis缓存机制】1.Redis介绍和使用场景

    (1)持久化数据库的缺点平常我们使用的关系型数据库有Mysql.Oracle以及SqlServer等,在开发的过程中,数据通常都是通过Web提供的数据库驱动来链接数据库进行增删改查. 那么,我们日常使 ...

  3. Java的一些小知识

    Switch和If的区别: Switch case成功后将不再向下继续执行,而If却要每个条件判断一遍.过于浪费: Java中的多态: 方法重载: 通常是指在同一个类中,相同的方法名对应着不同的方法实 ...

  4. WPF 线程中异常导致程序崩溃

    一般我们WPF中都加全局捕获,避免出现异常导致崩溃. Application.Current.DispatcherUnhandledException += Current_DispatcherUnh ...

  5. storm的安装

    一. 安装storm要先本机搭建好zookeeper集群(手动目录安装或者CDH安装) 二. Java 6 Python 2.6.6 unzip(针对使用语言要安装好相应环境 比如java 要JDK和 ...

  6. mybatis学习:mybatis注解开发一对多

    实体类User: public class User implements Serializable { private Integer id; private String username; pr ...

  7. TZOJ 3042 切蛋糕(并查集)

    描述 KK是个心灵手巧的好姑娘,她做了一个大蛋糕请她的好朋友们来品尝.这个蛋糕分成n×n个正方形小格,每个小格包含一块水果.KK要把蛋糕切成若干块,显然她不会破坏任意一个小格.无聊的某同学在她切蛋糕时 ...

  8. BZOJ3339&&3585 Rmq Problem&&mex

    BZOJ3339&&3585:Rmq Problem&&mex Description 有一个长度为n的数组{a1,a2,...,an}.m次询问,每次询问一个区间内最 ...

  9. TZ_05_Spring_annotation常见注解

    Spring常用的注解大全和解释 注解 解释 @Controller 组合注解(组合了@Component注解),应用在MVC层(控制层),DispatcherServlet会自动扫描注解了此注解的类 ...

  10. JS random函数深入理解(转载)

    转载自:(本文对读者有帮助的话请移步支持原作者) http://www.cnblogs.com/starof/p/4988516.html 一.预备知识 Math.ceil();  //向上取整. M ...