URAL 2021 Scarily interesting!(贪心)

来源:互联网 发布:淘宝卫浴安装 编辑:程序博客网 时间:2024/04/29 22:05

题目链接

2021. Scarily interesting!

Time limit: 1.0 second
Memory limit: 64 MB
This year at Monsters University it is decided to arrange Scare Games. At the Games all campus gathers at the stadium stands, and the Scare program students divide into two teams to compete in their abilities of scaring children. This year the two teams will be “Oozma Kappa” and “Roar Omega Roar”.
Each team has n monsters, and the Games consist ofn challenges. During each challenge Dean Hardscrabble, the chair of the Scare program, invites one monster from each team to demonstrate his mastery. Each of the monsters is invited only once and scores from 0 to 6 points, depending on how much a child is scared. The results of each challenge are announced at the same time for both monsters right after the end of this challenge. The winning team will be identified by the sum of the points scored by all its members.
Sports competition is an unpredictable process. But the Dean wants to keep all the course of the Games under control, so that the identity of the winning team will have been unclear for the audience as long as possible. For example, if six challenges until the end “Oozma Kappa” is forty points ahead, the audience at the stadium stands will just lose interest to the game. The Dean knows the skill level of all her students, and she wants to decide beforehand the order in which both teams’ members will be participating in the challenges. In what order should monsters from “Oozma Kappa” and from “Roar Omega Roar” show up to keep the audience in suspense as long as possible?

Input

The first line contains an integer n (2 ≤n ≤ 1 000). The second line contains n integers within the range from 0 to 6, which are the points monsters from “Oozma Kappa” will score. The third line contains the points, monsters from “Roar Omega Roar” will score, written in the same manner.

Output

Output n lines, each containing integersoi and ri, which are the numbers of monsters from “Oozma Kappa” and “Roar Omega Roar” respectively, who should be called by the Dean to take part in thei-th challenge. In each team monsters are numbered with integers from 1 ton in the order they appear in the input data. If the problem has several solutions, output any of them.

Sample

inputoutput
50 1 4 3 66 5 1 3 0
5 11 54 42 33 2

题意:两个队进行比赛,每个队n个人,现在已知每个人会得多少分。每个人的得分不超过6。比赛进行n回合,每个回合一个队派一个人参赛,每个人只能参赛一次。一个队伍前i个回合的总得分为该队伍派出的前i个人的得分和。现在让你输出一个方案,让比赛尽量不失去悬念。假设第i回合比赛已经没有悬念,那么我们需要输出一个方案,让i尽量的大。

题解:首先判断两个队伍谁最终会获胜。对于最后会输的队伍,从最强的人派出来参赛,对于最后会赢的队伍,先派最弱的人参赛,这样让比赛上演逆转,悬念一定能保持得最久。代码如下:

#include<cstdio>#include<cstring>#include<string>#include<algorithm>#define nn 1100using namespace std;int n;struct node{    int id,val;}a[nn],b[nn];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 suma,sumb;        suma=sumb=0;        for(i=1;i<=n;i++)        {            scanf("%d",&a[i].val);            suma+=a[i].val;            a[i].id=i;        }        for(i=1;i<=n;i++)        {            scanf("%d",&b[i].val);            sumb+=b[i].val;            b[i].id=i;        }        if(suma>sumb)        {            sort(a+1,a+n+1,cmp);            sort(b+1,b+n+1,cmp1);            int ix,fc;            ix=fc=0;            for(i=1;i<=n;i++)            {                printf("%d %d\n",a[i].id,b[i].id);                ix+=a[i].val;                fc+=b[i].val;               // if(ix-fc>(n-i)*6)                   // break;            }        }        else        {            sort(a+1,a+n+1,cmp1);            sort(b+1,b+n+1,cmp);            int ix,fc;            ix=fc=0;            for(i=1;i<=n;i++)            {                printf("%d %d\n",a[i].id,b[i].id);                ix+=a[i].val,fc+=b[i].val;               // if(fc-ix>(n-i)*6)                   // break;            }        }    }    return 0;}


0 0
原创粉丝点击