首页 技术 正文
技术 2022年11月15日
0 收藏 594 点赞 2,702 浏览 2317 个字

Moving Tables

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 42736    Accepted Submission(s): 13986

Problem DescriptionThe famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure.

hdu1050Moving Tables(贪心)

The floor has 200 rooms each on the north side and south side along the corridor. Recently the Company made a plan to reform its system. The reform includes moving a lot of tables between rooms. Because the corridor is narrow and all the tables are big, only one table can pass through the corridor. Some plan is needed to make the moving efficient. The manager figured out the following plan: Moving a table from a room to another room can be done within 10 minutes. When moving a table from room i to room j, the part of the corridor between the front of room i and the front of room j is used. So, during each 10 minutes, several moving between two rooms not sharing the same part of the corridor will be done simultaneously. To make it clear the manager illustrated the possible cases and impossible cases of simultaneous moving.

hdu1050Moving Tables(贪心)

For each room, at most one table will be either moved in or moved out. Now, the manager seeks out a method to minimize the time to move all the tables. Your job is to write a program to solve the manager’s problem.

 InputThe input consists of T test cases. The number of test cases ) (T is given in the first line of the input. Each test case begins with a line containing an integer N , 1<=N<=200 , that represents the number of tables to move. Each of the following N lines contains two positive integers s and t, representing that a table is to move from room number s to room number t (each room number appears at most once in the N lines). From the N+3-rd line, the remaining test cases are listed in the same manner as above. OutputThe output should contain the minimum time in minutes to complete the moving, one per line. Sample Input3410 20 30 40 50 60 70 80 2 1 3 2 200 3 10 100 20 80 30 50  Sample Output102030

题意:有400个房间两边各200个,中间有一条走廊,在房间之间搬桌子,走廊的宽度只能容纳一张桌子,所以如果1号房间搬桌子到5号房间的时候二号房间就不能搬桌子,因为这块区域的走廊塞满了,但7号房间的走廊还是空的,可以搬,搬一次需要10分钟。问搬完给出的桌子需要多少时间。

题解:之间搬桌子的那块区域作为下标的数组值+10,每次都这样。最后这个数组中的最大值就是搬完所有桌子的时间。每次搬桌子的路径都可以看成是从低编号房间搬到高编号房间。这样方便为那块区域的数值+10,因为房间是面对面的,所以计算区域的时候可以从奇数编号房间到偶数编号房间。这样区域比较全。

 #include<bits/stdc++.h>
using namespace std;
int a[];
int main() {
int t;
while(~scanf("%d",&t)) {
while(t--) {
int n;
memset(a,,sizeof(a));
scanf("%d",&n);
int maxx=;
for(int i=; i<n; i++) {
int start,end;
scanf("%d %d",&start,&end);
if(start>end)swap(start,end);
if(start%==) {
start-=;
}
if(end%)end+=;
for(int j=start; j<=end; j++) {
a[j]+=;
maxx=max(maxx,a[j]);
}
}
printf("%d\n",maxx);
} }
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,991
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,505
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844