http://acm.hdu.edu.cn/showproblem.php?

pid=1050

Moving Tables

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 18850    Accepted Submission(s): 6440

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
 

简单贪心题,找重叠次数最多的部分。
AC代码:
<span style="font-size:18px;">#include<stdio.h>
#include<string.h>
int a[201];
int main()
{
int n,b,i,m,p,q,t,j,k;
scanf("%d",&n);
for(t=0;t<n;t++)
{
memset(a,0,sizeof(a));
scanf("%d",&b);
for(i=1;i<=b;i++)
{
scanf("%d %d",&p,&q);
p=(p-1)/2;//缩小
q=(q-1)/2;
if(p>q)//确保q大于p
{
m=p;
p=q;
q=m;
}
for(j=p;j<=q;j++)
a[j]++; //标记
}
k=1;
for(j=0;j<200;j++)
if(a[j]>k)//重叠次数最多的
k=a[j];
printf("%d\n",k*10);
} return 0;
}</span>

杭电 1150 moving tables的更多相关文章

  1. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  2. HDU ACM 1050 Moving Tables

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

  3. 杭电ACM题单

    杭电acm题目分类版本1 1002 简单的大数 1003 DP经典问题,最大连续子段和 1004 简单题 1005 找规律(循环点) 1006 感觉有点BT的题,我到现在还没过 1007 经典问题,最 ...

  4. acm入门 杭电1001题 有关溢出的考虑

    最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...

  5. 杭电acm 1002 大数模板(一)

    从杭电第一题开始A,发现做到1002就不会了,经过几天时间终于A出来了,顺便整理了一下关于大数的东西 其实这是刘汝佳老师在<算法竞赛 经典入门 第二版> 中所讲的模板,代码原封不动写上的, ...

  6. 杭电OJ——1198 Farm Irrigation (并查集)

    畅通工程 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可 ...

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

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

  8. Moving Tables(贪心或Dp POJ1083)

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

  9. 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”

    按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...

随机推荐

  1. 17. PROCESSLIST

    17. PROCESSLIST PROCESSLIST表提供有关正在运行的线程的信息. PROCESSLIST表有以下列: ID :连接标识符. 这是SHOW PROCESSLIST语句的Id列中显示 ...

  2. JS获取粘贴内容

    http://classjs.com/2013/03/05/js%E8%8E%B7%E5%8F%96%E7%B2%98%E8%B4%B4%E5%86%85%E5%AE%B9/ 思路:在编辑环境中,粘贴 ...

  3. intellij idea2016

    注册server http://idea.imsxm.com

  4. python-001 第一个Python3.x程序 hello world

    我们可以使用以下命令来查看我们使用的Python版本: (d:\ProgramData\Anaconda3) C:\Users\Administrator.2016-20160920ET>pyt ...

  5. Oracle中的特殊判式

    Oracle中的特殊判式 除了逻辑运算之外,Oracle提供了一些特殊判式.这些判式可以用来生成更加复杂和灵活的查询条件.本节将着重介绍以下几种判式. Between: 取值范围 In: 集合成员测试 ...

  6. 机器学习基础-Logistic回归2

    随机梯度上升法--一次仅用一个样本点来更新回归系数(因为可以在新样本到来时对分类器进行增量式更新,因而属于在线学习算法) 梯度上升法在每次更新回归系统时都需要遍历整个数据集,该方法在处理100个左右的 ...

  7. [codevs3622] 假期(单调队列)

    传送门 首先考虑暴力做法,可以先求一遍前缀和 sum,然后ans = max(ans, sum[i] - sum[k]) (i - q <= k <= i - p) 但这个肯定会超时. 仔 ...

  8. 【2018 Multi-University Training Contest 1】

    01:https://www.cnblogs.com/myx12345/p/9362221.html 02:https://www.cnblogs.com/myx12345/p/9382267.htm ...

  9. AndroidUI的基本结构

    AndroidUI的基本结构 创建时间: 2013-9-13 11:05 更新时间: 2013-9-13 11:05

  10. express 写接口

    实例下载:百度云盘免密码 (): 指注释 一.准备工作 1.安装express npm install express -g npm install express-generator -g 2.初始 ...