poj 1083
来源:互联网 发布:每日一文 知乎 编辑:程序博客网 时间:2024/04/29 05:02
一、题目大意
一层里面有400个房间,北边和南边各有200个房间,要从一个房间里面把一张桌子移动到另一个房间(特别注意有可能有s比t大的情况,我因为这个WA了一次),需要占用这两个房间之间的所有走廊(包括这两个房间前面的),每移动一个桌子需要10分钟,给出需要移动的桌子的数据(从哪移动到哪),要求计算出最少需要多少分钟才能把所有桌子移动完。
另外注意:
房间1和2前面是同一个走廊,所以从1移动到2只需要占用一个走廊,房间2和3前面不是同一个走廊,因此从2移动到3需要占用2个走廊。
问题的关键是:
什么情况下移动不能同时进行?
比如3—5和4—6这里有重复要使用的4这个有什么用呢?而 10—20和30—40,这里没有重复的区间,可以同时进行移动。。想来想去他为什么要这么说,其实就是要告诉你去求覆盖区间最大的区域,所以acm重点在数学模型的抽象
二、AC code
分析:
本来是在dp专题里面找到的这题,很像贪心法,但是我硬是没想出如何用dp,倒是利用每条走廊都设置一个计数器,每经过一次+1,最大的次数X10就是答案。
#include <stdio.h>#include <iostream>#include <string.h>#define MAXN 202using namespace std;int corridor[MAXN];int main(){ //freopen("input.txt","r",stdin); int T; cin >> T; while(T--) { memset(corridor,0,sizeof(corridor)); int N; cin>>N; int time = 0; for (int i = 0; i < N; ++i) { int s,t; cin>>s; cin>>t; if (s>t) { int tmp = s; s = t; t = tmp; } for (int j = (s%2 == 1)?(s+1)/2:s/2; j <= ( (t%2 == 1)?(t+1)/2:t/2 ); ++j) /* count time of the use of corridor */ if ( time < ++corridor[j] ) time = corridor[j]; } cout<<time*10<<endl; } return 0;}
1 0
- poj 1083 & poj 1328
- POJ 1083
- Poj 1083
- POJ 1083
- POJ 1083
- poj 1083
- POJ-1083
- POJ 1083
- POJ 1083
- poj 1083
- POJ 1083
- POJ 1083
- poj 1083
- poj 1083
- POJ-1083
- poj 1083
- poj 1083
- poj 1083
- 【DBaas】如何建立一个Oracle 数据库云服务
- SDL学习小结(1)
- POJ2420爬山算法
- [Docker] ubuntu14.04LTS 上部署自己的 provider docker registry
- GDCPC GO
- poj 1083
- 互联网架构设计之Redis篇-【Redis Windows版本安装过程】
- android网络请求Volley框架的使用
- 蓝桥杯 无穷分数
- 为啥要用(++i)分析++i和i++在效率上的区别
- 计数排序
- Swift中的switch 和 do while
- BestCoder Round #76
- img标签的属性title和alt