BOJ 385

Problem C. Vaccine
Description
On Christmas Eve, 2029, the unidentified "Apocalypse Virus" spreads and
plunges JA into a state of emergency in a chaos known as the "Lost
Christmas" incident. An international organization known as the GHQ
intervenes with martial law and restores order to JA at the cost of its
independence. GHQ takes the domination of JA by the monopolization of
the vaccines, which are the only known solution to prevent the spreading
of the fatal Apocalypse Virus.
However, where there is oppression, there is resistance. The armed NGO
“Undertakers” is such a resistance group that aims to liberate JA from the
GHQ. One of the members' task is to manufacture the Anti-Apocalypse-
Virus vaccines. Of course, the government GHQ won't give them the raw
material as the Undertakers is announced as a terroristic organization. So
they have to get the material on their own.
Just as the sources of the raw material they get are various, the material
should be purified. The process of purification for each portion of raw
material needs 2 steps IN THE FOLLOWING ORDER:
1. take a portion of raw material into machine A to heat it to
142.857℃.
2. take the portion of raw material into machine B to centrifugalize it .
And the problem comes: Undertakers has only one machine A and only
one machine B. The machine A is able to handle only one portion of
material at a time, so is the machine B. However, there are N portions of
raw material in all, and the time for heating them and for centrifugalizing
them differs. So how to make a proper plan to purify them to minimumize
the total time? You may assume that taking a portion into a machine or
taking a portion out from a machine cost no time.
Input
There are multiple cases, end by EOF.
For each case, the first line contains an integer N (1 <= N <= 1000), the
number of portions of raw material. Then N lines followed, each contains
two integers, time for heat the ith portion of material and for
centrifugalize it respectively.
Output
For each case, output one integer, the minimum total time for purifying
these portions of raw material.
Sample Input
2 3
5
4 3
5 8
5
9 2
4 10
6 8
3 5
Sample Output
11
33
Hint
Take the first example for explaining. The following process takes the
minimum time:
At the beginning, take the first portion of material into machine A.
At the 3rd minute, take out the first portion from machine A and take it
into machine B, and then take the second portion into machine A.
At the 7th minute, take out the second portion from machine A.
At the 8th minute, take out the first portion from machine B and take the
second portion into machine B.
At the 11th minute, take out the second portion from machine B

贪心的思路,利用排序不等式排序,然后求总时间。

#include<stdio.h>
#include<stdlib.h>
struct raw{
	int a,b;
}lis[1010];
int max(int a,int b){
	return a>b?a:b;
}
int cmp(const void * a,const void *b){
	struct raw *aa=(struct raw *)a;
	struct raw *bb=(struct raw *)b;
	if(aa->a+bb->b+max(aa->b,bb->a)>aa->b+bb->a+max(aa->a,bb->b))
		return 1;
	return 0;
}
int main(){
	int i,j,n;
	while(scanf("%d",&n)!=EOF){
		for(i=1;i<=n;i++){
			scanf("%d %d",&lis[i].a,&lis[i].b);
		}
		qsort(&lis[1],n,sizeof(lis[1]),cmp);
		int s=0,t=0;       //这里s记录上一过程中A机器运行结束时间,t记录上一过程中B机器运行结束时间
		for(i=1;i<=n;i++){
			if(s+lis[i].a>t)
				t=s+lis[i].a;
			s+=lis[i].a;
			t+=lis[i].b;
		}
		printf("%d\n",t);
	}
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值