bzoj 4029 定价|模拟

直接模拟定价过程,如果这个荒谬程度存在合法解就出解,否则继续枚举

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>

#define md
#define ll long long
#define inf (int) 1e9
#define eps 1e-8
#define N
using namespace std;
ll mi[20];
int main()
{
 mi[1]=1; for (int i=2;i<=10;i++) mi[i]=mi[i-1]*10;
 int tt,lenx,leny;
 ll x,y,ans;
 scanf("%d",&tt);
 while (tt--)
 {
  scanf("%lld%lld",&x,&y); ans=0;
  lenx=10; while (mi[lenx]>x) lenx--;
  leny=10; while (mi[leny]>y) leny--;
  if (lenx!=leny)
  {
   for (int i=lenx;i<=leny;i++)
     if (x<=5*mi[i]&&5*mi[i]<=y) { ans=5*mi[i]; break;}
   if (!ans) ans=mi[lenx]*(x/mi[lenx]+(x%mi[lenx]!=0));
   printf("%d\n",ans);
   continue;
  }
  ans=0;
  while (lenx)
  {
   if (x/mi[lenx]!=y/mi[lenx])
   {
    if (x==0);
    else if (x<=5*mi[lenx]&&5*mi[lenx]<=y) { ans+=5*mi[lenx];}
    else ans+=mi[lenx]*(x/mi[lenx]+(x%mi[lenx]!=0));
    break;
   }
   else
   {
    ans+=x/mi[lenx]*mi[lenx];
    x%=mi[lenx]; y%=mi[lenx];
    lenx--;
   }
  }
  printf("%lld\n",ans);
 }
 return 0;
}


你可能感兴趣的:(bzoj 4029 定价|模拟)