1. 程式人生 > >It’s Time for a Montage

It’s Time for a Montage

higher std fan data other who 系列 don n)

問題 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;
}

 

It’s Time for a Montage