BOJ 385
来源:互联网 发布:mac无u盘安装win10 编辑:程序博客网 时间:2024/05/21 22:47
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);}}
- BOJ 385
- BOJ 288
- BOJ 394
- BOJ 396
- BOJ 519
- BOJ 93
- BOJ 204
- BOJ 672
- BOJ 1454
- BOJ 387
- BOJ 652
- BOJ 1452
- BOJ 1461
- BOJ 1450
- boj contest, C++
- boj 215(树形DP)
- boj 212(栈模拟)
- o.boj 1022 Steps
- 杭电1251 统计难题 字典树的应用
- WIn7修复开机引导解决无法正常启动
- C++中static_cast、const_cast、reinterpret_cast的用法举例,附带举例说明强制类型转换时int和int&的区别
- 演化算法(一) 基本概念
- 颜色空间,图像格式,彩色转灰度函数
- BOJ 385
- Warning: The Copy Bundle Resources build phase
- OUTLOOK错误代码
- GeekOS project2--自己做project2的流程遇到的问题及解决
- NSData to base64Encoding
- redhat或centos下用yum安装(卸载)KDE和GNOME
- 图片里面存放其他文件的方法
- Code Sign error
- php编程技巧