码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces899D Shovel Sale(思路)

时间:2018-04-08 22:44:01      阅读:426      评论:0      收藏:0      [点我收藏+]

标签:存储   typedef   namespace   mat   ons   clu   std   algorithm   方案   

http://codeforces.com/problemset/problem/899/D

还是得tag一下,以下代码只有G++ 14 6.4.0能过,其他都过不了不知为什么?

思路:先求出最多的9的个数,发现最多的9的个数总比2*n的位数少一位。t存储9的位数,sum则是该值。

然后对这个sum加上先导0~9,由于序列是连续的,可以先判断sum是可以分解为1+x还是由x+n,然后判断1~x或者x~n有多少位,位数/2就是该值的方案。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cstdlib>
 6 #include<cmath>
 7 #define IO ios::sync_with_stdio(false);cin.tie(0);
 8 const int MOD=1e9+7;
 9 typedef int ll;
10 using namespace std;
11 ll n;
12 int main()
13 {
14     IO;
15     while(cin >> n){ 
16         ll m = 2*n, cnt=0;
17         while(m){
18             cnt++;
19             m /= 10;
20         }
21         ll t = cnt-1;
22         ll r=1, sum=0;
23         while(t--){
24             sum += r*9;
25             r = r*10;
26         }
27         ll tmp = pow(10, cnt-1), ans=0;
28         for(int i = 0; i < 10; i++){
29             ll k = sum+tmp*i;
30             if(k>n+(n-1)){
31                 break;
32             }
33             if(k-1>n){
34                 ll p = k-n;
35                 ans += (n-p+1)/2;
36             }
37             else{
38                 ll p = k-1;
39                 ans += (p-1+1)/2;
40             }
41         }
42         cout << ans << endl;
43     }
44     return 0;
45 } 

 

Codeforces899D Shovel Sale(思路)

标签:存储   typedef   namespace   mat   ons   clu   std   algorithm   方案   

原文地址:https://www.cnblogs.com/Surprisezang/p/8747477.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!