input | output |
---|---|
5 0 1 4 3 6 6 5 1 3 0 | 5 1 1 5 4 4 2 3 3 2 |
题意:两个队进行比赛,每个队n个人,现在已知每个人会得多少分。每个人的得分不超过6。比赛进行n回合,每个回合一个队派一个人参赛,每个人只能参赛一次。一个队伍前i个回合的总得分为该队伍派出的前i个人的得分和。现在让你输出一个方案,让比赛尽量不失去悬念。假设第i回合比赛已经没有悬念,那么我们需要输出一个方案,让i尽量的大。
题解:首先判断两个队伍谁最终会获胜。对于最后会输的队伍,从最强的人派出来参赛,对于最后会赢的队伍,先派最弱的人参赛;因为题目让输出其中一种合理方案,因此赢的队从小到大排序,输的队从大到小排序一一输出编号就行。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <stack>
using namespace std;
typedef long long ll;
#define PI 3.1415926535897932
#define E 2.718281828459045
#define INF 0xffffffff//0x3f3f3f3f
#define mod 1000000007
const int MOD=1e9+7;
const int M=1005;
int n,m;
struct node
{
int id,val;
}a[10000],b[10000];
bool cmp(node xx,node yy)
{
return xx.val<yy.val;
}
bool cmp1(node xx,node yy)
{
return xx.val>yy.val;
}
int main()
{
int i;
while(scanf("%d",&n)!=EOF)
{
int sum1,sum2;
sum1=sum2=0;
for(i=1;i<=n;i++)
{
scanf("%d",&a[i].val);
sum1+=a[i].val;
a[i].id=i;
}
for(i=1;i<=n;i++)
{
scanf("%d",&b[i].val);
sum2+=b[i].val;
b[i].id=i;
}
if(sum1>sum2)
{
sort(a+1,a+n+1,cmp);
sort(b+1,b+n+1,cmp1);
for(i=1;i<=n;i++)
{
printf("%d %d\n",a[i].id,b[i].id);
}
}
else
{
sort(a+1,a+n+1,cmp1);
sort(b+1,b+n+1,cmp);
for(i=1;i<=n;i++)
{
printf("%d %d\n",a[i].id,b[i].id);
}
}
}
return 0;
}