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

第十周 11.2---11.8

时间:2015-11-03 02:01:39      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:

新的一周>_<

---------11.3

cf 373 B

http://codeforces.com/contest/373/problem/B

写一个二分改到现在----真是,挫---爆---了---

先是算 [l,r] 的区间里面的数字的位数调了很久

然后是INF取太大,一直算不出来---

然后是二分的端点没有搞清楚---

最后中间相乘的时候还爆long long 了----

技术分享
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<algorithm>
 5 using namespace std;
 6 
 7 typedef long long LL;
 8 const long long INF = 2e16;
 9 
10 LL w,m,k;
11 LL a[105];
12 
13 LL calc(LL l,LL r){
14     LL tmp = l;
15     LL c = 0;
16     int ok = 0;
17     int cnt = 0;
18 //    printf("---l = %I64d  r = %I64d\n",l,r);
19     for(;;){
20         cnt++;
21         int x = lower_bound(a+1,a+20+1,tmp) - a;
22         if(a[x] == tmp) x++;
23         LL y = a[x];
24         if(y > r){
25             y = r,ok = 1;
26             c += (y-tmp+1)*(x-1);
27         }
28         else{
29             c += (y-tmp)*(x-1);
30         }
31     //    printf("---y = %I64d\n",y);
32         tmp = a[x];
33     //    printf("c = %I64d  tmp = %I64d y = %I64d\n",c,tmp,y);
34         if(ok == 1) break;
35         //if(cnt >= 7) break;
36     } 
37     return c;
38 } 
39 
40 void solve(){
41     LL l,r,mid;
42     l = m,r = INF;
43     w = w/k;
44     for(int i = 0;i <= 100;i++){
45         mid = (r+l)/2;
46         if(calc(m,mid) <= w) l = mid;
47         else r = mid-1; 
48     //    printf("l = %I64d  r = %I64d  mid = %I64d\n",l,r,mid);
49     } 
50     
51         LL d = 0;
52         if(calc(m,l) <= w) d = max(d,l);//printf("%I64d-\n",calc(m,l));
53         if(calc(m,r) <= w) d = max(d,r);//printf("%I64d--\n",calc(m,r));
54         if(calc(m,mid) <= w) d = max(d,mid);//printf("%I64d-==\n",calc(m,mid));
55     //    printf("d = %I64d\n",d);
56         if(d == 0) puts("0");
57         else printf("%I64d\n",d-m+1);
58 }
59 
60 int main(){
61     a[1] = 1;
62     for(int i = 2;i <= 20;i++) a[i] = a[i-1]*10;
63     while(scanf("%I64d %I64d %I64d",&w,&m,&k) != EOF){
64         solve();
65     }
66     return 0;
67 }
View Code

 

第十周 11.2---11.8

标签:

原文地址:http://www.cnblogs.com/wuyuewoniu/p/4932014.html

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