链接
http://codeforces.com/problemset/problem/798/D
题解
这题啊,亦可赛艇。
做这道题要首先注意到两个事实:
一、所有数都是正数;
二、答案一定是恰好选择
⌊n2⌋+1
个。
因为如果存在一种选择小于
⌊n2⌋+1
的答案,那么我多选几组数字肯定依然合法。
因为有两个序列不好搞,先给第一个序列排个序。
当
n
为奇数时,如果我选择了第一组,那么后面的
对于
代码
//数学、贪心
#include <cstdio>
#include <algorithm>
#define maxn 100010
using namespace std;
int N, cho[maxn];
struct num{int a, b, id;}n[maxn];
bool operator<(const num &x, const num &y){return x.a>y.a;}
int main()
{
int i, j;
scanf("%d",&N);
for(i=1;i<=N;i++)scanf("%d",&n[i].a);
for(i=1;i<=N;i++)scanf("%d",&n[i].b);
for(i=1;i<=N;i++)n[i].id=i;
sort(n+1,n+N+1);
if(N&1)
{
cho[n[1].id]=1;
for(i=2;i<=N;i+=2)
{
if(n[i].b>n[i+1].b)cho[n[i].id]=1;
else cho[n[i+1].id]=1;
}
}
else
{
cho[n[1].id]=cho[n[2].id]=1;
for(i=3;i<=N;i+=2)
{
if(n[i].b>n[i+1].b)cho[n[i].id]=1;
else cho[n[i+1].id]=1;
}
}
printf("%d\n",N/2+1);
for(i=1;i<=N;i++)if(cho[i])printf("%d ",i);
return 0;
}