这道题太坑了,from 和to有可能写反,还得正过来;

推桌子

时间限制:1000 ms  |  内存限制:65535 KB
难度:3
 
描述
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.
 
输入
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.
输出
The output should contain the minimum time in minutes to complete the moving, one per line.
样例输入
3
4
10 20
30 40
50 60
70 80
2
1 3
2 200
3
10 100
20 80
30 50
样例输出
10
20
30
上传者

这个思路非常好

#include <stdio.h>
#include <string.h>
int move[];
int main()
{
freopen("250.txt","r",stdin);
int T,i,j,table,ans,from,to,tmp;
scanf("%d",&T);
do
{
scanf("%d",&table);
memset(move,,sizeof(move));
for(j = ; j < table ; ++j)
{
scanf("%d%d",&from,&to);
from = (from+)>>;
to = (to +)>>;
if(from > to)
{
tmp = from ;
from = to ;
to = tmp;
}
for(i = from ; i <= to ; ++i)
++move[i];
}
ans = ;
for(i = ;i <= ; ++i)
if(move[i] > ans)
ans = move[i];
printf("%d\n",ans*); }while(--T); return ;
}

nyoj220 推桌子(贪心算法)的更多相关文章

  1. nyoj 220——推桌子——————【贪心】

    推桌子 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 The famous ACM (Advanced Computer Maker) Company has re ...

  2. LEETCODE —— Best Time to Buy and Sell Stock II [贪心算法]

    Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price of a ...

  3. nyist 220 推桌子

    题目链接:推桌子 题目意思:给你一些操作,将S出的桌子推到L出,但是这个过道有时会被占用,推一次是10min,不影响的操作可以同时开始,并且只记一次. 思路:贪心,首先按照S从小到大排序,决策:从第一 ...

  4. js算法初窥05(算法模式02-动态规划与贪心算法)

    在前面的文章中(js算法初窥02(排序算法02-归并.快速以及堆排)我们学习了如何用分治法来实现归并排序,那么动态规划跟分治法有点类似,但是分治法是把问题分解成互相独立的子问题,最后组合它们的结果,而 ...

  5. poj_1042 贪心算法

    poj 1042 gone fishing 题目要求: 由有n个湖, 按照顺序排列,一个人从第一个湖向最后一个湖行进(方向只能从湖0到湖n-1),途中可以在湖中钓鱼.在每个湖中钓鱼时,开始的5分钟内可 ...

  6. Algorithm - 贪心算法使用场景 ( LEETCODE —— Best Time to Buy and Sell Stock II)

    先看一道leetcode题: Best Time to Buy and Sell Stock II Say you have an array for which the ith element is ...

  7. 贪心算法和动态规划[zz]

    http://www.cnblogs.com/asuran/archive/2010/01/26/1656399.html 贪心算法 1.贪心选择性质 所谓贪心选择性质是指所求问题的整体最优解可以通过 ...

  8. python常用算法(6)——贪心算法,欧几里得算法

    1,贪心算法 贪心算法(又称贪婪算法)是指,在对问题求解时,总是做出在当前看来是最好的选择.也就是说,不从整体最优上加以考虑,他所做出的的时在某种意义上的局部最优解. 贪心算法并不保证会得到最优解,但 ...

  9. 二叉树遍历问题、时间空间复杂度、淘汰策略算法、lru数据结构、动态规划贪心算法

    二叉树的前序遍历.中序遍历.后序遍历 前序遍历 遍历顺序规则为[根左右] ABCDEFGHK 中序遍历 遍历顺序规则为[左根右] BDCAEHGKF 后序遍历 遍历顺序规则为[左右根] DCBHKGF ...

随机推荐

  1. Media Queries 详解

    Media Queries直译过来就是“媒体查询”,在我们平时的Web页面中head部分常看到这样的一段代码:  <link href="css/reset.css" rel ...

  2. [Django]模型学习记录篇--基础

    模型学习记录篇,仅仅自己学习时做的记录!!! 实现模型变更的三个步骤: 修改你的模型(在models.py文件中). 运行python manage.py makemigrations ,为这些修改创 ...

  3. 【Python数据分析】工作日发文章比周末发文章访问量高?

    前言 看前面有位朋友分析了一下每天某个时间发文章的访问量区别,以讨论非系统性因素对文章访问量的影响.之所以进一步讨论工作日和周末发文对文章访问量的影响,一是觉得很有意思,二是毕业设计与此有很大关系,三 ...

  4. HDU1890 Robotic Sort[splay 序列]

    Robotic Sort Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  5. [bzoj1013][JSOI2008][球形空间产生器sphere] (高斯消元)

    Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球 面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧 ...

  6. 鼠标/手指相对于元素的坐标(px转百分比)

    鼠标/手指相对于元素的坐标:鼠标或手指当前的位置 - 元素距离文档的位置 px转百分比:px / 文档尺寸 * 100 获取手指触摸在屏幕中相对于元素的坐标(px转百分比): $('#div').on ...

  7. Linux 进程间通讯详解六

    ftok()函数 key_t ftok(const char *pathname, int proj_id); --功能:创建系统建立IPC通讯 (消息队列.信号量和共享内存) 时key值 --参数 ...

  8. 软件工程导论-目录-K-T+RJ大

    目录 10 第1章 软件工程学概述/1 19 1.1 软件危机/1 19 1.1.1 软件危机的介绍/1 19 1.1.2 产生软件危机的原因/3 21 1.1.3 消除软件危机的途径/4 22 1. ...

  9. [转载]jQuery中wrap、wrapAll和wrapInner用法以及区别

    原文地址:jQuery中wrap.wrapAll和wrapInner用法以及区别作者:伊少君 原文: <ul>   <li title='苹果'>苹果</li>   ...

  10. 屏蔽防止被别的网站嵌入框架代码(防止被人frame)

    <SCRIPT LANGUAGE=javascript> if (top.location != self.location)top.location=self.location; < ...