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);
	}
}


 

斯坦福大学秋季课程《深度学习理论》STATS 385开讲

转载:http://mp.weixin.qq.com/s?timestamp=1510210312&src=3&ver=1&signature=qmn1IsRtGkSXORGKr9DZzJ8ttsqr...
  • feng98ren
  • feng98ren
  • 2017年11月09日 16:09
  • 145

设备树那些事

四 中断 中断一般包括中断产生设备和中断处理设备。中断控制器负责处理中断,每一个中断都有对应的中断号及触发条件。中断产生设备可能有多个中断源,有时多个中断源对应中断控制器中的一个中断,这种情况中断产...
  • qq84395064
  • qq84395064
  • 2017年12月21日 17:26
  • 18

385高校毕业设计选题

泰州学院计算机毕业设计选题参考表.doc http://dl.vmall.com/c0d3cpga24 历年南阳医学高等专科学校计算机毕业设计选题.doc http://dl.vmall.com...
  • u013638614
  • u013638614
  • 2014年02月19日 00:49
  • 1398

BOJ 446 大神题

题意:给出一个长度为n的整数序列,和一个数m,有两种操作:1.求出给定区间上...
  • u012139398
  • u012139398
  • 2014年08月02日 22:15
  • 333

BOJ 4358 左手定则

题目链接~~> 做题感悟:这题开始时没想出来什么好办法,但是某个瞬间灵感爆发想到用方向做第三维标记这样就很轻松解决了。 解题思路:用方向做第三维标记看是否重复走,只要发现重复走就结束。 代码: ...
  • u011074149
  • u011074149
  • 2014年03月28日 18:31
  • 408

BOJ 4228 哈哈哈

题目链接~~> 做题感悟:这题一看就知道要用状态压缩,本题和HDU 1429 胜利大逃亡(续)差不多。 解题思路:你可以把宝物压缩为二进制,例如:01001 代表你已经拿过 1 号和 4 号宝物了 0...
  • u011074149
  • u011074149
  • 2014年04月01日 16:05
  • 435

BOJ 469. 暑假作业题

题意:给出一个数,输出中文读法 思路:巨坑的模拟题
  • u012139398
  • u012139398
  • 2014年08月02日 21:27
  • 356

BOJ 477. 新来的小妹妹

题意:给出一个字符串,找出其中出现次数大于等于2次且最长的连续子串;
  • u012139398
  • u012139398
  • 2014年08月02日 20:36
  • 276

老BOJ 16 棋盘分割

//DP枚举,注意输出用%f不可以用%lf #include #include #include #include #include #include #define ll long long #de...
  • u012662688
  • u012662688
  • 2014年08月03日 00:39
  • 462

BOJ 451 田田的算术题

题意:给出一个数列。有两个
  • u012139398
  • u012139398
  • 2014年08月02日 20:54
  • 376
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:BOJ 385
举报原因:
原因补充:

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