It’s Time for a Montage

问题 I: It’s Time for a Montage

时间限制: 1 Sec  内存限制: 128 MB
提交: 64  解决: 25

题目描述

The heroes of your favorite action TV show are preparing for the final confrontation with the villains. Fundamentally, there are two rivals who will fight each other: a very important main hero who wants to save the universe and an equally important main villain who wants to destroy it. However, through countless recursive spin-offs, they may have slightly less important sidekicks (a hero and a villain who are rivals themselves), who in turn may also have their own (even less important) sidekicks, and so on. Note that there is an equal number of heroes and villains, and each rival pair has at most one sidekick pair.
Initially, every character will fight their rival, with the winner being determined by who has the higher Power Level. If a hero and their corresponding villain have the same Power Level, their battle will be determined by their sidekicks’ battle, as the winning sidekick can help as a sort of tiebreaker. (If rivals of equal Power Level do not have sidekicks, the hero character will win with the help of random passersby.) However, whenever a battle is won by either side, there is nothing the sidekicks can do about it – this is because the people behind the show believe some fans might get upset if a character were to get defeated by a bunch of less important characters, so they would lose regardless of the Power Levels.
After the battles between rivals (and possible tiebreakers) are done, the most important character remaining will defeat the rest of the opposing side and determine the fate of the universe. Fortunately, the heroes can ensure victory through hard, rigorous training. For each day they spend training, the Power Level of each hero increases by 1, while the villains’ Power Levels remain constant.
But you already knew all this. The question plaguing your mind is how long the training is going to take.

 

输入

The input consists of:
•one line with an integer n (1 ≤ n ≤ 1 000), giving the number of rival pairs.
•one line with n integers h1, ... , hn (1 ≤ hi ≤ 1 000 for each i), the i-th value giving the Power Level of the i-th most important hero.
•one line with n integers v1, ... , vn (1 ≤ vi ≤ 1 000 for each i), the i-th value giving the Power Level of the i-th most important villain.


 

输出

Output a single integer, the minimum number of days the heroes need to spend training in order for their side to win.

 

样例输入

4
5 3 1 1
8 6 9 1

 

样例输出

4

题意:读题很不友好系列。给你n个英雄和n个灭霸的战斗值,一一对决,两个人的能力值要是不一样就能力值高的赢,要是一样的话,可以找一个帮手来,要是帮手能把对方灭掉也是可以的,算我赢,帮手呢一
定要在我的编号后面才可以,赢了的人的能力值不会掉,也不会死,最重要的一点,一下降低本题难度的是,赢的人中,等级最高(即标号最小的那个),双方谁的标号最小的那个小哪一就赢。英雄一天每个人
增加1的战斗值,问几天之后可以赢得灭霸队伍。
做法:我们知道,第一局谁赢谁就赢了啊,因为我的赢的人中标号没有比1小的了。于是对于第一个对决,要是英雄1本来就比灭霸1等级高,那么不需要训练。如果相等,要看之后的帮手能否打败灭霸,打不过的
话再多训练一天,英雄1大于灭霸1一定可以赢。就是在帮手中找到活着的战斗值最大的即可。
疑问:这里我只找了英雄队伍帮手最大的,比较能否打败灭霸,没有找灭霸队伍最大的能否打败英雄,但是竟然奇迹的过了,明天问问陈东明。挖坑
代码如下:
#include<stdio.h>
#include<iostream>
 
using namespace std;
 
int n;
int a[1010] , b[1010];
 
void input()
{
    for(int i=1; i<=n; i++)
    {
        scanf("%d" , &a[i]);
    }
    for(int i=1; i<=n; i++)
    {
        scanf("%d" , &b[i]);
    }
}
 
bool ok(int x)
{
    for(int i=2; i<=n; i++)
    {
        if(a[i]+x > b[i])
            return true;
        else if(a[i]+x < b[i])
            return false;
    }
    return true;
}
 
int main()
{
    while( scanf("%d" , &n) != EOF )
    {
        input();
        if(a[1]>b[1])
        {
            printf("0\n");
        }
        else
        {
            if( ok(b[1]-a[1]) )
            {
                printf("%d\n" , b[1]-a[1]);
            }
            else
            {
                printf("%d\n" , b[1]-a[1]+1);
            }
        }
    }
 
 
 
    return 0;
}

 

 
posted @ 2018-09-07 21:54  Flower_Z  阅读(319)  评论(0编辑  收藏  举报