B - Moving Tables
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d
& %I64u
Description
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
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
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一直WA,查不出来,,,,后来偶然看到我的for循环是i《begin;i!=end;i++。。。。哎,平常写的手顺了,应该是〈=。下回要特别注意。附上25行代码:my answer:#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int T,n;
cin>>T;
while(T--)
{
scanf("%d",&n);
int m=0,begin,end, sum[500]={0};
for(int i=0;i!=n;i++){
cin>>begin>>end;
begin = (begin - 1)/2;
end = (end - 1 )/2;
if(begin >end )swap(begin ,end );
if(m<end)m=end;
for(int j=begin;j<=end;j++)
sum[j]+=10;
}
printf("%d\n",*max_element(sum,sum+m));
}
return 0;
}有一点就是房间是要分奇偶的,上面那个有点不理解为啥要减一除以2.下面是我的代码:
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int T,n;
cin>>T;
while(T--)
{
scanf("%d",&n);
int m=0,begin,end, sum[500]={0};
for(int i=0;i!=n;i++){
cin>>begin>>end;
if(begin >end )swap(begin ,end );
if(end%2!=0) end++;
if(m<end)m=end;
for(int j=begin;j<=end;j++)
sum[j]+=10;
}
printf("%d\n",*max_element(sum,sum+m));
}
return 0;
}
B - Moving Tables的更多相关文章
- zstu.2512. Moving Tables(贪心)
Moving Tables Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1182 Solved: 563 Description The famo ...
- Moving Tables(贪心或Dp POJ1083)
Moving Tables Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28304 Accepted: 9446 De ...
- HDOJ 1050 Moving Tables
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 1050 Moving Tables
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- Moving Tables
Moving Tables Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- hdoj 1050 Moving Tables【贪心区间覆盖】
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- uvalive 2326 - Moving Tables(区间覆盖问题)
题目连接:2326 - Moving Tables 题目大意:在一个走廊上有400个教室, 先在有一些桌子要移动, 每次移动需要十分钟, 但是不同房间的桌子可以在同一个十分钟内移动,只要走廊没有被占用 ...
- HDU1050(Moving Tables:贪心算法)
解题思路: 这种做法是基于hdu2037的做法上考虑的,找出所有可以同时搬运的桌子,然后就很方便求出最短总时间. 还有一种更简单的做法是直接遍历一遍找出与别的重复次数最多的那片区域,重复次数*10就可 ...
- POJ1083 Moving Tables
POJ1083 Moving Tables Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 35297 Accepted: ...
随机推荐
- Mantis 1.1.0 报告问题中设置必填项或取消必填项[Z]
打开/mantis/core/bug_api.php,其中有类似下面的语句 if ( is_blank( $c_summary ) ) { error_parameters( lang_get( ...
- iOS-NSAttributedString自定义文字变色
1.使用注意: 1.给UILabel设置attributedText了会导致给UILabel中text,font,textColor,shadowColor,shadowOffset,textAlig ...
- 灵光一闪-VS设计界面能访问到private修饰的各种控件
大家都知道,用VS设计界面时,VS默认控件的访问修饰符为private,但是我就很奇怪,private修饰的字段不是只有类内部才能访问吗? 好神奇的VS,这到底是怎么实现的?难道就是类似文本编辑器的作 ...
- 精读《javascript高级程序设计》笔记一——基本概念
语法 严格模式 启用严格模式,在脚本顶部或函数内部上方添加"use strict";语句. 数据类型 typeof typeof返回undifined,boolean,number ...
- 你的阅读造就了你 You are what you read
在豆瓣上看到的一篇很有思想和正能量的文章,在这里请允许我用原创的方式来呈现给大家.如果你是在校的大学生或者研究生博士生,这篇文章会让你有很多的共鸣.如果你已真正的踏入这个社会,也将受益匪浅. 电脑 ...
- [LeetCode]题解(python):010-Regular Expression Matching
题目来源: https://leetcode.com/problems/regular-expression-matching/ 题意分析: 这道题目定义了两个正则表达式规则.’.’代表任意字符,’* ...
- Probability theory
1.Probability mass functions (pmf) and Probability density functions (pdf) pmf 和 pdf 类似,但不同之处在于所适用的分 ...
- 全角和半角相互转换(C语言实现)
目前,我们接触的汉字编码主要包括GBK和GB2312.其中,GB2312又称国标码,它是一个简化字的编码规范,也包括其他的符号.字母.日文假名等,共7445个图形字符,其中汉字占6763个.我们平时说 ...
- OSG中的视角 eye up center
这三个值都是vec3变量,其中eye和center确定视角 eye就相当于人的眼睛,我们观察场景,是从这个坐标去看的,然后有了眼睛,我们观察得有一个方向,那么久需要另外一个坐标,就是c ...
- 無塵室(Clean Room)的級數標準規格
無塵室又稱潔淨室,是將一定空間範圍內空氣的微塵粒子.有害氣體.細菌等之污染物控制在一定的數量內.無塵室的等級是以一立方英呎含有多少大於0.5um的微塵粒子來定義的.下表是根據「美國聯邦標準209D規格 ...