[ACM Steps] 1.3.1 Moving Tables

来源:互联网 发布:知乎接口 编辑:程序博客网 时间:2024/06/07 01:51

http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=1&sectionid=3&problemid=2


搬桌子问题:在一个一次只能通过一张桌子的走廊上将桌子从A房间搬运到B房间,求最少的搬运时间。


贪心问题:每次搬运时间固定,取决于搬运路径重叠最多的次数。所以,将搬运路径经过的房间记录下来,数次最多的即为最小搬运次数。(不可能两人同时走同一段)


#include <stdio.h>#include <string.h>void swap(int& a,int& b){int temp = a;a = b;b = temp;}int main(){int T,n;int begin[200],end[200],room[200];int max;scanf("%d",&T);for(int k=0;k<T;k++){memset(room,0,sizeof(room));scanf("%d",&n);for(int i=0;i<n;i++){scanf("%d %d",&begin[i],&end[i]);if(begin[i] > end[i])swap(begin[i],end[i]);for(int j = (begin[i]-1)/2 ;j <= (end[i]-1)/2;j++)room[j]++;}max = 0;for(int l = 0;l <200;l++){if(room[l] > max)max = room[l];}printf("%d\n", max * 10);}return 0;}




0 0
原创粉丝点击