题意:

给定 $n$ 个物品,每个物品有两个属性$a_i$, $b_i$,求一个长度为$[\frac{n}{2}]+1$的子序列 $p$ 使得

$2 * \sum_{i = 1}^{|p|}{a_{p_i}} > \sum_{i=1}^n {a_i}$

$2 * \sum_{i = 1}^{|p|}{b_{p_i}} > \sum_{i=1}^n {b_i}$

解法:

非常巧妙的构造方法。

注意到题目的要求可以转化为非 $p_i$ 的集合的元素之和小于 $p_i$内元素之和。

考虑一种构造方法:

  首先按照$a_i$大小将物品从大到小进行排序。

  首先选上第一个物品,接下来对于后面的物品分成 $[\frac{n-1}{2}]$ 个两对物品来看,

    对于每一对物品选取$b_i$较大的物品加入$p$集合。

  如果余下了一个物品,则加入$p$集合。

正确性:

  首先对于$b$,显然有原题要求条件成立。

  对于$a$,可以发现 $a_1$ 大于后面所有 $a_{i+1} - a_i$ 的和,这样,也成立。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> #define N 100010 using namespace std; int n;
int a[N], p[N], b[N], c[N]; bool cmp(int x, int y)
{
return a[x] > a[y];
} int main()
{
scanf("%d", &n);
for(int i = ;i <= n;i++) scanf("%d", &a[i]);
for(int i = ;i <= n;i++) scanf("%d", &b[i]);
for(int i = ;i <= n;i++) c[i] = i;
sort(c + , c + n + , cmp);
int tot = ;
p[tot = ] = c[];
for(int i = ;i <= n;i += )
{
if(i<n && b[ c[i] ] < b[ c[i+] ]) p[++tot] = c[i+];
else p[++tot] = c[i];
}
sort(p + , p + tot + );
cout << tot << endl;
for(int i = ;i <= tot;i++) cout << p[i] << ' ';
cout << endl;
return ;
}

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 ...

  10. Codeforces 798D Mike and distribution

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

随机推荐

  1. 最简单的基于FFmpeg的移动端样例附件:SDL Android HelloWorld

    ===================================================== 最简单的基于FFmpeg的移动端样例系列文章列表: 最简单的基于FFmpeg的移动端样例:A ...

  2. ListView的异步载入(笔记,多线程和AsyncTask)

    异步载入最经常使用的两种方式: 多线程,线程池     AsyncTask 实例操作: 从一个站点上获取Json数据.然后将数据在ListView上显示. 1.创建item_layout布局 , 改动 ...

  3. Erlang function guards NOTE

    Note: I've compared , and ; in guards to the operators andalso and orelse. They're not exactly the s ...

  4. bootstrap-table 行内编辑

    1.文件引入 <link rel="stylesheet" href="bootstrap.css"> <link rel="sty ...

  5. Apache JServ Protocol

    ajp_百度百科 https://baike.baidu.com/item/ajp/1187933 AJP(Apache JServ Protocol)是定向包协议.因为性能原因,使用二进制格式来传输 ...

  6. Java Message Service

    en.wikipedia.org/wiki/Java_Message_Service Messaging is a form of loosely coupled distributed commun ...

  7. C++正则表达式笔记之wregex

    遍历所有匹配 #include <iostream> #include <regex> using namespace std; int main() { wstring ws ...

  8. 完美的jquery事件绑定方法on()

    在讲on()方法之前,我们先讲讲在on()方法出现前的那些事件绑定方法: .live() jQuery 1.3新增的live()方法,使用方法例如以下: $("#info_table td& ...

  9. Mac下eclipse的快捷键

    一.Command类 Command+1 快速修复 Command+d 删除当前行 Command+Option+↓ 复制当前行到下一行 Command+Option+↑ 复制当前行到上一行 Comm ...

  10. H264 各种profile

    关键字:H264 ,base profile, main profile, extend profile, high profile. 提到High Profile H.264解码许多人并不了解,那么 ...