题目:http://poj.org/problem?id=1083 题意:有两排房间,每排200个房间,现在要搬桌子,每搬一次花费10分钟,同一段走廊不能同时使用,求至少花费多长时间。 思路:因为每搬一次桌子就要使用一次s到j的走廊,因此,每次s到j的区间加1,最后求出使用次数最多的*10,即为答案。 需要注意的是,当s为偶数的时候,s--,当t为奇数的时候, t++;#include <stdio.h> #include <string.h> const int maxn=400; int num[maxn+10]; int T, n, s, t, tem, ans; int main() { //freopen("in.txt", "r", stdin); scanf("%d", &T); while (T--) { scanf("%d", &n); memset(num, 0, sizeof(num)); for (int i=0; i<n; i++) { scanf("%d %d", &s, &t); if (s>t) tem=s, s=t, t=tem; if (s%2==0) s--; if (t%2==1) t++; for (int j=s; j<=t; j++) num[j]++; } ans=0; for (int i=1; i<=maxn; i++) if (num[i]>ans) ans=num[i]; printf("%d\n", ans*10); } return 0; }
PKU 1083 Moving Tables
最新推荐文章于 2013-03-31 20:03:33 发布