题目链接

http://codeforces.com/contest/798/problem/D

题解

前几天的模拟赛,居然出这种智商题。。被打爆了QAQ

这个的话,考虑只有一个序列怎么做,把所有的排序取最大的当然可以,但是还有一种做法,就是两两分组之后每两个相邻的取大的!!

于是按照\(a\)排序,先取第一个,后面每两个相邻的取b较大的。做完了!

哇这怎么想出来的啊。。。。

代码

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std; const int N = 1e5;
int a[N+3],b[N+3],permu[N+3];
vector<int> ans;
int n; bool cmp(int x,int y) {return a[x]>a[y];} int main()
{
scanf("%d",&n);
for(int i=1; i<=n; i++) scanf("%d",&a[i]);
for(int i=1; i<=n; i++) scanf("%d",&b[i]);
for(int i=1; i<=n; i++) permu[i] = i;
sort(permu+1,permu+n+1,cmp);
ans.push_back(permu[1]);
for(int i=2; i<=n; i+=2)
{
ans.push_back(b[permu[i]]>b[permu[i+1]] ? permu[i] : permu[i+1]);
}
printf("%d\n",ans.size());
for(int i=0; i<ans.size(); i++) printf("%d ",ans[i]); puts("");
return 0;
}

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

    题目链接 题目大意 给定两个序列a,b,要求找到不多于个下标,使得对于a,b这些下标所对应数的2倍大于所有数之和. N<=100000,所有输入大于0,保证有解. 因为明确的暗示,所以一定找个. ...

  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. codeforces 816B Karen and Coffee (差分思想)

    题目链接 816B Karen and Coffee 题目分析 题意:有个人在学泡咖啡,因此看了很多关于泡咖啡温度的书,得到了n种推荐的泡咖啡温度范围[L1,R1] ,此人将有k种做法推荐的温度记为可 ...

  2. 使用vs工具查看dll依赖(也可查看pyc文件的依赖)

    vs工具中有个工具叫dumpin.exe,可以用来查看exe文件.dll文件.pyc文件依赖于哪些dll,从而针对性地去检查具体缺失哪些文件(目前是在装TensorFlow时查看具体需要哪个版本的cu ...

  3. python-day39(正式学习)

    目录 线程锁 死锁问题及递归锁 死锁 递归锁 信号量 GIL全局解释器锁 线程锁 from threading import Thread,Lock x=0 lock=Lock() def test( ...

  4. python线程中的同步问题

    多线程开发可能遇到的问题 假设两个线程t1和t2都要对num=0进行增1运算,t1和t2都各对num修改1000000次,num的最终的结果应该为2000000.但是由于是多线程访问,有可能出现下面情 ...

  5. Codeforces 1190B. Tokitsukaze, CSL and Stone Game

    传送门 不妨把每一堆按照石头数量从小到大排序 注意到每次只能拿一个石头,那么不论何时每堆石头的排名都是一样的 那么最终所有堆的状态一定就是 $0,1,2,...,n-1$,现在每一堆最终的石头数量都确 ...

  6. sql server case when

    case具有两种格式:简单Case函数和Case搜索函数 简单case函数 实例:CASE sex     when '1' then '男'     when '2' then'女'     els ...

  7. SQL学习(二)之四大查询语句以及标准写法

    SQL四大查询语句——增删改查 增-INSERT INSERT INTO 表 (字段列表) VALUES(值列表) INSERT INTO `user_table` (`ID`, `username` ...

  8. Git复习(十)之常见报错和疑问

    报错 情况一:git pull报错 There is no tracking information for the current branch. Please specify which bran ...

  9. JS基础_字面量和变量

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. Redis从入门到高可用,分布式实践

    redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted set ...