codeforces331C1 - The Great Julya Calendar 贪心

也是第一次看见有  C1 C2 C3这三个等级的题目,只撸出了C1  

题意:给你一个10^6以内的数字,问你要每一次减去它其中的一位(当做个位)最少需要多少次减为0 

解题思路:每一次减去最大的那个数可得是贪心最优。

解题代码:

 1 // File Name: 331c1.cpp
 2 // Author: darkdream
 3 // Created Time: 2014年07月24日 星期四 22时32分18秒
 4 
 5 #include<vector>
 6 #include<list>
 7 #include<map>
 8 #include<set>
 9 #include<deque>
10 #include<stack>
11 #include<bitset>
12 #include<algorithm>
13 #include<functional>
14 #include<numeric>
15 #include<utility>
16 #include<sstream>
17 #include<iostream>
18 #include<iomanip>
19 #include<cstdio>
20 #include<cmath>
21 #include<cstdlib>
22 #include<cstring>
23 #include<ctime>
24 
25 using namespace std;
26 
27 int main(){
28     int n; 
29     scanf("%d",&n);
30     int ans = 0 ; 
31     while(n)
32     {
33        int t = n;  
34        int maxn = 0 ; 
35        while(t)
36        {
37            maxn = max(maxn,t%10);
38            t = t /10 ;
39        }
40        n -= maxn;
41        ans ++; 
42     }
43     printf("%d\n",ans);
44 return 0;
45 }
View Code

转载于:https://www.cnblogs.com/zyue/p/3867154.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值