您的位置:首页 > 产品设计 > UI/UE

cf B. Making Sequences is Fun

2014-11-06 17:38 197 查看
http://codeforces.com/contest/373/problem/B

用二分枚举长度就可以。

#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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: