POJ1083 Moving Tables
来源:互联网 发布:白金数据 原著 编辑:程序博客网 时间:2024/05/01 08:36
题目大意:走廊中搬桌子,走廊的宽度只允许一张桌子通过,但允许路线不交叉的同时搬桌子,每次搬桌子都需要10分钟,问所需最短时间。
解题思路:统计搬桌子过程中经过每个房间的最大次数,即可求出最短时间。
根据房间号排列规则,奇数号\2+1;偶数号\2
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring> using namespace std; #define MAXN 1010 int T;int n;int cnt[MAXN];int maxcnt; void Update(int l,int r){ for(int i=l;i<=r;i++) { cnt[i]++; maxcnt=max(maxcnt,cnt[i]); }} int main(){ scanf("%d",&T); while(T--) { scanf("%d",&n); maxcnt=0; memset(cnt,0,sizeof(cnt)); for(int i=0;i<n;i++) { int a,b; scanf("%d%d",&a,&b); if(a&1) a=a/2+1; else a/=2; if(b&1) b=b/2+1; else b/=2; if(a>b) swap(a,b); Update(a,b); } printf("%d\n",maxcnt*10); } return 0;}
可理解为判断奇偶,效率比a%2高
0 0
- POJ1083 Moving Tables
- poj1083 Moving Tables
- POJ1083 Moving Tables
- POJ1083 Moving Tables
- POJ1083--Moving Tables
- POJ1083 Moving Tables
- poj1083:moving tables
- poj1083 Moving Tables
- poj1083 Moving Tables
- poj1083 Moving Tables
- [POJ1083]Moving Tables
- POJ1083-Moving Tables
- poj1083-Moving Tables-贪心
- POJ1083 Moving Tables
- [POJ1083]Moving Tables
- POJ1083-Moving Tables解题报告
- 【离散化】poj1083 Moving Tables
- POJ1083,Moving Tables,好纠结的题
- BZOJ 1861 [Zjoi2006] Book 书架
- Probability
- math.h 三角函数
- 理解java web项目中的路径问题
- 处理:/var/redis/run/redis_6379.pid exists, process is already running or crashed
- POJ1083 Moving Tables
- A1078. 逆序对个数
- Android中BitmapFactory.Options学习
- 1.21
- Android下拉刷新与轮播图冲突解决方案
- Android 弹性ScrollView
- 简易电子钟
- 六、浅记java面向对象
- 通信协议——Http、TCP、UDP