问题 F: 求多个数的最大公约数 multigcd [1*]:
` #include
include
include
include
using namespace std;
int fun(int a,int b)
{
return b==0?a:fun(b,a%b);
}
int main()
{
int n;
cin>>n;
vector
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
int ans=0;
ans=fun(a[1],a[2]);
for(int i=3;i<=n;i++)
ans=fun(ans,a[i]);
cout<<ans;
}`
问题 G: 【高精度】高精度整数除法(例题):
` #include
include
include
include
include
include
using namespace std;
int a[260],b[260],c[260],t[260];
void init(int* p)
{
string s;
cin>>s;
p[0]=s.size();
for(int i=1;i<=p[0];i++)
{
p[i]=s[p[0]-i]-'0';
}
}
void numcpy(int n)
{
t[0]=b[0]+n;
for(int i=1;i<=b[0];i++)
t[n+i]=b[i];
}
int compare()
{
if(a[0]!=t[0])
return a[0]>t[0];
else
{
for(int i=a[0];i>=1;i--)
{
if(a[i]!=t[i])
return a[i]>t[i];
}
}
return 1;
}
void mul()
{
for(int i=1;i<=t[0];i++)
{
if(t[i]>a[i])
{
a[i+1]--;
a[i]+=10;
}
a[i]-=t[i];
}
while(a[a[0]]==0)
a[0]--;
}
void print(int* p)
{
for(int i=p[0];i>=1;i--)
printf("%d",p[i]);
if(p[0]<1)
printf("0");
cout<<endl;
}
int main()
{
init(a);
init(b);
c[0]=a[0]-b[0]+1;
for(int i=c[0]-1;i>=0;i--)
{
memset(t,0,sizeof(int)*260);
numcpy(i);
while(compare())
{
c[i+1]++;
mul();
}
}
while(c[c[0]]==0)
c[0]--;
print(c);
print(a);
}`
问题 H: 栈:
` #include
include
include
include
include
using namespace std;
int f[20][20];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n+1;i++)
f[1][i]=1;
for(int i=2;i<=n+1;i++)
{
for(int j=i;j<=n+1;j++)
{
if(i==j)
f[i][j]=f[i-1][j];
else
f[i][j]=f[i-1][j]+f[i][j-1];
}
}
cout<<f[n+1][n+1]<<endl;
}`
问题 I: 车厢调度:
` #include
include
include
include
include
using namespace std;
int main()
{
int n;
cin>>n;
vector
stack
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
int w=0,flag=0;
for(int i=1;i<=n;i++)
{
while(b.empty()||b.top()<a[i])
b.push(++w);
if(b.top()==a[i])
b.pop();
else
flag=1;
}
if(flag)
printf("NO\n");
else
printf("YES");
}`