在征得楼天城本人的同意(谢谢楼天城同学)后,我们在这里公布他的三轮比赛的答题源码,供有兴趣的各位参考。
初赛#1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _MAXL 2000000
void GetN(char *s,long long &N)
{
N=0;
for (int i=0;s[i];i++)
N=N*10+(s[i]-48);
}
void print_bigint(long long n)
{
if (n>=10)
print_bigint(n/10);
printf("%d",int(n%10));
}
void Solve(long long N)
{
bool find_answer=false;
long long L,T,A1,k;
for (L=2;L<=_MAXL && L*(L-1)/2<N;L++);
for (L--;L>=2;L--)
{
T=L*(L-1)/2;
if (N>T && (N-T)%L==0)
{
find_answer=true;
A1=(N-T)/L;
for (k=0;k<L;k++)
{
if (k>0)
printf(" ");
print_bigint(A1+k);
}
printf("\n");
}
}
if (!find_answer)
printf("NONE\n");
}
int main(int argc,char *arg[])
{
long long N;
GetN(arg[1],N);
Solve(N);
return 0;
}
初赛#2
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
//buf
const int bufsize=128*1024;
int bufL,bufP;
char buf[bufsize];
//segments
const int maxn=1000005;
int n;
unsigned int A[maxn],B[maxn];
//sort
const int countsize=65536;
int arcA[maxn],arcB[maxn],turnB[maxn];
int count[countsize],tmp[maxn];
//solve
unsigned int maxB[maxn],maxL[maxn];
void swap(unsigned int &a,unsigned int &b)
{
unsigned int t=a;
a=b;
b=t;
}
char readchar()
{
if (bufL==bufP)
{
bufL=read(0,buf,bufsize);
if (bufL==0)
return 0;
bufP=0;
}
return buf[bufP++];
}
bool readnumber(unsigned int &v)
{
char c;
do{
c=readchar();
if (c==0)
return false;
}while (c<'0' || c>'9');
for (v=0;c>='0' && c<='9';c=readchar())
v=v*10+(c-48);
return true;
}
void init()
{
bufL=bufP=0;
for (n=0;readnumber(A[n+1]) && readnumber(B[n+1]);)
{
n++;
if (A[n]>B[n])
swap(A[n],B[n]);
}
}
void count_sort(unsigned int A[],int arc[])
{
int i;
//lower bit
memset(count,0,sizeof(count));
for (i=1;i<=n;i++)
count[A[i]&65535]++;
for (i=1;i<countsize;i++)
count[i]+=count[i-1];
for (i=n;i>=1;i--)
tmp[count[A[i]&65535]--]=i;
//higher bit
memset(count,0,sizeof(count));
for (i=1;i<=n;i++)
count[A[i]>>16]++;
for (i=1;i<countsize;i++)
count[i]+=count[i-1];
for (i=n;i>=1;i--)
arc[tmp[i]]=(count[A[tmp[i]]>>16]--);
}
void preprocess()
{
count_sort(A,arcA);
count_sort(B,arcB);
for (int i=1;i<=n;i++)
turnB[arcB[i]]=i;
}
void checkmax(double &answer,unsigned int S,unsigned int T)
{
if (S>T)
return;
double t=double(T)-double(S)+1;
if (t>answer)
answer=t;
}
#define lowbit(n) (((n)^((n)-1))&(n))
void add_maxB(int i,unsigned int v)
{
for (;i<=n;i+=lowbit(i))
if (v>maxB[i])
maxB[i]=v;
}
void add_maxL(int i,unsigned int v)
{
i=n+1-i;
for (;i<=n;i+=lowbit(i))
if (v>maxL[i])
maxL[i]=v;
}
unsigned int get_maxB(int i)
{
unsigned int t=0;
for (;i>0;i-=lowbit(i))
if (maxB[i]>t)
t=maxB[i];
return t;
}
unsigned int get_maxL(int i)
初赛#1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _MAXL 2000000
void GetN(char *s,long long &N)
{
N=0;
for (int i=0;s[i];i++)
N=N*10+(s[i]-48);
}
void print_bigint(long long n)
{
if (n>=10)
print_bigint(n/10);
printf("%d",int(n%10));
}
void Solve(long long N)
{
bool find_answer=false;
long long L,T,A1,k;
for (L=2;L<=_MAXL && L*(L-1)/2<N;L++);
for (L--;L>=2;L--)
{
T=L*(L-1)/2;
if (N>T && (N-T)%L==0)
{
find_answer=true;
A1=(N-T)/L;
for (k=0;k<L;k++)
{
if (k>0)
printf(" ");
print_bigint(A1+k);
}
printf("\n");
}
}
if (!find_answer)
printf("NONE\n");
}
int main(int argc,char *arg[])
{
long long N;
GetN(arg[1],N);
Solve(N);
return 0;
}
初赛#2
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
//buf
const int bufsize=128*1024;
int bufL,bufP;
char buf[bufsize];
//segments
const int maxn=1000005;
int n;
unsigned int A[maxn],B[maxn];
//sort
const int countsize=65536;
int arcA[maxn],arcB[maxn],turnB[maxn];
int count[countsize],tmp[maxn];
//solve
unsigned int maxB[maxn],maxL[maxn];
void swap(unsigned int &a,unsigned int &b)
{
unsigned int t=a;
a=b;
b=t;
}
char readchar()
{
if (bufL==bufP)
{
bufL=read(0,buf,bufsize);
if (bufL==0)
return 0;
bufP=0;
}
return buf[bufP++];
}
bool readnumber(unsigned int &v)
{
char c;
do{
c=readchar();
if (c==0)
return false;
}while (c<'0' || c>'9');
for (v=0;c>='0' && c<='9';c=readchar())
v=v*10+(c-48);
return true;
}
void init()
{
bufL=bufP=0;
for (n=0;readnumber(A[n+1]) && readnumber(B[n+1]);)
{
n++;
if (A[n]>B[n])
swap(A[n],B[n]);
}
}
void count_sort(unsigned int A[],int arc[])
{
int i;
//lower bit
memset(count,0,sizeof(count));
for (i=1;i<=n;i++)
count[A[i]&65535]++;
for (i=1;i<countsize;i++)
count[i]+=count[i-1];
for (i=n;i>=1;i--)
tmp[count[A[i]&65535]--]=i;
//higher bit
memset(count,0,sizeof(count));
for (i=1;i<=n;i++)
count[A[i]>>16]++;
for (i=1;i<countsize;i++)
count[i]+=count[i-1];
for (i=n;i>=1;i--)
arc[tmp[i]]=(count[A[tmp[i]]>>16]--);
}
void preprocess()
{
count_sort(A,arcA);
count_sort(B,arcB);
for (int i=1;i<=n;i++)
turnB[arcB[i]]=i;
}
void checkmax(double &answer,unsigned int S,unsigned int T)
{
if (S>T)
return;
double t=double(T)-double(S)+1;
if (t>answer)
answer=t;
}
#define lowbit(n) (((n)^((n)-1))&(n))
void add_maxB(int i,unsigned int v)
{
for (;i<=n;i+=lowbit(i))
if (v>maxB[i])
maxB[i]=v;
}
void add_maxL(int i,unsigned int v)
{
i=n+1-i;
for (;i<=n;i+=lowbit(i))
if (v>maxL[i])
maxL[i]=v;
}
unsigned int get_maxB(int i)
{
unsigned int t=0;
for (;i>0;i-=lowbit(i))
if (maxB[i]>t)
t=maxB[i];
return t;
}
unsigned int get_maxL(int i)