Moving Tables
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 28304   Accepted: 9446

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 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.




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 , 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 3 + 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

3
4
10 20
30 40
50 60
70 80
2
1 3
2 200
3
10 100
20 80
30 50

Sample Output

10
20
30

Source

Taejon 2001

开始做的时候用的贪心后来感觉好麻烦,就又写的Dp;

贪心

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm> using namespace std; typedef struct node
{
int L;
int R;
bool operator <(const node &a)const
{
if(L<a.L||(L==a.L&&R<a.R))
{
return true;
}
return false;
}
} Edge; Edge a[300]; bool vis[300]; int main()
{
int T,n,x,y;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=0; i<n; i++)
{
scanf("%d %d",&x,&y);
if(x>y)
{
swap(x,y);
}
if(x&1)
{
a[i].L=(x+1)/2;
}
else
{
a[i].L=x/2;
}
if(y&1)
{
a[i].R=(y+1)/2;
}
else
{
a[i].R=y/2;
} }
sort(a,a+n);
memset(vis,false,sizeof(vis));
int sum=0;
while(1)
{
int ans=-1;
for(int i=0; i<n; i++)
{
if(!vis[i])
{
if(a[i].L>ans)
{
ans=a[i].R;
vis[i]=true;
}
}
}
if(ans==-1)
{
break;
}
else
{
sum++;
}
}
printf("%d\n",sum*10);
}
return 0;
}

Dp

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
int Dp[201];
int main()
{
int T,n,x,y;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
memset(Dp,0,sizeof(Dp));
for(int i=0; i<n; i++)
{
scanf("%d %d",&x,&y);
if(x>y)
{
swap(x,y);
}
x=(x+1)/2;
y=(y+1)/2;
Dp[x]+=1;
Dp[y+1]-=1;
}
int sum=0;
for(int i=1;i<201;i++)
{
Dp[i]+=Dp[i-1];
sum=max(sum,Dp[i]);
}
printf("%d\n",sum*10);
}
return 0;
}

Moving Tables(贪心或Dp POJ1083)的更多相关文章

  1. zstu.2512. Moving Tables(贪心)

     Moving Tables Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 1182  Solved: 563 Description The famo ...

  2. HDU1050(Moving Tables:贪心算法)

    解题思路: 这种做法是基于hdu2037的做法上考虑的,找出所有可以同时搬运的桌子,然后就很方便求出最短总时间. 还有一种更简单的做法是直接遍历一遍找出与别的重复次数最多的那片区域,重复次数*10就可 ...

  3. hdu_1050 Moving Tables 贪心

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

  4. UVAlive 2326 Moving Tables(贪心 + 区间问题)

    The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in ...

  5. --hdu 1050 Moving Tables(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 AC code: #include<stdio.h> #include<str ...

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

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

  7. POJ1083 Moving Tables

    POJ1083 Moving Tables Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 35297   Accepted: ...

  8. 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 ...

  9. HDOJ 1050 Moving Tables

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

随机推荐

  1. oracle 字符乱码问题解决方案

    今天在客户服务器上遇到了oracle中文乱码问题,第一个想到的是:要想避免oracle字符乱码的问题,需要注意oracle客户端的字符编码和服务端的字符编码保持一致. 于是操作如下: 1.查看服务端字 ...

  2. java类加载机制

    使用某个类是发生的事情 加载->链接(验证.准备.解析)->初始化->可以使用 加载:将class文件字节码内容加载到内存当中,并将这些静态数据转换成方法区中的运行时数据结构 在堆中 ...

  3. mysql怎么导入大文件的sql文件

    这个方法在windows上或者linux上都可以使用 多数人习惯使用phpmyadmin或者一些客户端比如workbench,navicat 但是最有效的是原生的php工具 命令都差不多 请在cmd的 ...

  4. ubuntu下wine安装软件

    安装wine 1. sudo apt-get install playonlinux playonlinux就是wine.或者在软件中心,搜索wine. 2. 在dash搜索playonlinux 安 ...

  5. java 求 两个数的百分比% (转)

    int num1 = 7; int num2 = 9; // 创建一个数值格式化对象 NumberFormat numberFormat = NumberFormat.getInstance(); / ...

  6. yii1 render方法解析(记录下)

    先判断主题(themes)中是否有相对应的文件,如果没有变换file为protected/views路径下的文件,如果有文件则变换为themes路径下的文件.然后,如果加载了viewrender模块( ...

  7. fbset 移植

    手头上的文件系统的fbset有问题,所以就自己从新移植一个到开发板上. 参考链接 http://blog.chinaunix.net/uid-20768928-id-5748009.html 下载地址 ...

  8. Linux下查看某个软件安装路径

    1:如果包是通过yum或者rpm方式安装 [root@localhost yum.repos.d]# rpm -qa //找出系统所有的包,找到对应的文件名 [root@localhost yum.r ...

  9. Python之路-python(paramiko,进程和线程的区别,GIL全局解释器锁,线程)

    一.paramiko 二.进程.与线程区别 三.python GIL全局解释器锁 四.线程 语法 join 线程锁之Lock\Rlock\信号量 将线程变为守护进程 Event事件 queue队列 生 ...

  10. Oracle12c:安装后新建用户及其默认表空间,并创建表测试

    环境: 操作系统:Windows Server2008 R2 X64 Oracle版本:12c 如何安装? -- oracle 12c在oracle linux 6.6 x64上的安装 -- Wind ...