「CFgym100541」Treasure Box
题解
x转换y次的增加值和x%100转换y次相同
预处理0-99转换1-50000次的答案
就能每50000一次转移了。。。
或者倍增也可以
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<set> #include<ctime> #include<vector> #include<queue> #include<algorithm> #include<map> #include<cmath> #define eps 1e-6 #define inf 1000000000 #define mod 1000000009 #define pa pair<int,int> #define ll long long using namespace std; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int T; ll val[105][50005]; ll dp(ll x,ll y) { if(y==0)return x; if(val[x][y]!=-1)return val[x][y]; int t=0; if(x+x>=100)t=100; return val[x][y]=t+dp((x+x)%100,y-1); } ll solve(ll x,ll y) { ll ans=0; ans=x/100*100;x%=100; for(int i=1;i<=y/50000;i++) { ll t=dp(x,50000); ans+=t/100*100; x=t%100; } y%=50000; return ans+dp(x,y); } int main() { memset(val,-1,sizeof(val)); T=read(); while(T--) { ll x=read(),y=read(); printf("%I64d\n",solve(x,y)); } return 0; } |
Subscribe