BOJ 385

597人阅读 评论(0)

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

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：494840次
• 积分：8475
• 等级：
• 排名：第2378名
• 原创：359篇
• 转载：28篇
• 译文：0篇
• 评论：56条
最新评论