zoukankan      html  css  js  c++  java
  • sicily 1636. show me the money

    Description
    Fakosh like playing the game "StarCraft".  However, he is not so good at this game that he can't beat the AI. For victory, he typed "show me the money" to cheat, and then he would get some money in the game. Now he can build more powerful cannons and make more strong soldiers with the money. But maybe the money is not enough, so he wants to know the amount of the money left.

    Input
    The first line of the input is an integer T, the number of test cases.
    In each test case, the first line is the money M(1<=M<=1000) that Fakosh would get after he typed "show me the money", and N(1<=N<=5), the number of kinds of the cannons or soldiers he would like to make. Each of the next N lines will contain two integers Ai(1<=Ai<=100) and Bi(1<=Bi<=5). Ai is the price of the cannon or soldier, Bi is the number of the cannon or soldier of this kind he would like to make.

    Output
    For each test case, if the money is not enough, output "Not enough", or else output the amount of the money left, in one line.

    这个题目简直充满槽点………………就算没玩过星际争霸只要玩过即时战略的都不会陌生,捶地

    题目本身很水,不过输入有点多看起来有点混乱,注释如下

    (不够的话其实再输一次秘技不就行了嘛哦呵呵呵呵呵呵)

    一次AC

    View Code
     1 #include<stdio.h>
     2 #define MAX 5
     3 
     4 int left( int cheat, int kind, const int price[], const int num[] );
     5 
     6 int main()
     7 {
     8     int t;
     9     int m, n;
    10     int a[MAX] = {0};
    11     int b[MAX] = {0};
    12     int i, j;
    13     int money;
    14     
    15     scanf( "%d", &t );
    16     
    17     for ( i = 0; i < t; i++ )
    18     {
    19         scanf( "%d %d", &m, &n );
    20         
    21         for ( j = 0; j < n; j++ )
    22         {
    23             scanf( "%d %d", &a[j], &b[j]);
    24         }
    25         
    26         money = left( m, n, a, b );
    27         
    28         if ( money == -1 )
    29         {
    30             printf( "Not enough\n" );
    31         }
    32         else
    33         {
    34             printf( "%d\n", money );
    35         }
    36     }
    37     
    38     return 0;
    39 }
    40 
    41 int left( int cheat, int kind, const int price[], const int num[] )
    42 {
    43     int i;
    44     
    45     for ( i = 0; i < kind; i++ )
    46     {
    47         cheat -= price[i] * num[i];
    48         
    49         if ( cheat < 0 )
    50         {
    51             return -1;
    52         }
    53     }
    54     
    55     return cheat;
    56 }
  • 相关阅读:
    安卓adb
    图数据库学习
    分布式架构演进
    多活架构
    异地多活
    分布式CRDT
    技术架构的战略和战术原则
    分布式金融架构课笔记
    使用jackson进行json序列化时进行敏感字段脱敏(加密)或者忽略
    读书笔记《演进式架构》
  • 原文地址:https://www.cnblogs.com/joyeecheung/p/2798574.html
Copyright © 2011-2022 走看看