Problem a
来源:互联网 发布:ppt柱状图显示数据 编辑:程序博客网 时间:2024/04/29 04:42
The input consists of T test cases. The number of test cases ) (T is given in the first line of the input. 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 N+3-rd line, the remaining test cases are listed in the same manner as above.
Output
The output should contain the minimum time in minutes to complete the moving, one per line.
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
102030
¢在经理给出的说明表格中,已经明确地描述了算法:
l(从房间30到50)和(从房间60到90)是允许的,因为没有占用公共的走廊;
l(从房间20到40)和(从房间31到80)是不允许的,因为要占用公共的走廊。
¢我们将每个房间之间的走廊作为一个统计单位,当所有的办公桌都搬运完成之后,看看这段走廊到底需要占用多少次?然后统计所有的走廊被占用的最大值max,这个值就是要单独安排的搬运次数,乘以10就是总的搬运时间。
¢该算法属于贪心算法,因为它尽可能使搬运办公桌同时进行,以便使单独安排的搬运次数最少。
int i, j;
int move[200];
int N; //搬运次数
//每次搬运的起点和终点
int from, to;
scanf("%d", &N);
memset(move, 0, sizeof(move));
for(i = 0; i < N; i++)
{
scanf("%d%d", &from, &to);
//将房间号映射为走廊号
from = (from - 1)/2;
to = (to - 1)/2;
//确保from<to,C++使用:swap(from,to)
if(from > to) {
int temp = from;
from = to;
to = temp;
}
//占用走廊情况
for(j = from; j <= to; j++)
move[j]++;
}
以下是Accept的代码:
#include<iostream>
#include<memory.h>using namespace std;
int main()
{
int i,n1,move[200];
int from,to,n;
cin>>n;
for(int i =0;i<n;++i)
{
memset(move,0,sizeof(move));
cin>>n1;
for(int p =0;p<n1;++p)
{
cin>>from>>to;
from = (from - 1)/2;
to = (to - 1)/2;
if(from > to)
{
swap(from,to);
}
for(int j = from;j<=to;++j)
{
move[j]++;
}
}
int max = 0;
for(int i1 = 0;i1<200;++i1)
{
if(move[i1] > max)
{
max = move[i1];
}
}
cout<<max*10<<endl;
}
}
0 0
- Problem A
- Problem A
- Problem A
- Problem A
- Problem A
- Problem A
- Problem A
- Problem A
- problem A
- Problem a
- Problem A
- Problem A
- Problem-A
- Problem A
- Problem A
- Problem A
- Problem A
- problem 1000: A+B problem
- c++ 纠正空格换行书写以及大写后输出
- 给定一个仅包含'A'-'Z'的字符串,表示成'kX'形式输出
- Win10如何安装MySQL5.7.11
- QT学习笔记(2)—信号与槽
- Android中设计模式--状态模式(将动作委托到当前状态,状态之间可以互相转换)
- Problem a
- CODE[VS] 1031素数环
- Angular中实现树形结构视图
- codevs 1992 聚会 最短路+SPFA优化+反向建边
- iOS-UITableView的增加、移除
- 201603232007
- java中代码执行顺序(静态代码块、构造函数)
- Cordys BOP 4.3流程实例监控及流程恢复、流程环节配置Method问题的分析处理
- RCC