poj-1083-Moving Tables(hdu-1050)
Moving Tables
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: Accepted:
Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure. The floor has 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 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 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. 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.
Input The input consists of T test cases. The number of test cases ) (T is given in the first line of the input file. Each test case begins with a line containing an integer N , <= N <= , 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 -rd
line, the remaining test cases are listed in the same manner as above.
Output The output should contain the minimum time in minutes to complete the moving, one per line.
Sample Input Sample Output Source Taejon 题意:公司有400个房间,单号对双号对门,中间有一条走廊,
现在要搬东西,给出要搬的次数,还有每次搬动的房间号,
每次搬动需要10分钟,搬动过程中的那段走廊不能被使用,
求最大搬动时长。
解析:
按a从大到小排序,开始我按b从大到小排序,一直wa,后来找到
一组测试数据发现按b排序时错误的。 本题还可以统计每个点进过的次数,所有点最大的次数即为移动的次数
*/ #include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<string>
using namespace std;
#define maxn 460
struct Tab
{
int a;
int b;
bool operator < (const Tab & ta)const
{
return b<ta.b;
}
} tab[maxn],tab1[maxn];
int main()
{
int i,T,n,b,sum,k;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=; i<n; i++)
{
scanf("%d%d",&tab[i].a,&tab[i].b);
if(tab[i].a>tab[i].b)
swap(tab[i].a,tab[i].b);
}
sum=;
int f=;
do
{ sort(tab,tab+n);
k=;
b=tab[].b;
printf("第 %d 次\n%d -> %d\n",f,tab[].a,tab[].b);
for(i=; i<n; i++)
{
if(tab[i].a-b-b%>=)
{
printf("%d -> %d\n",tab[i].a,tab[i].b);
b=tab[i].b; }
else
{
tab1[k].a=tab[i].a;
tab1[k].b=tab[i].b;
k++;
}
}
sum++;
n=k;
memcpy(tab,tab1,sizeof(tab1));
f++;
}while(n);
printf("%d\n",sum*);
}
return ;
}
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<string>
using namespace std;
#define maxn 460
int main()
{
int t,i,n,b,e;
scanf("%d",&t);
while (t--)
{
int c[]={},m=;
scanf("%d",&n);
while (n--)
{
scanf("%d%d",&b,&e);
if (b>e)
{
i=b;
b=e;
e=i;
}
for (i=(b-)/;i<=(e-)/;++i)++c[i];
}
for (i=;i<;++i)if (m<c[i])m=c[i];
printf("%d\n",*m);
}
return ;
}
poj-1083-Moving Tables(hdu-1050)的更多相关文章
- POJ 1083 && HDU 1050 Moving Tables (贪心)
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- OpenJudge/Poj 1083 Moving Tables
1.链接地址: http://poj.org/problem?id=1083 http://bailian.openjudge.cn/practice/1083/ 2.题目: 总时间限制: 1000m ...
- POJ 1083 Moving Tables 思路 难度:0
http://poj.org/problem?id=1083 这道题题意是有若干段线段,每次要求线段不重叠地取,问最少取多少次. 因为这些线段都是必须取的,所以需要让空隙最小 思路: 循环直到线段全部 ...
- POJ 1083 Moving Tables
题意:一个建筑物里有400个房间,房间都在一层里,在一个走廊的两侧,如图,现在要搬n张桌子,告诉你每张桌子是从哪个屋搬到哪个屋,搬桌子的线路之间不可以有重叠,问最少搬几次. 解法:贪心.一开始觉得只要 ...
- 1083 Moving Tables
题目链接:http://poj.org/problem?id=1083 题意: 走廊两边分别有200个房间,一边连续编号为1-399的奇数,另一边是2-400的偶数, 如果从房间 i 移动桌子到房间 ...
- poj 1083 Moving Tables_dp
题意:给你n个凳子,接着告诉你一个凳子从a房间到b房间,运输时间为10分钟,走廊很窄能通过一张凳子,当然不堵塞的话能同时扮凳子,问最小花费多少时间 因为数据很小就直接用数组统计了,a,b如果是奇数的话 ...
- HDOJ 1050 Moving Tables
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 1050 Moving Tables
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- hdoj 1050 Moving Tables【贪心区间覆盖】
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 杭电 1150 moving tables
http://acm.hdu.edu.cn/showproblem.php? pid=1050 Moving Tables Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- WPF画图简便技巧
下面这个就是:起点在(0,0)开始的正方形.(用绿色填充).此方法比一条一条的写方便多了! <Path Fill="LawnGreen" Data="M 0 0 L ...
- 为什么.NET感觉上比Java差一点
其实,我本人很喜欢.NET技术.工作经历中,大部分时间也在使用.NET开发. 这几年,由于工作的原因,开始进入Java+Linux世界. 今年,开始学习Python和Scala. 使用.NET时,有种 ...
- ArrayList集合
//在使用ArrayList时别忘了引用命名空间 using System.Collections;//首先得导入命名空间 //01.添加方法 add方法 //告诉内存,我要存储内容 ArrayLis ...
- 「C语言」文件的概念与简单数据流的读写函数
写完「C语言」单链表/双向链表的建立/遍历/插入/删除 后,如何将内存中的链表信息及时的保存到文件中,又能够及时的从文件中读取出来进行处理,便需要用到”文件“的相关知识点进行文件的输入.输出. 其实, ...
- Javascript的一种代码结构方式——插件式
上几周一直在做公司的webos的前端代码的重构,之中对javascript的代码进行了重构(之前的代码耦合严重.拓展.修改起来比较困难),这里总结一下当中使用的一种代码结构——插件式(听起来怎么像独孤 ...
- Win10安装framework3.5
.NET少不了framewrok,其版本也比较多,默认情况下win7及上版本没有安装framework3.5,但有些软件又需要它,比如arcgis软件在安装时会检测是否存在3.5,如果没有,将不会正常 ...
- 移动,企业社交(sharepoint2013)--jindahao(金大昊)
MobileIncreasingly, a major component of sharing and collaborating involves mobile access. SharePoin ...
- Java中字节流和字符流的比较(转)
字节流与和字符流的使用非常相似,两者除了操作代码上的不同之外,是否还有其他的不同呢? 实际上字节流在操作时本身不会用到缓冲区(内存),是文件本身直接操作的,而字符流在操作时使用了缓冲区,通过缓冲区再操 ...
- Device Channels in SharePoint 2013
[FROM:http://blog.mastykarz.nl/device-channels-sharepoint-2013/] One of the new features of SharePoi ...
- Force.com微信开发系列(八)生成带参数的二维码
为了满足用户渠道推广分析的需要,公众平台提供了生成带二维码的接口.使用该接口可以获得多个带不同场景值的二维码,用户扫描后,公众号可以接收到事件推送.目前有两种类型的二维码,分别是临时二维码和永久二维码 ...