长安大学第三届ACM-ICPC程序设计竞赛(同步赛)L- Big Boss

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld

题目描述

Many years later, Rainbow Island is in the mercy of big boss qiami. Big boss qiami is fond of number 9 because each side of the magic cube is made up of 9 small pieces and he changes the face value of circulating currency to 90,91,92,93,9Yuan.
One day programmer Uucloud went to a shop to buy Cat food worth n Yuan. The shopkeeper NoMoreWords and Uucloud are good friends so he will give Uucloud his change. Uucloud wants to know how many bills do they need in their trade at least.
For example, if Uucloud wants to buy cat food of 8 Yuan, he will pay a 9 Yuan bill and NoMoreWords will give Uucloud 1 Yuan bill as change. Two paper money are used in this trade.

输入描述:

The first line contains an integer number T, the number of test cases.
Next T lines contains a number n(1 ≤ n ≤ 109)。

输出描述:

For each test case print the number of bills they need at least.

//牛客网的题有毒。。辛辛苦苦写了一堆结果没有了

这是个简单的水题,但是还是没有签到出来,补一下,顺便提高下自己的代码能力


我们先不看这个题,先想一个这样的问题

你现在有面值1,10,100块的钱,如何凑出129块钱,用最少的钱的张数

那么就是1+2+9呗

那么这个题同理,只不过1,10,100换成了1,9,81,728,6561


但这个题还是没有结束

注意这句话

 The shopkeeper NoMoreWords andUucloud are good friends so he will give Uucloud his change.

也就是说,可以提供找零服务了

那么129块钱,就可以变成1+3+1

//取一张100的,3张10块的,然后找零一张1快的就ok

至于这个找零还是加一,可以手动模拟一下啊,很容易知道是5

//代码如下

#include<bits/stdc++.h>
using namespace std;
long long int a[10];
int main()
{
   int t;
   scanf("%d",&t);
   while(t--)
   {
       long long int n;
       scanf("%lld",&n);
       int bit=1;
       while(bit<=4)
       {
           a[bit]=n%9;
           n/=9;
           bit++;
       }
       a[5]=n;
       for(int i=1;i<=4;i++)
       {
           if(a[i]>=5)
           {
               a[i]=9-a[i];
               a[i+1]++;
           }
       }
       long long int sum=0;
       for(int i=1;i<=5;i++)
       {
           sum=sum+a[i];
       }
       printf("%lld\n",sum);
   }
   return 0;
}



阅读更多
个人分类: 提高代码能力题
上一篇BZOJ 2563: 阿狸和桃子的游戏
下一篇计蒜客-蒜头君买书&&蒜头君采摘苹果-(贪心)
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭