emmm
改题稍紧张,以后几篇并一起写
9.6
(前十并没有参加本次考试)
于是我就rank8了
一道题一道题来
先说T1:
显然是一个高精度GCD,于是打算用计算器算一下时间复杂度
众所周知gcd是log的
于是...

按这样算显然会T对吧
所以我放弃了
但考后发现
计算器运算优先级锅了
其实是:

完全可过
P.S.鉴于高精取模并不好打,我yy出了多一个log的只用高精加&&减的做法
代码:
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
#define int long long
char ch[105];
struct num{
int a[1005];
int opt;
friend num operator +(num a,num b)
{
num c;int k=0;
c.clear();
c.a[0]=max(a.a[0],b.a[0]);
/*cout<<"add:"<<endl;
a.out(),b.out();
cout<<a.a[0]<<" "<<b.a[0]<<endl;*/
for(int q=1;q<=c.a[0];q++)
{
c.a[q]=a.a[q]*(q<=a.a[0])+b.a[q]*(q<=b.a[0])+k;
k=c.a[q]/10;
c.a[q]%=10;
}
if(k) c.a[++c.a[0]]=k;
c.a[0]=100;
while(!c.a[c.a[0]]&&c.a[0]) c.a[0]--;
//cout<<"before pre:"<<endl;c.out();
//char ch=getchar();
c.pre();
//cout<<"after pre:"<<endl;c.out();
c.a[0]=100;
|
8
|
859乔屹 | 30
03:11:03
|
60
03:13:36
|
40
03:14:28
|
130
03:14:28
|
while(!c.a[c.a[0]]&&c.a[0]) c.a[0]--;
return c;
}
friend bool operator <(num a,num b)
{
if(a.opt<b.opt) return 1;
if(b.opt<a.opt) return 0;
int bo=0;
if(a.opt<0) a.change(),bo=-1;
if(b.opt<0) b.change();
if(a.a[0]>b.a[0]) return 0-bo;
if(a.a[0]<b.a[0]) return 1+bo;
for(int q=a.a[0];q;q--)
{
if(a.a[q]>b.a[q]) return 0-bo;
if(a.a[q]<b.a[q]) return 1+bo;
}
return 0;
}
friend bool operator >(num a,num b)
{return 1^(a<b);}
void pre()
{
//out();
for(int q=1;q<a[0];q++)
if(a[q]<0)
a[q+1]--,a[q]=10+a[q];
//char ch=getchar();
}
void change()
{
opt*=-1;
for(int q=1;q<=a[0];q++)
a[q]*=-1;
}
void clear(){memset(a,0,sizeof(a));opt=1;}
void get()
{
clear();
scanf("%s",ch);
a[0]=strlen(ch);
for(int q=0;q<a[0];q++)
a[q+1]=ch[a[0]-q-1]-'0';
}
void out()
{
for(int q=a[0];q;q--)
cout<<a[q];
cout<<endl;
}
}tmp,cmp,a,b,res[500];
void pre()
{
tmp.clear(),cmp.clear();
tmp.a[0]=1;
cmp.a[0]=cmp.a[1]=1;
}
num gcd(num a,num b)
{
num c;c.clear();
while(tmp<a)
{
int q=2;
if(a>b) c=a,a=b,b=c;
res[1]=a;
for(q=2;res[q-1]<b;q++)
{
res[q].clear();
res[q]=res[q-1]+res[q-1];
//res[q].out();
//char ch=getchar();
}
q--;
for(;q;q--)
if(b>res[q])
{
/*b.out();*/
res[q].change();
//cout<<"res"<<endl;
//res[q].out();
//cout<<"res"<<endl;
/*char ch=getchar();*/
b=b+res[q];
res[q].change();
}
// a.out();
// b.out();
if(a>b) c=a,a=b,b=c;
}
return b;
}
signed main()
{
//freopen("ans.in","w",stdout);
int qu;
cin>>qu;
pre();
for(int q=1;q<=qu;q++)
{
a.clear(),b.clear();
a.get(),b.get();
num now=gcd(a,b);
if((now<cmp||cmp<now))
puts("No");
else
puts("Yes");
}
}
好,接下来是T2:
对于n<=2000
$/Theta n^2$的暴力总是可以的
对于只有0\1的
$/Theta n /log n$