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) ...
随机推荐
- knockout的依赖属性dependentObservable的参数 和Value转换器
可写的依赖监控属性ko.dependentObservable的参数 read: 必选,一个用来执行取得依赖监控属性当前值的函数write: 可选,如果声明将使你的依赖属性可写,别的代码如果这个 ...
- Go eclipse plugin
Installation Requirements: Eclipse 4.5 (Mars) or later. Java VM version 8 or later. Gocode and Go or ...
- lnmp+phpmyadmin配置与出现问题
本博客归moka同学(新浪微博:moka同学)本人亲自整理,如有使用,请加链接注明出处. lnmp 安装完全后,配置phpmyadmin .其访问方式为 http://202.18.400.379/p ...
- 彻底卸载JDK的-并只依赖配置环境安装JDK(不依赖注册表)-解决Error opening registry key'software\Javasoft\Java Runti问题
一.备份安装好的绿色版JDK a.重新安装JDK到任意目录,假设这个目录是C:\java.b.将装好的JDK,JRE拷贝到任意一个其他目录,如D:\bak,这样做的目的主要是为了备份JDK.(建议打成 ...
- css实现垂直居中的方法
1,设置其line-height值,使之与其高度相同 2,设置table结构,用vertical-align:middle; 3,应用定位,父级别:position:relative:子级:posit ...
- Jquey Form 异步提交文件参数并且在http 信息头header中加上一定参数
1.下载jQuery.Form 包 官网下载:http://jquery.malsup.com/form/#download 2.模拟代码: <!DOCTYPE html> <htm ...
- andriod arcgis加载影像TIF
private static final String TAG = "MainActivity"; private MapView mapView = null; @Overrid ...
- 推导大O阶方法
用大写O()来体现算法时间复杂度的记法,我们称之为大O阶记法. O(1)叫做常数阶:O(n)叫做线性阶:O(n^2)叫做平方阶. 1.用常数1取代运行时间中的所有加法常数. 2.在修改后的运行次数函 ...
- 内置对象Clob对从数据库表中取的字符大对象CLOB类型的列值进行读取操作
package readclobDemo.bao; import java.io.IOException; import java.io.Reader; import java.sql.Clob; i ...
- 系统自带的NSJSONSerialization解析json文件
#import "ViewController.h" #import "Student.h" #import "GDataXMLNode.h" ...