C. Skyscraper “MinatoHarukas ”
爱吃代码:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#define inf 0x3f3f3f3f
const double PI=acos(-1.0);
using namespace std;
int main()
{
long long n,k,i,ans1,ans2;
while(scanf("%lld",&n)!=EOF)
{
if(n==0)
break;
k=sqrt(n);
ans1=n,ans2=1;
for(i=1;i<=k;i++)
{
if(n%i==0&&n/i%2==1&&i-n/i/2>0)
{
if(n/i>ans2)
{
ans2=n/i;
ans1=i-ans2/2;
}
}
if(n%i==0&&i%2==1&&n/i-i/2>0)
{
if(i>ans2)
{
ans2=i;
ans1=n/i-i/2;
}
}
}
for(i=2;n/i-i/2+1>0;i+=2)
{
if(n-n/i*i==i/2)
{
if(i>ans2)
{
ans2=i;
ans1=n/i-i/2+1;
}
}
}
printf("%lld %lld\n",ans1,ans2);
}
return 0;
}
B. Origami, or the art of folding paper
爱吃代码:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#define inf 0x3f3f3f3f
const double PI=acos(-1.0);
using namespace std;
long long hang[10010],lie[10010];
int main()
{
int n,m,t,p,u,v,x,y;
while(scanf("%d %d %d %d",&n,&m,&t,&p)!=EOF&&n!=0)
{
memset(hang,0,sizeof(hang));
for(int i=0;i<n;i++)
hang[i]=1;
memset(lie,0,sizeof(lie));
for(int i=0;i<m;i++)
lie[i]=1;
x=0;
y=0;
while(t--)
{
scanf("%d %d",&u,&v);
if(u==1){
for(int i=0;i<v;i++)
hang[x+v*2-i-1]+=hang[x+i];
x+=v;
}
else{
for(int i=0;i<v;i++)
lie[y+v*2-i-1]+=lie[y+i];
y+=v;
}
}
while(p--)
{
scanf("%d %d",&u,&v);
printf("%lld\n",hang[x+u]*lie[y+v]);
}
}
return 0;
}