hdu2600

来源:互联网 发布:java写接口供别人调用 编辑:程序博客网 时间:2024/05/29 05:55

War

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3173    Accepted Submission(s): 1137


Problem Description
      War is the reciprical and violent application of force between hostile political entities aimed at bringing about a desired political end-state via armed conflict. War is an interaction in which two or more militaries have a “struggle of wills”. When qualified as a civil war, it is a dispute inherent to a given society, and its nature is in the conflict over modes of governance rather than sovereignty. War is not considered to be the same as mere occupation,murder or genocide because of the reciprical nature of the violent struggle, and the organized nature of the units involved.
      War is also a cultural entity, and its practice is not linked to any single type of political organisation or society. Rather, as discussed by John Keegan in his “History Of Warfare”, war is a universal phenomenon whose form and scope is defined by the society that wages it.

      Today we don't want to talk about war, rather than , I want you to tell me which year there was no war.
 

Input
For each test case, first input one integer N(1<= N <= 100), then two integers p and q (-6000000 <= p <= q <= 6000000) represent the starting year and the ending year in this case. Followed by N wars.
Each war described as follows:
Ai Bi Ni (A,B is integer, p <= A, B <= q, Ni is a String which is the ith war's name )
Represent that the ith War took place between year A and year B.
 

Output
Output one number represent which year there was no war in the range p and q, if there are not only one year, output the maximum year which there was no war. If all the year had war, just output "Badly!".
 

Sample Input
3100 200100 120 RtWar110 140 WeWar141 199 QqWar 1-600 600-600 600 Cool War
 

Sample Output
200Badly!
题意分析:给一个区间p和q表示年份。给n个战争的起始年份、终止年份和战争名字。问[p,q]区间内最大没有战争的年份是多少。
 
AC代码:
#include<stdio.h>#include<string.h>#include<algorithm>const int INF=0x3f3f3f3f;using namespace std;char s[30];struct node{        int x;        int y;}a[105];int cmp(node a,node b){        return a.x<b.x;}int main(){        int n,p,q,b,c;        while(scanf("%d",&n)!=EOF)        {                scanf("%d%d",&p,&q);                for(int i=1;i<=n;i++)                {                        scanf("%d%d",&a[i].x,&a[i].y);                        gets(s);                }                sort(a+1,a+1+n,cmp);                int cnt=-INF;                int m=a[1].y;                for(int i=2;i<=n;i++)                {                        if(a[i].x>a[i-1].y+1)                        {                                cnt=a[i].x-1;                        }                        if(a[i].y>m)                                m=a[i].y;                }                if(m<q)                        printf("%d\n",q);                else if(cnt!=-INF)                        printf("%d\n",cnt);                else                        printf("Badly!\n");        }        return 0;}

原创粉丝点击