题目链接

题目大意

给定两个序列a,b,要求找到不多于个下标,使得对于a,b这些下标所对应数的2倍大于所有数之和。

N<=100000,所有输入大于0,保证有解。

因为明确的暗示,所以一定找个。

考虑去掉取整符号,分奇偶讨论。

1 n为奇数

将a从大到小排序,首先取最大的,接着每两个数取其中b较大的。

2 n为偶数

将a从大到小排序,首先取最大的和另一个(都可以),接着每两个数取其中b较大的。

 #include<algorithm>
#include<iostream>
#include<cstdio>
using namespace std;
const int N=;
int n;
struct node
{
int a,b,pos;
}t[N];
bool cmp(node c,node d)
{
return c.a>d.a;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&t[i].a);
for(int i=;i<=n;i++)
scanf("%d",&t[i].b);
for(int i=;i<=n;i++)
t[i].pos=i;
sort(t+,t+n+,cmp);
printf("%d\n",n/+);
printf("%d ",t[].pos);
if(n%==)
{
printf("%d ",t[n].pos);
n--;
}
for(int i=;i<=n;i+=)
if(t[i].b>t[i+].b)
printf("%d ",t[i].pos);
else
printf("%d ",t[i+].pos);
printf("\n");
return ;
}

Codeforces 798D Mike and distribution的更多相关文章

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

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

  2. Codeforces 798D Mike and distribution - 贪心

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

  3. CodeForces - 798D Mike and distribution 想法题,数学证明

    题意:给你两个数列a,b,你要输出k个下标,使得这些下标对应的a的和大于整个a数列的和的1/2.同时这些下标对应的b //题解:首先将条件换一种说法,就是要取floor(n/2)+1个数使得这些数大于 ...

  4. Codeforces 798D - Mike and distribution(二维贪心、(玄学)随机排列)

    题目链接:http://codeforces.com/problemset/problem/798/D 题目大意:从长度为n的序列A和序列B中分别选出k个下表相同的数要求,设这两个序列中k个数和分别为 ...

  5. Codeforces 798D Mike and distribution (构造)

    题目链接 http://codeforces.com/contest/798/problem/D 题解 前几天的模拟赛,居然出这种智商题..被打爆了QAQ 这个的话,考虑只有一个序列怎么做,把所有的排 ...

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

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

  7. codeforces 798 D. Mike and distribution

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

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

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

  9. CF410div2 D. Mike and distribution

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

随机推荐

  1. java eclipse jdk 关系

    java 经常用到多个jdk版本 1.7   1.8.... 兼容时几个位置 处理 eclipse.ini (A处) #-vm#C:\Program Files\Java\jdk1.7.0_79\bi ...

  2. FineUIMvc v4.0.0 发布了,MVC控件库基础版免费!

    FineUI(MVC版)v4.0.0 已经于 2017-10-24 发布! 这个版本将引入了激动人心的 CSS3 动画,只需要开启全局属性 EnableAnimation 即可,先睹为快: 1. 菜单 ...

  3. 深入理解Redis复制

    复制 A few things to understand ASAP about Redis replication. 1) Redis replication is asynchronous, bu ...

  4. logstash grok内置规则

    logstash grok 内置正则 https://github.com/elastic/logstash/blob/v1.4.2/patterns/grok-patterns USERNAME [ ...

  5. shell 小工具

    1.打印进度条(待完善) #!/bin/sh printf -- 'Performing asynchronous action..'; DONE=; printf -- '............. ...

  6. Random()种子数

    Random rand =new Random(25); int i; i=rand.nextInt(100); 初始化时25并没有起直接作用,rand.nextInt(100);中的100是随机数的 ...

  7. 我们为什么要使用List和Set(List,Set详解)

    1.集合概述 类图 集合和数组的区别? 集合基本方法 集合特有的遍历方式? public static void main(String[] args) { //创建集合对象 Collection c ...

  8. Zabbix appliance manual

    https://www.zabbix.com/documentation/4.0/manual/appliance If the appliance fails to start up in Hype ...

  9. React Native之图片保存到本地相册(ios android)

    React Native之图片保存到本地相册(ios android) 一,需求分析 1,react native保存网络图片到相册,iOS端可以用RN自带的CameraRoll完美解决,但是andr ...

  10. 13 Connectors: show contrast/oppistion

    1 "but" 和 "yet" 用来显示两个意思之间的对比关系.在写作中,当 "but" 和"yet" 将两个分句连为一 ...