nyoj220 推桌子(贪心算法)
这道题太坑了,from 和to有可能写反,还得正过来;
推桌子
- 描述
- 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 推桌子(贪心算法)的更多相关文章
- nyoj 220——推桌子——————【贪心】
推桌子 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 The famous ACM (Advanced Computer Maker) Company has re ...
- 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 ...
- nyist 220 推桌子
题目链接:推桌子 题目意思:给你一些操作,将S出的桌子推到L出,但是这个过道有时会被占用,推一次是10min,不影响的操作可以同时开始,并且只记一次. 思路:贪心,首先按照S从小到大排序,决策:从第一 ...
- js算法初窥05(算法模式02-动态规划与贪心算法)
在前面的文章中(js算法初窥02(排序算法02-归并.快速以及堆排)我们学习了如何用分治法来实现归并排序,那么动态规划跟分治法有点类似,但是分治法是把问题分解成互相独立的子问题,最后组合它们的结果,而 ...
- poj_1042 贪心算法
poj 1042 gone fishing 题目要求: 由有n个湖, 按照顺序排列,一个人从第一个湖向最后一个湖行进(方向只能从湖0到湖n-1),途中可以在湖中钓鱼.在每个湖中钓鱼时,开始的5分钟内可 ...
- 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 ...
- 贪心算法和动态规划[zz]
http://www.cnblogs.com/asuran/archive/2010/01/26/1656399.html 贪心算法 1.贪心选择性质 所谓贪心选择性质是指所求问题的整体最优解可以通过 ...
- python常用算法(6)——贪心算法,欧几里得算法
1,贪心算法 贪心算法(又称贪婪算法)是指,在对问题求解时,总是做出在当前看来是最好的选择.也就是说,不从整体最优上加以考虑,他所做出的的时在某种意义上的局部最优解. 贪心算法并不保证会得到最优解,但 ...
- 二叉树遍历问题、时间空间复杂度、淘汰策略算法、lru数据结构、动态规划贪心算法
二叉树的前序遍历.中序遍历.后序遍历 前序遍历 遍历顺序规则为[根左右] ABCDEFGHK 中序遍历 遍历顺序规则为[左根右] BDCAEHGKF 后序遍历 遍历顺序规则为[左右根] DCBHKGF ...
随机推荐
- [Django]模型学习记录篇--基础
模型学习记录篇,仅仅自己学习时做的记录!!! 实现模型变更的三个步骤: 修改你的模型(在models.py文件中). 运行python manage.py makemigrations ,为这些修改创 ...
- FeWeb基础之HTML
FeWeb基础之HTML 1.HTML简介 HTML是一种超文本标记语言,它的文件扩展名为.html,它的所有部分都是由标记<...>和标记</...>包括起来. 在一个HTM ...
- (转)Doxygen文档生成工具
http://blog.csdn.net/lostaway/article/details/6446786 Doxygen 是一个支持 C/C++,以及其它多种语言的跨平台文档生成工具.如同 Java ...
- 在github上建立自己的网站
学了前端小半年,如今写了个自己的网页想要去应聘,却发现部署很麻烦,部署到阿里云之类,买域名啊啥的还要收费,说贵也不贵,但我就是傲娇~ google一下了解到Github有一个Github pages的 ...
- java1.8常用的函数式接口
//常用函数式接口 final ; //num++; //第一个为传入参数的类型:第二个为返回数据的类型 Function<int[],String> function = (from) ...
- Linux编译安装源码包的流程
流程: 1. 下载并解压源码包2. 运行:configure3. 编译:make4. 安装:make install 编译时需要注意一个原则:不要在解压的包中直接执行./configure.m ...
- 适配iOS10的哪些事 ---- 学习笔记八
一. 上传了一个版本,为什么没有构建版本? 解:info.plist中的Bundle version 与上一个版本一致或少于上一个版本,上线新版本时,Bundle version和Bundle ... ...
- (原创)JAVA多线程二线程池
一,线程池的介绍 线程池包括一下三种: 线程池名称 创建方法 特点 其他 固定大小线程池 ExecutorService threadpool = Executors.newFixedThreadPo ...
- 几个ES6新特性
ES6是JavaScript语言的下一代标准,已经在2015年6月正式发布了,因为ES6的第一个版本是在2015年发布的,所以又称ECMAScript 2015(简称ES2015).本文主要讲述的是E ...
- Macbook被格式化之后
macbook不小心被手贱格式化了,开机显示一个大问号. 于是查询得到恢复方式是使用command+R. 照做了,试了好几次,那个地球还是卡住不动的.都没有提示让我输入wifi密码. 于是又查了一下, ...