cf B. Making Sequences is Fun
2014-11-06 17:38
197 查看
http://codeforces.com/contest/373/problem/B
用二分枚举长度就可以。
View Code
用二分枚举长度就可以。
#include <cstdio> #include <cstring> #include <algorithm> #define LL __int64 using namespace std; LL w,m,k; bool ok(LL c) { LL ans=0; LL x2=m+c-1; int t1=0; LL b=x2; while(b) { b/=10; t1++; } int t2=0; LL b1=m; while(b1) { b1/=10; t2++; } if(t1==t2) { ans+=c*t1*k; if(ans<=w&&ans>=0) return true; else return false; } LL x1=1; int a1=t1-1; while(a1--) { x1*=10; } ans+=(x2-x1+1)*t1*k; LL x3=1; int a2=t2; while(a2--) { x3*=10; } ans+=(x3-m)*t2*k; for(LL i=x3; i<x1; i*=10) { t2++; ans+=(i*10-i)*t2*k; } if(ans<=w&&ans>=0) return true; else return false; } int main() { while(scanf("%I64d%I64d%I64d",&w,&m,&k)!=EOF) { LL l=1,r=w; LL ans=0; while(l<=r) { LL mid=(l+r)/2; if(ok(mid)) { ans=mid; l=mid+1; } else r=mid-1; } printf("%I64d\n",ans); } return 0; }
View Code
相关文章推荐
- 数学 Codeforces Round #219 (Div. 2) B. Making Sequences is Fun
- CodeForces 373B——模拟——Making Sequences is Fun
- Making Sequences is Fun(简单枚举)
- CodeForces 373 B. Making Sequences is Fun
- Codeforces Round #219 (Div. 2) B. Making Sequences is Fun
- Codeforces373B_Making Sequences is Fun_枚举长度。。。
- codeforces#219_div2_B Making Sequences is Fun
- Making AI Fun: When Good Enough is Good Enough
- cf C. Counting Kangaroos is Fun
- CF 372D Choosing Subtree is Fun
- CF - 447C. DZY Loves Sequences - 动态规划
- 20 Funny Commands of Linux or Linux is Fun in Terminal
- B. Counting Rectangles is Fun----dp
- A. Collecting Beats is Fun
- CodeForces 372 A. Counting Kangaroos is Fun
- CodeForces 372b_Counting Rectangles is Fun_dp(暴力)
- Machine Learning is Fun!
- python 状态机语句"Python is fun"褒贬义判断的两种实现方式
- spoj422 Transposing is Even More Fun(polya)
- J-- DZY Loves Sequences(CF-447C