sicily 1193. Up the Stairs
Time Limit: 1sec Memory Limit:32MB
Description
John is moving to the penthouse of a tall sky-scraper. He packed all his stuff in boxes and drove them to the entrance of the building on the ground floor. Unfortunately the elevator is out of order, so the boxes have to be moved up the stairs.
Luckily John has a lot of friends that want to help carrying his boxes up. They all walk the stairway at the same speed of 1 floor per minute, regardless of whether they carry a box or not. The stairway however is so narrow that two persons can't pass each other on it. Therefore they deciced to do the following: someone with a box in his hands is always moving up and someone empty-handed is always moving down. When two persons meet each other somewhere on the stairway, the lower one (with a box) hands it over to the higher one (without a box). (And then the lower one walks down again and the higher one walks up.) The box exchange is instantaneous. When someone is back on the ground floor, he picks up a box and starts walking up. When someone is at the penthouse, he drops the box and walks down again. After a while the persons are scattered across the stairway, some of them with boxes in their hands and some without. There are still a number of boxes on the ground floor and John is wondering how much more time it will take before all the boxes are up. Help him to find out! Input
One line with a positive number: the number of test cases. Then for each test case:
Output
One line with the amount of time (in minutes) it will take to get all the remaining boxes to the penthouse.
Sample Input
aaarticlea/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAARABIDASIAAhEBAxEB/8QAGAABAAMBAAAAAAAAAAAAAAAAAAMFBwT/xAAlEAACAQQCAQMFAAAAAAAAAAABAgMABAURBiESIjFBMjZxdbP/xAAYAQACAwAAAAAAAAAAAAAAAAAAAwEEBf/EABsRAQEAAgMBAAAAAAAAAAAAAAEAAgMEEyFh/9oADAMBAAIRAxEAPwDQeRW+SyVnctBIkiiScOk87qm0ciP0aZWA8dkEDZA2fcGPCWPI+PXkUt3GIcQjkyQxTGdtMrAhUVQO5CraVd/UB1pa7cnHmbaW5hjxEktoZJJGulnjChWYsT4lvLoHvr3B1vommvuQYaSe/jGSxrW9yXEiCWIiTe9eWohvs/LH8n5ocDh9jlnsER+zt+9wDE9G0uKWO4hSaGRJIpFDI6MCrKewQR7ilVfFPs7B/r4P5rStB8ZJW9KUqIlKUoi//9k=" alt="" /> Copy sample input to clipboard
2 Sample Output
30 |
首先这个可以看成一组人在移动,因为它的交换物品与方向跟没交换的效果是一样的。
另外考虑的就是,搬一个新的物品比已经在楼梯上的人来说它的速度总是更慢的。所以在搬运期间,还没到最后一趟的时候,大家搬运的个数是一样的,所以可以用 (boxNum / personNum - ) * 来计算在这期间的时间,剩下的就是初始状态在楼梯上和最后一趟的时间的考虑了。
#include <iostream>
#include <algorithm> using namespace std; int main(int argc, char const *argv[])
{
int testCase, personNum, floorNum, boxNum, floor, cally;
int person[];
cin >> testCase;
while (testCase--) {
cin >> personNum >> floorNum >> boxNum; for (int i = ; i != personNum; ++i) {
cin >> floor >> cally;
if (cally == )
person[i] = floorNum + floor;
else
person[i] = floorNum * - floor;
} sort(person, person + personNum); int remain = boxNum % personNum;
int minute = ;
if (remain == ) {
minute = (boxNum / personNum - ) * * floorNum + person[personNum - ]; // 上到顶端就不需要再下来了,所以 -1
} else {
minute = (boxNum / personNum) * * floorNum + person[remain - ]; // 上到顶端后还需要下来搬运剩下的
} cout << minute << endl;
}
return ;
}
sicily 1193. Up the Stairs的更多相关文章
- [LeetCode] Climbing Stairs 爬梯子问题
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- [LintCode] Climbing Stairs 爬梯子问题
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- Leetcode: climbing stairs
July 28, 2015 Problem statement: You are climbing a stair case. It takes n steps to reach to the top ...
- sicily 中缀表达式转后缀表达式
题目描述 将中缀表达式(infix expression)转换为后缀表达式(postfix expression).假设中缀表达式中的操作数均以单个英文字母表示,且其中只包含左括号'(',右括号‘)’ ...
- sicily 1934. 移动小球
Description 你有一些小球,从左到右依次编号为1,2,3,...,n. 你可以执行两种指令(1或者2).其中, 1 X Y表示把小球X移动到小球Y的左边, 2 X Y表示把小球X移动到小球Y ...
- LintCode Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- 54. Search a 2D Matrix && Climbing Stairs (Easy)
Search a 2D Matrix Write an efficient algorithm that searches for a value in an m x n matrix. This m ...
- Climbing Stairs
Climbing Stairs https://leetcode.com/problems/climbing-stairs/ You are climbing a stair case. It tak ...
- bzoj 1193 贪心
如果两点的曼哈顿距离在一定范围内时我们直接暴力搜索就可以得到答案,那么开始贪心的跳,判断两点横纵坐标的差值,差值大的方向条2,小的条1,不断做,直到曼哈顿距离较小时可以暴力求解. 备注:开始想的是确定 ...
随机推荐
- python的N个小功能(文件内容的匹配替换)
# -*- coding: utf-8 -*- """ Created on Fri Feb 17 20:25:05 2017 @author: who "&q ...
- EVE-NG FAQ
EVE-NG FAQ How to install EVE on bare box using Ubuntuoriginal ISO distro. Get Ubuntu ISO: https://w ...
- codeforces765F Souvenirs
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...
- Hadoop1重新格式化HDFS
注意:原来的数据全部被清空了.产生了一个新的hdfs 1. 删除已有目录 1.1 查看hdfs-site.xml 将 dfs.name.dir和dfs.data.dir所指定的目录删除 vim hdf ...
- Python之旅:装饰器
装饰器就是闭包函数的一种应用场景 一.为何要用装饰器 开放封闭原则:软件一旦上线后,就应该遵循开放封闭原则,即对修改源代码是封闭的,对功能的扩展是开放的 也就是说我们必须找到一种解决方案:能够在不修该 ...
- Listener 介绍
当 web 应用在 web 容器中运行时,web 应用内部会不断地发生各种事件:如 web 应用启动.web 应用停止,用户 session 开始.用户 session 结束.用户请求到达等. 实际上 ...
- windows下安装pthreads扩展注意问题
1.php版本必须是ts版本 2.pthreads扩展下载地址 http://windows.php.net/downloads/pecl/releases/pthreads/ 3.把下载的扩展php ...
- json&pickle序列化
一.用途 我们需要将内存中的数据进行序列化,即写入文件中时,写入的类型只能是字符串或者二进制类型.但是如果我们想要将复杂一些的数据类型,如:列表.字典或者函数之类的同样进行序列化,我们就要用到 jso ...
- javaFX8初探(环境搭建)
1:下载java8 Oracle官网2:下载eclipse4.4 eclipse官网3:安装e(fx)clipse插件 http://download.eclipse.org/efxclipse/u ...
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is defined
请检查你在web.xml中加载spring.xml文件的时候没有加载成功,看你的路径是否正确 <context-param> <param-name>contextConfi ...