水题练手POJ1083

POJ1083

import java.util.Scanner;

public class _1083 {
public static final int MAX = 400;

public static void main(String[] args) {
int from, to, max_time;
int times[] = new int[MAX + 1];
Scanner sc = new Scanner(System.in);
int count = sc.nextInt();

while (count-->0) {

for (int j = 1; j <= MAX; j++)
times[j] = 0;

int num = sc.nextInt();
int i = 0, tmp;

while (i++ < num) {

from = sc.nextInt();
to = sc.nextInt();

if (from > to) {
tmp = from;
from = to;
to = tmp;
}
if ((from & 1) == 0)
from--;
if ((to & 1) != 0)
to++;

for (int j = from; j <= to; j++)
times[j]++;
}
max_time = times[1];
for (int j = 2; j <= MAX; j++) {
if (times[j] > max_time)
max_time = times[j];
}
System.out.println(max_time * 10);
}
}
}

小结:

1.不要求得到具体搬运决策而只需知道总时间,用一个走廊次数的数组表明使用情况,最终的时间就是次数的最大值*10分钟;

2.将from>to规约到from<to的情形;

3.对偶数from和奇数to的特殊处理方式(在这里考虑的是例如1,2;3,4和2,3;4,5不同的情况)。

转载于:https://www.cnblogs.com/leftcopy/archive/2012/03/06/2382783.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值