It’s Time for a Montage

**

Problem I: It’s Time for a Montage(German Collegiate Programming Contest 2018)

**

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个人。从1到n按顺序开始,期间只要你有一个大于对方,你就获胜,或者你方所有和对方所有人的数值刚好都一样也能获胜。
如果你的数值不够,则每天你方所有人的数值都能+1,问你至少需要多少天才能获胜。

代码

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
#define maxn 1005
int h[maxn], v[maxn];

int main(){
	int day = 0;
	int i, j, k, n, m;
	scanf("%d",&n);
	for(i = 1; i <= n; i++){
		scanf("%d",&h[i]);
	}
	for(i = 1; i <= n; i++){
		scanf("%d",&v[i]);
	}
	if(h[1]>v[1]){
		printf("0\n");
		return 0;
	}
	else{
		day = (v[1]-h[1]);
		for(i = 2; i <= n; i++){
			if(h[i]+day<v[i]){
				printf("%d\n",++day);
				return 0;
			}else if(h[i]+day>v[i]){
				printf("%d\n",day);
				return 0;
			} 
		}
		printf("%d\n",day);
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值