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,不断做,直到曼哈顿距离较小时可以暴力求解. 备注:开始想的是确定 ...
随机推荐
- Arrays.toString 如果传入的是对象 那么调用的是此对象的toString
Arrays.toString(Object[] obj) 如果传入参数的是对象 那么调用的是此对象的toString
- (转)Linux GCC常用命令
1简介 2简单编译 2.1预处理 2.2编译为汇编代码(Compilation) 2.3汇编(Assembly) 2.4连接(Linking) 3多个程序文件的编译 4检错 5库文件连接 5.1编译成 ...
- java学习5-jar包的下载以及导入
1.出现未导入包的情况 ,表示当前jdk不 2.百度下载jar包 3.File. 未完待续http://blog.csdn.net/a153375250/article/details/5085104 ...
- 【刷题】BZOJ 3926 [Zjoi2015]诸神眷顾的幻想乡
Description 幽香是全幻想乡里最受人欢迎的萌妹子,这天,是幽香的2600岁生日,无数幽香的粉丝到了幽香家门前的太阳花田上来为幽香庆祝生日. 粉丝们非常热情,自发组织表演了一系列节目给幽香看. ...
- 【读书笔记】《HTTP权威指南》:Web Hosting
一.概述 从零开始构建一个真正意义的网站需要做很多事情,包括购买计算机硬件.建造机房.注册域名.购买网络带宽.开发Web服务器软件.管理网站内容等等.在互联网发展的早期,构建网站的这一系列动作通常都是 ...
- 【agc012E】Camel and Oases
Portal --> agc012 Description 有一排点,两点间有一定距离,初始的时候有一个行走值\(v\),如果说两点间距离不超过\(v\),那么可以在这两点间自由行走,如果当前\ ...
- 【hdu6051】If the starlight never fade
Portal --> hdu6051 Solution 神仙题qwq好吧我个人感觉是神仙题 这题其实有一个比较野路子的做法..就是..打表观察..反正场上ckw大佬就是这样把这题A穿的 ...
- python基础----__next__和__iter__实现迭代器协议
#_*_coding:utf-8_*_ __author__ = 'Linhaifeng' class Foo: def __init__(self,x): self.x=x def __iter__ ...
- 框架----Django之Ajax全套实例(原生AJAX,jQuery Ajax,“伪”AJAX,JSONP,CORS)
一.原生AJAX,jQuery Ajax,“伪”AJAX,JSONP 1. 浏览器访问 http://127.0.0.1:8000/index/ http://127.0.0.1:8000/fake_ ...
- 「PLC」PLC的硬件与工作原理