UVALive 7483 贪心策略
来源:互联网 发布:百度统计 js请求 编辑:程序博客网 时间:2024/06/04 18:43
题目如下(在线转换PDF到word这差距实在是太大了)
You are the boss of ACM (Air Conditioned Minions), an upstanding company with a single goal of
worlddomination.
The company has N minions. Each minion works evilly from early morning until evening inside
a super secret bunker in Helsinki. After much deliberation, you decided to move your headquarters
to Singapore. However, unlike Helsinki, Singapore is very hot, so the entire complex must be air
conditioned. Withstrenuousworkinghours(underminimumwagetoo), itisimperativethatallyour
minions work under optimal work condition. In particular, all minions must like the temperatures of
theroomstheyarein.
You are planning to construct several rooms in your new hideout, and assign your minions there.
You fix the temperature of each room to any value you want (different rooms may have different
temperatures). Afteryoufixthetemperatures,youwillassigneachofyourminionstotheserooms(a
roomcanholdanynumberofminions). Youwantallminionstolikethetemperaturesoftheirassigned
rooms. Eachminionlikesanintervaloftemperature,andthesepreferenceswillbegiventoyou.
Air conditioners are very expensive to maintain. Thus, you want to construct as few rooms as
possible. Whatistheminimumnumberofroomsyouneedtosetupsuchthatitwouldbepossibleto
assignminionstoroomsasdiscussedearlier?
Input
Theinputfilecontainsseveraltestcases,eachofthemasdescribedbelow.
The first line contains a non-negative integer 2≤N ≤100, giving the number of minions in your
company. The next N lines each describe the temperature preferences of all your minions. The i-th
lineconsistsoftwosinglespaceseparatedintegersLandU (1≤L≤U ≤2N),whichdenotesthatthe
i-thminionlikesanytemperaturebetweenLandU ,inclusively.
Output
Foreachcase,printanintegerdenotingtheminimumnumberofroomsyouneedtoconstructonaline
byitself.
Explanation:
In the first example, one of the possible solutions is to setup two rooms — one with temperature
2,andanotherwithtemperature5. Thefirsttwominionscanbeassignedtothefirstroom,whilethe
thirdminioncanbeassignedtothesecondroom.
Sample Input
3
1 2
2 4
5 6
5
1 2
3 5
4 6
7 9
8 10
Sample Output
2
3
AC代码如下 View Source On GitHub
/**LINK=http://acm.hust.edu.cn/vjudge/contest/view.action?cid=115784#problem/F*/#include <cstdio>#include <cstdlib>#include <cstring>#include <climits>#include <vector>#include <algorithm>using namespace std;#define MAXN 105int main(){ int n; while(scanf("%d",&n)==1) { vector<int> pool[MAXN*2+8]; for(int i=0;i<n;i++) { int a,b; scanf("%d %d",&a,&b); pool[a].push_back(b); } int k=INT_MAX; int cnt=0; for(int i=0;i<MAXN*2+8;i++) { if(k<i) { ++cnt; k=INT_MAX; } for(int j=0;j<pool[i].size();j++) { k=min(k,pool[i].at(j)); } } if(k<INT_MAX) { ++cnt; } printf("%d\n",cnt); } /// End of main loop return 0;}另外我还想用一种朴素的做法解这道题,但是一直WA就不贴代码了。
我在GitHub上建立了一个仓库,用于存放已经AC的题目的源代码。如果各位有未收录的题目或者有更好的解法,欢迎fork仓库+PR~ 让我们共同创建一个AC代码集中仓库,造福ACM Beginner ~
仓库地址: OJ-Problems-Source On GitHub
- UVALive 7483 贪心策略
- UVAlive 2911 Maximum(贪心)
- uvalive 2322(贪心)
- uvalive 2326(贪心)
- uvalive 2519(贪心)
- uvalive 3971(贪心)
- uvalive 3635(贪心)
- uvalive 2911(贪心)
- uvalive 2949(二分+贪心)
- uvalive 4725(贪心 + 二分)
- uvalive 4850(贪心)
- uvalive 3266(贪心)
- uvalive 4094(贪心)
- uvalive 2757(贪心)
- uvalive 4328(贪心)
- UVALive - 5848 Soju 贪心
- UVALive 7416 贪心 multiset
- UVALive 3177-贪心+二分
- const对象默认为文件的局部变量
- Android 图片弹跳动画
- C#二十六 使用Ado.Net调用存储过程
- 解决了在Android原生TextView中,当text长度小于hint时,TextView右方会占据多余的位置
- 多线程(三)
- UVALive 7483 贪心策略
- 传统硬盘与固态硬盘的比较
- html5中的创建热点区域
- 30多条mysql数据库优化方法,千万级数据库记录查询轻松解决
- EasyTouch学习
- 回调函数_结构体
- cqm解题报考01
- 猜读数
- C#中静态与非静态方法比较