BOJ 385

原创 2012年03月25日 13:30:51

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题目1023. Ancient Keyboard 源代码

  • 2012年10月08日 10:36
  • 561B
  • 下载

boj 0809复试模拟题答案

  • 2010年04月22日 16:18
  • 853KB
  • 下载

LeetCode 394. Decode String LeetCode 385. Mini Parser

题目链接:https://leetcode.com/problems/decode-string/ 题目描述: The encoding rule is: k[encoded_string], w...

MS90C385电子文件

  • 2015年07月17日 09:32
  • 68KB
  • 下载

LeetCode:385. Mini Parser

LeetCode:385. Mini ParserGiven a nested list of integers represented as a string, implement a parser...
  • Wisimer
  • Wisimer
  • 2016年08月20日 09:01
  • 277

Codeforces Round #385 (Div. 2) B. Hongcow Solves A Puzzle

题意: 给你两个相同的拼图,每个拼图里的X都只能整体水平竖直移动,不能旋转,问你通过整体移动能不能让这两块拼图的X组成一个矩形(中间不能为空)。 思路: 因为每个拼图内部的X不能移动,所以要想拼...
  • CillyB
  • CillyB
  • 2016年12月18日 11:47
  • 299

385高校毕业设计选题

泰州学院计算机毕业设计选题参考表.doc http://dl.vmall.com/c0d3cpga24 历年南阳医学高等专科学校计算机毕业设计选题.doc http://dl.vmall.com...

CodeForces 385D Bear and Floodlight

题意: 从坐标(L,0)到坐标(R,0)直线行走  走过的地方必须被N盏灯里的至少1盏照亮  每盏灯有一个位置坐标  照亮方向任意且可照亮无限远  但只有一个固定的照明角度  求最远走多远 思路:...

Codeforces Round #385 (Div. 2) B. Hongcow Solves A Puzzle 几何、思维题

题意:那个由x构成的图片可以平移但不能翻转,问2个一样的图片分别经过以后能否构成一个矩形。 几何、思维题 其实就是判断所给的X构成的图形是否本身是矩形,因为只有这样才能在不翻转的情况下拼出一个矩形。 ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:BOJ 385
举报原因:
原因补充:

(最多只允许输入30个字)