Moving Tables

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 24316    Accepted Submission(s):
8053

Problem 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. 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 N+3-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
 
题解:因为是双排房间,所以对面的两间不可能同时往外搬桌子如1 2处在对面数据
1  2
3  4
结果应该是20,而不是10,
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define MAX 1100
using namespace std;
int dp[MAX];
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int n,t,m,i,j;
scanf("%d",&t);
int a,b,c;
while(t--)
{
scanf("%d",&n);
memset(dp,0,sizeof(dp));
for(i=0;i<n;i++)
{
scanf("%d%d",&a,&b);
if(a>b)
{
c=a;
a=b;
b=c;
}
a=(a+1)/2;
b=(b+1)/2;
for(j=a;j<=b;j++)
{
dp[j]++;
}
}
sort(dp,dp+200,cmp);
printf("%d\n",dp[0]*10);
}
return 0;
}

  

hdoj 1050 Moving Tables【贪心区间覆盖】的更多相关文章

  1. HDOJ 1050 Moving Tables

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

  2. Hdoj 1050.Moving Tables 题解

    Problem Description The famous ACM (Advanced Computer Maker) Company has rented a floor of a buildin ...

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

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

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

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

  5. 高效算法——E - 贪心-- 区间覆盖

    E - 贪心-- 区间覆盖 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/E 解题思路: 贪心思想, ...

  6. 【题解】Cut the Sequence(贪心区间覆盖)

    [题解]Cut the Sequence(贪心区间覆盖) POJ - 3017 题意: 给定一大堆线段,问用这些线段覆盖一个连续区间1-x的最小使用线段的数量. 题解 考虑一个这样的贪心: 先按照左端 ...

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

  8. HDU – 1050 Moving Tables

    http://acm.hdu.edu.cn/showproblem.php?pid=1050 当时这道题被放在了贪心专题,我又刚刚做了今年暑假不AC所以一开始就在想这肯定是个变过型的复杂贪心,但是后来 ...

  9. hdu_1050 Moving Tables 贪心

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

随机推荐

  1. lower_bound()函数

    头文件 # include<algorithm> 函数简介 lower_bound()返回一个 iterator 它指向在[first,last)标记的有序序列中可以插入value,而不会 ...

  2. 输出第N个素数

    输出第N个素数 public class FindNthPrime { public static void main(String[] args){ int N = Integer.parseInt ...

  3. Win32中GDI+应用(一)

    GDI+, Microsoft Graphics Device Interface Plus, 是微软在继GDI(Microsoft Graphics Device Interface)后推出的图形编 ...

  4. php之工厂模式

    工厂类是指包含一个专门用来创建其他对象的方法的类,工厂类在多态性编程实践中是至关重要的,它允许动态的替换类,修改配置,通常会使应用程序更加灵活,熟练掌握工厂模式高级PHP开发人员是很重要的. 工厂模式 ...

  5. jquery文本折叠

    /** * Created by dongdong on 2015/4/28. */(function($){ var defaults = { height:40, //文本收起后的高度 speed ...

  6. Oracel用rownum实现真分页

    因为oracle的rownum是一个伪列,使用的时候如果要用必须查询出来显示的标记例如本sql中标记为 num. 值得一提的是最内层的这个查询sql:“select a.集团规范编码...”本身有一个 ...

  7. JavaScript学习总结【3】、JS对象

    在 JS 中一切皆对象,并提供了多个内置对象,比如:String.Array.Date 等,此外还支持自定义对象.对象只是一种特殊类型的数据,并拥有属性和方法,属性是与对象相关的值,方法是能够在对象上 ...

  8. jquery 学习日记之选择器

    看完Jquery选择器的教程视频后,对jquery的选择器有一定的认识和了解,现整理一下知识: 一.jquery基本选择器,这类比较简单,一笔带过. #id 选择器,是选择  匹配id值中的第一个元素 ...

  9. #Leet Code# Root to leaf

    语言:Python 描述:使用递归实现 def getList(self, node): if node is None: return [] if node.left is None and nod ...

  10. python随机数

    前提:需要导入random模块 >>>import random 1.random.random random.random()用于生成一个0到1的随机符小数: 0 <= n ...