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)的更多相关文章

  1. POJ 1083 &amp;&amp; HDU 1050 Moving Tables (贪心)

    Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  2. OpenJudge/Poj 1083 Moving Tables

    1.链接地址: http://poj.org/problem?id=1083 http://bailian.openjudge.cn/practice/1083/ 2.题目: 总时间限制: 1000m ...

  3. POJ 1083 Moving Tables 思路 难度:0

    http://poj.org/problem?id=1083 这道题题意是有若干段线段,每次要求线段不重叠地取,问最少取多少次. 因为这些线段都是必须取的,所以需要让空隙最小 思路: 循环直到线段全部 ...

  4. POJ 1083 Moving Tables

    题意:一个建筑物里有400个房间,房间都在一层里,在一个走廊的两侧,如图,现在要搬n张桌子,告诉你每张桌子是从哪个屋搬到哪个屋,搬桌子的线路之间不可以有重叠,问最少搬几次. 解法:贪心.一开始觉得只要 ...

  5. 1083 Moving Tables

    题目链接:http://poj.org/problem?id=1083 题意: 走廊两边分别有200个房间,一边连续编号为1-399的奇数,另一边是2-400的偶数, 如果从房间 i 移动桌子到房间 ...

  6. poj 1083 Moving Tables_dp

    题意:给你n个凳子,接着告诉你一个凳子从a房间到b房间,运输时间为10分钟,走廊很窄能通过一张凳子,当然不堵塞的话能同时扮凳子,问最小花费多少时间 因为数据很小就直接用数组统计了,a,b如果是奇数的话 ...

  7. HDOJ 1050 Moving Tables

    Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  8. 1050 Moving Tables

    Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  9. hdoj 1050 Moving Tables【贪心区间覆盖】

    Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  10. 杭电 1150 moving tables

    http://acm.hdu.edu.cn/showproblem.php? pid=1050 Moving Tables Time Limit: 2000/1000 MS (Java/Others) ...

随机推荐

  1. 实现GridView翻页并且实现CheckBox选中功能的保持

    在GridView与数据库进行绑定后,由得到的数据记录可能有许多条,以至一个页面无法容纳,这时需要进行多页显. 要实现分页显现,只要使用分页类 "PagedDataSource" ...

  2. [moka同学笔记]yii2.0小物件的简单使用(第一种方法)

    这是第一种方法,还有另一种方法,其实都差不多. 1.在创建widgets\HelloWiget.php <?php /** * Created by PhpStorm. * User: Admi ...

  3. jquery自定义插件——window的实现

    本例子实现弹窗的效果: 1.jquery.show.js /* * 开发者:lzugis * 开发时间:2014年6月10日 * 实现功能:点击在鼠标位置显示div * 版本序号:1.0 */ (fu ...

  4. redis 慢日志 slowlog

    1 slowlog是什么 redis的slowlog是redis用于记录记录慢查询执行时间的日志系统.由于slowlog只保存在内存中,因此slowlog的效率很高,完全不用担心会影响到redis的性 ...

  5. Xml序列化、反序列化帮助类

    之前从网络上找了一个Xml处理帮助类,并整理了一下,这个帮助类针对Object类型进行序列化和反序列化,而不需要提前定义Xml的结构,把它放在这儿供以后使用 /// <summary> / ...

  6. FDO error:Failed to label layer(XXX) for class Default

    描述: A column was specified that does not exist. 出现这个问题的原因在于label features 展示的字段不存在或者为空,只要将其勾选去掉或者换个显 ...

  7. 【转】Android Studio中通过快捷键来提取提取方法

    今天来给大家介绍一个非常有用的Studio Tips,有些时候我们在一个方法内部写了过多的代码,然后想要把一些代码提取出来再放在一个单独的方法里,通常我们的做法是复制粘贴,现在我来教给大家一个非常简洁 ...

  8. Android Studio用release模式进行调试

    有时候调试SDK必须要用release版本,但是每次打包混淆太麻烦,希望能在IDE中直接跑出release版本的应用,简单来说就是在debug模式下产生release版本的app,这时候该怎么做呢?当 ...

  9. 用Path来绘制一些图形

    Path是android中用来封装几何学路径的一个类,因为Path在图形绘制上占的比重还是相当大的.你可以用它来绘制各种样式的几何图形,做图表什么的都可以. 一.画线段 1.1 lineT(float ...

  10. 【原】画流程图工具visio使用技巧汇总

    最近写论文需要画不少流程图,有两种选择,一是word, 二是visio.原先一直用word画,效果也还可以,但是每个部件画完后为了便于适应排版变动,需要将需要的模块按下ctrl逐个点击选中后进行组合. ...