Little Sub and Mr.Potato's Math Problem-构造
Posted sdutning
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Little Sub and Mr.Potato's Math Problem-构造相关的知识,希望对你有一定的参考价值。
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5864
思路 : 判断小于它的合法的,再看大于它的合法的,特判10000、10、1000.... 这种情况
.
#include<bits/stdc++.h> using namespace std; #define ll long long ll t,n,k,m,po[222]; ll getmin(ll x) { ll ret=0,data[55],id=0; po[0]=1; while(x) { data[id++]=x; x/=10; po[id]=po[id-1]*10; } for(int i=0; i<id; i++) ret+=data[i]-po[id-i-1]+1; return ret; } int main() { scanf("%lld",&t); while(t--) { scanf("%lld%lld",&k,&m); m-=getmin(k); if(m<0)printf("0 "); else if(m==0)printf("%lld ",k); else { ll hig,big; for(ll i=1;; i*=10) if(k/i<10) { big=i; hig=k-i; break; } if(big==k)printf("0 "); else { big*=10; hig*=10; while(m>hig) { m-=hig; hig*=10; big*=10; } printf("%lld ",big+m-1); } } } return 0; }
以上是关于Little Sub and Mr.Potato's Math Problem-构造的主要内容,如果未能解决你的问题,请参考以下文章
ZOJ - 4089 :Little Sub and Isomorphism Sequences (同构 set)
ZOJ - 4082:Little Sub and his Geometry Problem (双指针)
石油大训练 Little Sub and Johann (博弈SG打表找规律)
ZOJ-4089-Little Sub and Isomorphism Sequences
ZOJ Monthly, January 2019 Little Sub and Isomorphism Sequences 离线离散化 + set + multiset