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

原文地址:https://www.cnblogs.com/Flower-Z/p/9607295.html

时间: 2024-10-24 18:14:05

It’s Time for a Montage的相关文章

如何在线制作gif图片?

最近想做个gif在线制作的网站,所以研究下了imagemagick和graphicsmagick制作gif图片 站已经做出来了:有兴趣的朋友可以先看看 http://www.sosogif.com/make_online.jsp 源码下载地址1:http://www.quzhuanpan.com/home/sourceList.jsp?type=6 源码下载地址2:http://www.quzhuanpan.com/download/checkResult.action?id=30&type=6

Image Retrieval Using Customized Bag of Features

This example shows how to create a Content Based Image Retrieval (CBIR) system using a customized bag-of-features workflow. Introduction Content Based Image Retrieval (CBIR) systems are used to find images that are visually similar to a query image.

学习笔记(2)---Matlab 图像处理相关函数命令大全

Matlab 图像处理相关函数命令大全 一.通用函数: colorbar  显示彩色条 语法:colorbar \ colorbar('vert') \ colorbar('horiz') \ colorbar(h) \ h=colorbar(...) \ colorbar(...,'peer',axes_handle) getimage 从坐标轴取得图像数据 语法:A=getimage(h) \ [x,y,A]=getimage(h) \ [...,A,flag]=getimage(h) \

计算机图形学研究领域分哪些

计算机图形学各个领域的目标或许不同,但最终的形式都是渲染(即绘制)在二维的显示设备上的图像.下面是一个简单(可能并不完全)的分类: ?计算机图形学-领域及分支: ?1 绘制1.1 真实感绘制(非实时)1.1.1 光线追踪(Ray-tracing)1.1.2 全局光照(Global Illumination)......1.2 实时绘制1.2.1 Shading(BRDF, Programmable Shading等)1.2.2 纹理(Texture Synthesis, 反走样, 采样等)1.2

linux基础学习-第十五天 磁盘管理(SWAP、dd、quota、RAID、LVM)

2016-08-26: 授课内容: 1.SWAP交换分区的创建 2.dd命令的使用 3.设定文件系统配额 4.设定和管理软RAID设备 5.配置逻辑卷 1.swap (1)SWAP分区:模拟内存,当物理内存不足时,进程需要内存资源是,内存会把一部分没有在用的进程分页挪到硬盘的模拟内存中,腾出空间被现在需要使用内存资源的进程 即其作用是可以允许内存过载使用,windows系统也有类似的机制,由于虚拟内存空间是建立在硬盘之上,所以其速度和性能会大打折扣,所以适合临时使用 (2)创建SWAP分区: 相

各式 Web 前端開發工具整理

程式碼編寫工具 (Coding Tools) 工作流程/建置/組合 (Workflow/Builds/Assemblers) lumbar brunch grunt lineman yeoman Takeoff mimosa codeKit liveReload stealJS anvil.js modjs AUTOMATON Fire.app 瀏覽器套件管理員 (Browser Package Managers) (參見: Front-End Package Manager Compariso

图象处理通用函数

一.通用函数: colorbar 显示彩色条 语法:colorbar \ colorbar('vert') \ colorbar('horiz') \ colorbar(h) \ h=colorbar(...) \ colorbar(...,'peer',axes_handle) getimage 从坐标轴取得图像数据 语法:A=getimage(h) \ [x,y,A]=getimage(h) \ [...,A,flag]=getimage(h) \ [...]=getimage imshow

15款值得开发者一试的最新的前端框架

无论你是新开发者还是经验丰富的老程序员,前端框架可以有效地在开发的早期阶段提升开发效率.在这篇文章中,我们选择了15个新框架分享给开发人员,你肯定会想尝试一下这些新鲜的框架. 您可能感兴趣的相关文章 网站开发中很有用的 jQuery 效果[附源码] 分享35个让人惊讶的 CSS3 动画效果演示 十分惊艳的8个 HTML5 & JavaScript 特效 Web 开发中很实用的10个效果[源码下载] 12款经典的白富美型 jQuery 图片轮播插件 1. RAD.js RAD.js is a fr

英语电影剧本大全(中英对照)

目     录 <泰坦尼克号>全部英文剧本 TV REPORTER: Treasure hunter Brock Lovett is best known for finding Spanish gold off islands in the best Caribbean. LIZZY: It’s OK, I’ll get you in a minutes. Come on. TV REPORTER: Now he is using Russian subs to reach the most