Food Buying(CF-1296B)
Problem Description
Mishka wants to buy some food in the nearby shop. Initially, he has s burles on his card.
Mishka can perform the following operation any number of times (possibly, zero): choose some positive integer number 1≤x≤s, buy food that costs exactly x burles and obtain ?x10? burles as a cashback (in other words, Mishka spends x burles and obtains ?x10? back). The operation ?ab? means a divided by b rounded down.
It is guaranteed that you can always buy some food that costs x for any possible value of x.
Your task is to say the maximum number of burles Mishka can spend if he buys food optimally.
For example, if Mishka has s=19 burles then the maximum number of burles he can spend is 21. Firstly, he can spend x=10 burles, obtain 1 burle as a cashback. Now he has s=10 burles, so can spend x=10 burles, obtain 1 burle as a cashback and spend it too.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1≤t≤104) — the number of test cases.
The next t lines describe test cases. Each test case is given on a separate line and consists of one integer s (1≤s≤109) — the number of burles Mishka initially has.
Output
For each test case print the answer on it — the maximum number of burles Mishka can spend if he buys food optimally.
Examples
Input
6
1
10
19
9876
12345
1000000000
Output
1
11
21
10973
13716
1111111111
題意:t 組數據,每組給出 1 個數 n,代表有 n 元錢,現在用這 n 元錢買東西,每買 10 元返現 1 元,不足 10 元不進行返現,在返現后,將剩下的錢與返現的錢相加,繼續買東西,重復返現過程,問最終能買多少錢的東西
思路:照題意模擬即可
Source Program
#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #include<bitset> #define PI acos(-1.0) #define INF 0x3f3f3f3f #define LL long long #define Pair pair<int,int> LL quickPow(LL a,LL b){ LL res=1; while(b){if(b&1)res*=a; a*=a; b>>=1;} return res; } LL multMod(LL a,LL b,LL mod){ a%=mod; b%=mod; LL res=0; while(b){if(b&1)res=(res+a)%mod; a=(a<<=1)%mod; b>>=1; } return res%mod;} LL quickMultPowMod(LL a, LL b,LL mod){ LL res=1,k=a; while(b){if((b&1))res=multMod(res,k,mod)%mod; k=multMod(k,k,mod)%mod; b>>=1;} return res%mod;} LL quickPowMod(LL a,LL b,LL mod){ LL res=1; while(b){if(b&1)res=(a*res)%mod; a=(a*a)%mod; b>>=1; } return res; } LL getInv(LL a,LL mod){ return quickPowMod(a,mod-2,mod); } LL GCD(LL x,LL y){ return !y?x:GCD(y,x%y); } LL LCM(LL x,LL y){ return x/GCD(x,y)*y; } const double EPS = 1E-15; const int MOD = 1000000000+7; const int N = 2000+5; const int dx[] = {0,0,1,-1,1,1,-1,-1}; const int dy[] = {1,-1,0,0,1,-1,1,-1}; using namespace std;int main() {int t;scanf("%d", &t);while (t--) {LL n;scanf("%lld", &n);LL res = 0;while (n >= 0) {LL k = floor(n / 10);res += k * 10;n -= k * 10;n += k;if (n <= 9) {res += n;break;}}printf("%lld\n", res);}}?
總結
以上是生活随笔為你收集整理的Food Buying(CF-1296B)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 信息学奥赛一本通(1027:输出浮点数)
- 下一篇: string matching(HDU-