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) ...
随机推荐
- 关于C#读取MySql数据时,返回DataTable中某字段数据是System.Array[]形式
我在使用C#(VS2008)读取MySql数据库(5.1版本)时,返回的DataTable数据中arrivalDate字段数据显示为System.Array[]形式(程序中没有对返回的数据进行任何加工 ...
- csharp: Export DataSet into Excel and import all the Excel sheets to DataSet
/// <summary> /// Export DataSet into Excel /// </summary> /// <param name="send ...
- pbfunc外部函数扩展应用-在Powerbuilder中进行Http的GET、POST操作
利用PBFunc扩展函数进行Http的操作时,需要对n_pbfunc_http的以下几个函数进行参数设置: of_set_URL(...)//要进行GET或POST的url,必须 of_set_Con ...
- 【GPU编解码】GPU硬解码---CUVID
问题描述:项目中,需要对高清监控视频分析处理,经测试,其解码过程所占CPU资源较多,导致整个系统处理效率不高,解码成为系统的瓶颈. 解决思路: 利用GPU解码高清视频,降低解码所占用CPU资源,加速解 ...
- FAQ_1_陌生的VERSION.SDK_INT
看到VERSION.SDK_INT不禁诧异,这是何物?! 看API的定义,如下: 原来是一个常量值.但是这个常量值可以根据系统的不同而不同哟!为了揭开其神秘的面纱,将源码ctrl如下: 可以看出,获取 ...
- 你可以使用 play framework 做5件很爽的事情http://www.anool.net/?p=629
1.绑定HTTP参数到JAVA方法里的参数. 使用PLAY可以很简单的从JAVA代码中检索HTTP参数.只要把方法参数申明成和HTTP参数相同既可. 比如,这个request: Http代码 /art ...
- javascript --- 设计模式之单体模式(二)
在JavaScript里,实现单例的方式有很多种,其中最简单的一个方式是使用对象字面量的方法,其字面量里可以包含大量的属性和方法: var her = { property1: 'someing', ...
- GetReadyForWin10Develop
GetReadyForWin10Develop 序言 今年4月29日晚的微软的Build大会上,微软在现场为我们演示了Android和IOS应用移植到windows平台,加上原本可以开发win8应用的 ...
- Azure SQL Database 时间点还原(Point in Time Restore)功能
微软中国TechNet 7 Oct 2014 9:17 PM Comments 0 Likes 原文地址:http://blogs.technet.com/b/azuretw/archive/20 ...
- ArcGis在Oracle中常用的sql
) m 查询坐标数据 更新坐标: update tableName set SHAPE = mdsys.sdo_geometry(2002,28420,null,mdsys.sdo_elem_info ...