长安大学第三届ACM-ICPC程序设计竞赛 L题
生活随笔
收集整理的這篇文章主要介紹了
长安大学第三届ACM-ICPC程序设计竞赛 L题
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
鏈接:
https://www.nowcoder.com/acm/contest/102/L
來源:牛客網(wǎng)
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.
來源:牛客網(wǎng)
題目描述
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,94?Yuan.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輸入
2 14 18輸出
6 2解題思路:
把錢用九進制表示,從低位向高位,當前位數(shù)字位x,
如果x>=5 則選擇用更大的面額交易,答案加9-x,
否則用當前面額交易,答案加x
#include<bits/stdc++.h> using namespace std; int main() {int t;cin>>t;while(t--){int n,v[10];cin>>n;int ans=0;for(int i=4;i>=0;i--){v[i]=n/(int)pow(9,i);n-=(int)pow(9,i)*v[i];}for(int i=0;i<4;i++){if(v[i]>=5){v[i]=9-v[i];v[i+1]++;}ans+=v[i];}printf("%d\n",ans+v[4]);}return 0; }總結
以上是生活随笔為你收集整理的长安大学第三届ACM-ICPC程序设计竞赛 L题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: STL堆算法
- 下一篇: 长安大学第三届ACM-ICPC程序设计竞