Codeforces 798D Mike and distribution
题目大意
给定两个序列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的更多相关文章
- Codeforces 798D Mike and distribution(贪心或随机化)
题目链接 Mike and distribution 题目意思很简单,给出$a_{i}$和$b_{i}$,我们需要在这$n$个数中挑选最多$n/2+1$个,使得挑选出来的 $p_{1}$,$p_{2} ...
- 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 想法题,数学证明
题意:给你两个数列a,b,你要输出k个下标,使得这些下标对应的a的和大于整个a数列的和的1/2.同时这些下标对应的b //题解:首先将条件换一种说法,就是要取floor(n/2)+1个数使得这些数大于 ...
- Codeforces 798D - Mike and distribution(二维贪心、(玄学)随机排列)
题目链接:http://codeforces.com/problemset/problem/798/D 题目大意:从长度为n的序列A和序列B中分别选出k个下表相同的数要求,设这两个序列中k个数和分别为 ...
- Codeforces 798D Mike and distribution (构造)
题目链接 http://codeforces.com/contest/798/problem/D 题解 前几天的模拟赛,居然出这种智商题..被打爆了QAQ 这个的话,考虑只有一个序列怎么做,把所有的排 ...
- 【算法系列学习】codeforces D. Mike and distribution 二维贪心
http://codeforces.com/contest/798/problem/D http://blog.csdn.net/yasola/article/details/70477816 对于二 ...
- codeforces 798 D. 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,求选 ...
随机推荐
- macOS下appstore提示未能完成该操作的解决办法
macOS下App Store下载软件,提示:未能完成该操作.(com.apple.commerce.client 错误 500.) 解决办法: 在终端输入 defaults write com.ap ...
- Luogu4916 魔力环 莫比乌斯反演、组合、生成函数
传送门 先不考虑循环同构的限制,那么对于一个满足条件的序列,如果它的循环节长度为\(d\),那么与它同构的环在答案中就会贡献\(d\)次. 所以如果设\(f_i\)表示循环节长度恰好为\(i\)的满足 ...
- Python 学习 第十篇:正则表达式 - re
规则表达式(Regular Expression, RE),又称作正则表达式,通常用于检索.替换符合指定规则的文本,正则表达式定义的规则,称作模式(Pattern),即正则表达式的作用是从文本中查找到 ...
- SSH(poderosa)を使って、さくらのMySQLサーバーに接続する方法
SSH(poderosa)を使って.さくらのMySQLサーバーに接続する方法の覚書. 現在のさくらサーバーでは.新規ユーザーはTELNETが使えない.なので.データベースをコマンドラインで操作するには ...
- Python_每日习题_0005_三数排序
# 题目: # 输入三个整数x,y,z,请把这三个数由大到小输出. # 程序分析: 练练手就随便找个排序算法实现一下,偷懒就直接调用函数. #方法一:排序 raw = [] for i in rang ...
- Python学习第十篇——函数初步
def make_album(name,album_name,song_nums = 1): dict_album = {name:[album_name]} if int(song_nums) &g ...
- SDN 实验室学生们
SDN实验室系列:https://edu.cnblogs.com/campus/fzu/SdnLab --研究生及本科生们的博客及GitHub链接.欢迎各位大佬招募. 研究生 2018级 姓名 博客地 ...
- JDK8-新特性-附demo
import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Base64; impor ...
- ElasticSearch 分组查询的几个例子
facets接口可以根据query返回统计数据,其中的 terms_stats 是分组统计,根据key的情况返回value的统计数据,类似group by的意思. "terms_stats& ...
- static特别用法【静态导包】——Java包的静态导入
面试我问你static关键字有哪些作用,如果你答出static修饰变量.修饰方法我会认为你合格,答出静态块,我会认为你不错,答出静态内部类我会认为你很好,答出静态导包我会对你很满意,因为能看出你非常热 ...