题目描述
Country Uranux wants to launch its new nuclear missile recently.
There are 3 types of missiles that Uranux has developed successful:
Name: Juno Price per unit: 120millionRange:450kmName:PoseidonPriceperunit: 600million Range: 1100km
Name: Apollo Price per unit: $3.5billion Range: 4500km
There are some targets Uranux wants to destory, If the distance between Uranux and target is in range of a type of missile, then Uranux can use one unit of this type to destory it. Uranux needs to destory all targets, but Uranux’s commander wants to make the cost minimum. Can you give a solution?
输入
Muiltple sets of input.
In one set of input, the first line contains a integer N (N <= 100), which means the count of targets Uranux need to destory. The next line contain N integers indicate the distance (0 <= x < 2^31) between each target and Uranux (Unit: km).
输出
Output the battle plan contains missile type and count(order: Juno, Poseidon, Apollo), total cost(unit: $million), if mission impossible, output “Mission impossible!”. See sample for more details.
样例输入
3
100 2000 500
4
400 400 400 4500
2
1500 4499
1
1000
1
5000
样例输出
Case 1:
1 Juno, 1 Poseidon, 1 Apollo. Total cost: 4220million.Case2:3Juno,1Apollo.Totalcost: 3860million.
Case 3:
2 Apollo. Total cost: 7000million.Case4:1Poseidon.Totalcost: 600million.
Case 5:
Mission impossible!
解答
#include<stdio.h>
int main()
{
int N,a,b,c,d;
long x,n=1;
while(scanf("%d",&N)!=EOF)
{
a=0;b=0;c=0;d=0;
while(N--)
{
scanf("%ld",&x);
if(x<=450) a++;
else if(x<=1100) b++;
else if(x<=4500) c++;
else d++;
}
printf("Case %ld:\n",n);
if(d>0) {printf("Mission impossible!\n");n++;continue;}
if(a>0) N++;
if(b>0) N++;
if(c>0) N++;
if(a>0) {printf("%d Juno",a);N--;if(N>=0) printf(", ");else printf(". ");}
if(b>0) {printf("%d Poseidon",b);N--;if(N>=0) printf(", ");else printf(". ");}
if(c>0) printf("%d Apollo. ",c);
x=a*120+b*600+c*3500;
printf("Total cost: $%ldmillion.\n",x);
n++;
}
return 0;
}