1256: Nuclear Missile

题目描述

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值