Scarily interesting! (URAL - 2021)

点击打开原题链接


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 of  n 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 integers  o  i and  r  i, 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 the  i-th challenge. In each team monsters are numbered with integers from 1 to  n in the order they appear in the input data. If the problem has several solutions, output any of them.
Example
input output
5
0 1 4 3 6
6 5 1 3 0
5 1
1 5
4 4
2 3
3 2


题意:两队进行比赛,怎样派人出场使得比赛最晚失去悬念。

思路:为了不尽早失去悬念,那么应该赢的那一队从小往大派人,输的那一队相反。这里其实是个贪心。

上代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
struct node{
 int val;
 int num;
};
node a[1001];
node b[1001];
int asum;
int bsum;
bool cmp1(node c,node d)
{
    return c.val < d.val;
}
bool cmp2(node c,node d)
{
    return c.val > d.val;
}
int main()
{
    int n;
    int p;
    scanf("%d" ,&n);
    asum = bsum = 0;
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    for(int i=0;i<n;i++)
    {
      scanf("%d",&p);
      a[i].val = p;
      a[i].num = i;
      asum += p;
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&p);
        b[i].val = p;
        b[i].num = i;
        bsum += p;
    }



    if(asum < bsum)
    {
      sort(a,a+n,cmp2);
      sort(b,b+n,cmp1);
      for(int i=0;i<n;i++)
      {
          printf("%d %d\n",a[i].num+1,b[i].num+1);
      }
     }
     else
     {
         sort(a,a+n,cmp1);
         sort(b,b+n,cmp2);
         for(int i=0;i<n;i++)
         {
             printf("%d %d\n",a[i].num+1,b[i].num+1);
         }
      }
    return 0;
}

水波。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值