生活随笔 
收集整理的這篇文章主要介紹了
                                
中石油训练赛 - Historical Maths(二分) 
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
 
                                
                             
                             
                            
 
題目大意:給出三個十進制下的數字 A ,B ,C ,問是否存在一個 k ,滿足在 k 進制下有 A * B = C
 
題目分析:需要觀察出進制與 A * B 和 C 的大小之間具有單調性,如果進制較小的話,那么進位自然就會變多,從而使得位數邊長,整體數字就會變大,反之亦然,所以據此,可以直接二分答案,用一個 check 進行檢查,需要注意的是答案會爆 long long,所以整體用 __int128 進行計算即可,二分的下限設置為所有數字的最大值 + 1,上限設置為 1e20?
 
代碼:  ?
 
//#pragma GCC optimize(2)
//#pragma GCC optimize("Ofast","inline","-ffast-math")
//#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<cassert>
#include<bitset>
#include<unordered_map> 
using namespace std;typedef __int128 LL;typedef unsigned long long ull;const int inf=0x3f3f3f3f;const int N=1e3+100;template <typename T>inline void read(T& t){t=0;register char ch=getchar();while(!('0'<=ch&&ch<='9')){if(ch=='-') t*=-1;ch=getchar();}while(('0'<=ch&&ch<='9')){t=((t<<1)+(t<<3))+ch-'0';ch=getchar();}
}template <typename T>inline void write(T x){if(x<0) putchar('-'),x=~(x-1);int s[50],top=0;while(x) s[++top]=x%10,x/=10;if(!top) s[++top]=0;while(top) putchar(s[top--]+'0');
}LL a[N],b[N],c[N],cc[N*N];int la,lb,lc;LL l=0,r=1e20;void input(int& n,LL a[])
{scanf("%d",&n);n--;for(int i=n;i>=0;i--){read(a[i]);l=max(l,a[i]+1);}
}int check(int pos)//1:大了,-1:小了 
{if(pos>lc)return -1;if(pos<lc)return 1;for(int i=pos;i>=0;i--){if(cc[i]>c[i])return -1;if(cc[i]<c[i])return 1;}return 0;
}int cal(LL mid)
{memset(cc,0,sizeof(cc));for(int i=0;i<=la;i++)for(int j=0;j<=lb;j++)cc[i+j]+=a[i]*b[j];int pos=0;while(pos<=la+lb||cc[pos]){cc[pos+1]+=cc[pos]/mid;cc[pos]%=mid;pos++;}return check(pos-1);
}int main()
{
#ifndef ONLINE_JUDGE
//  freopen("data.in.txt","r",stdin);
//  freopen("data.out.txt","w",stdout);
#endif
//  ios::sync_with_stdio(false);input(la,a);input(lb,b);input(lc,c);while(l<=r){LL mid=l+r>>1;int t=cal(mid);if(t==0){write(mid);return 0;}else if(t==1)r=mid-1;else if(t==-1)l=mid+1;}puts("impossible");return 0;
} 
?
                            總結 
                            
                                以上是生活随笔 為你收集整理的中石油训练赛 - Historical Maths(二分) 的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                            
                                如果覺得生活随笔 網站內容還不錯,歡迎將生活随笔 推薦給好友。