HDU 2600 War(水题 区间边排序+贪心)
2015-08-29 21:20
525 查看
War
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2340 Accepted Submission(s): 818
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
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!".
[align=left]Sample Input[/align]
3 100 200 100 120 RtWar 110 140 WeWar 141 199 QqWar 1 -600 600 -600 600 Cool War
[align=left]Sample Output[/align]
200 Badly!</pre>//注意战争名含有空格的字符串 一直wa<br /><pre name="code" class="cpp">#include <iostream> #include <cstdio> #include <math.h> #include <string.h> #include <string> #include <algorithm> #include <stdlib.h> using namespace std; struct Range{ int a,b; }r[100+10]; bool cmp(Range x,Range y){ if(x.b!=y.b) return x.b>y.b; else return x.a>=y.a; } int main(){ int t,p,q,i; string s; while(scanf("%d",&t)==1){ scanf("%d%d",&p,&q); for(i=0;i<t;i++){ scanf("%d%d",&r[i].a,&r[i].b); getline(cin,s); if(r[i].a>r[i].b) swap(r[i].a,r[i].b); } sort(r,r+t,cmp); for(i=0;i<t;i++){ if(q>r[i].b) break; else q=min(q,r[i].a-1); } if(q>=p) printf("%d\n",q); else printf("Badly!\n"); } return 0; }
相关文章推荐
- 两段用php转义从而可以防止刷入的代码
- 使用phantomjs抓取JS动态生成的页面
- iOS 并发编程之 Operation Queues
- 3D图形渲染管线
- SIFT特征提取分析
- codeforces293E (树上点分治+树状数组)
- JS添加节点方法与JQuery添加节点方法的比较及总结
- UILabel 学习知识点
- javascript 面向对象继承详解
- python笔记9
- 结构型模式总结
- Oracle11完全卸载方法
- 数据结构 实践项目——数据结构、算法、程序设计
- ComboTree
- UIView 学习知识点
- ubuntu中chromium无法播放flash,安装flash
- python数据驱动举例
- UILabel
- 大三下 期中试卷
- 视图和字段