War 2600HDU 一道简单题

#include <iostream>
#include <algorithm>

using namespace std;

struct Node
{
    int x,y;
}interval[101];
bool cmp(Node a,Node b)
{
    if(a.y != b.y)
      return a.y > b.y;
    return a.x < b.x;
}
void init(int n)
{
    string s;
    for(int i = 0;i < n;i++)
    {
        cin>>interval[i].x>>interval[i].y;
        getline(cin,s);
    }
    sort(interval,interval+n,cmp);
}
void Judge(int n)
{
    bool flag = false;
    int ans = interval[0].x;
    for(int i = 1;i < n;i++)
    {
        if(ans-interval[i].y>1){
          flag = true;
          break;
        }else
        {
            if(interval[i].x<ans)
              ans = interval[i].x;
        }
    }
    if(flag)
      cout<<ans-1<<endl;
    else
      cout<<"Badly!"<<endl;
}
int main()
{
    int n;
    while(cin>>n)
    {
        int s,e;
        cin>>s>>e;
        init(n);
        if(interval[0].y < e)
          cout<<e<<endl;
        else
          Judge(n);
    }
    return 0;
}

 
 
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:
A i B i N i (A,B is integer, p <= A, B <= q, N i 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
  
  
3 100 200 100 120 RtWar 110 140 WeWar 141 199 QqWar 1 -600 600 -600 600 Cool War
 

Sample Output
  
  
200 Badly!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值