Codeforces Round #617 (Div. 3)B. Food Buying

B. Food Buying

题目链接-Food Buying
Codeforces Round #617 (Div. 3)B. Food Buying
Codeforces Round #617 (Div. 3)B. Food Buying
题目大意
给你 x 块钱,你花费多少会返给你x/10(向下取整)的钱,问你最多能花费多少钱

解题思路
模拟+贪心即可,只要手中未花费的钱大于十块,就不断的花费10的倍数即可,最后剩下的钱小于10就直接花出,没有返现;

附上代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF=0x3f3f3f;
const int N=1e5+5;
typedef pair<int,int> PII;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	
	int t;
	cin>>t;
	while(t--){
		int s;
		cin>>s;
		if(s<10){
			cout<<s<<endl;
			continue;
		}
		ll ans=0;
		while(s>=10){
			ans+=(s/10)*10;
			s=s%10+s/10;
		}
		cout<<ans+s<<endl;
	}	
	return 0;
}

Codeforces Round #617 (Div. 3)B. Food BuyingCodeforces Round #617 (Div. 3)B. Food Buying Fiveneves 发布了25 篇原创文章 · 获赞 5 · 访问量 1万+ 私信 关注
上一篇:java基于token验证之登陆验证


下一篇:Codeforces Round #617 (Div. 3)