📄 datidama.txt
字号:
#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)
作者: 61.135.146.* 2005-10-20 16:43 回复此发言
2楼天城的比赛答题源码
{
i=n+1-i;
unsigned int t=0;
for (;i>0;i-=lowbit(i))
if (maxL[i]>t)
t=maxL[i];
return t;
}
void solve()
{
double answer=0;
memset(maxB,0,sizeof(maxB));
memset(maxL,0,sizeof(maxL));
for (int T=1;T<=n;T++)
{
int i=turnB[T],LA=arcA[i];
checkmax(answer,A[i],get_maxB(LA));
checkmax(answer,1 ,get_maxL(LA));
add_maxB(LA,B[i]);
add_maxL(LA,B[i]-A[i]+1);
}
printf("%0.0lf\n",answer);
}
int main()
{
freopen("input.txt","r",stdin);
init();
preprocess();
solve();
return 0;
}
初赛#3
#include <stdio.h>
#include <string.h>
#include <unistd.h>
//buf
const int bufsize=128*1024;
int bufL,bufP;
char buf[bufsize];
char readchar()
{
if (bufL==bufP)
{
bufL=read(0,buf,bufsize);
if (bufL==0)
return 0;
bufP=0;
}
return buf[bufP++];
}
//data
const int max_strlen=512*1024;
const int hashsize=30011;
struct THashPoint
{
char *s1,*s2;
THashPoint *next;
};
char lines[max_strlen],*s1,*s2;
FILE *f;
THashPoint *Hash[hashsize];
bool read_str()
{
lines[0]=0;
fgets(lines,max_strlen,f);
if (strlen(lines)>0 && lines[strlen(lines)-1]=='\n')
lines[strlen(lines)-1]=0;
if (strlen(lines)<3)
return false;
for (int i=0;lines[i];i++)
if (lines[i]==' ' || lines[i]=='\t')
{
s1=lines;
s2=lines+i+1;
lines[i]=0;
return true;
}
return false;
}
int HashTable_function(char *s)
{
int address=strlen(s)%hashsize;
for (int i=0;s[i];i++)
address=(address*107+s[i]+128)%hashsize;
return address;
}
void HashTable_Insert()
{
int address=HashTable_function(s1);
THashPoint *p;
for (p=Hash[address];p!=NULL;p=p->next)
if (strcmp(p->s1,s1)==0)
{
p->s2=new char[strlen(s2)+1];
strcpy(p->s2,s2);
return;
}
p=new THashPoint;
p->s1=new char[strlen(s1)+1];
p->s2=new char[strlen(s2)+1];
strcpy(p->s1,s1);
strcpy(p->s2,s2);
p->next=Hash[address];
Hash[address]=p;
}
void Print(char *s)
{
int address=HashTable_function(s);
THashPoint *p;
for (p=Hash[address];p!=NULL;p=p->next)
if (strcmp(p->s1,s1)==0)
{
printf("%s",p->s2);
return;
}
printf("%s",s);
}
void Init_HashTable()
{
f=fopen("dict.txt","r");
while (read_str())
HashTable_Insert();
fclose(f);
}
int main()
{
Init_HashTable();
//Main
freopen("text.txt","r",stdin);
bufL=bufP=0;
int L=0;
for (char c;(c=readchar())!=0;)
if (c==' ' || c=='\t' || c=='\n')
{
lines[L]=0;
Print(lines);
printf("%c",c);
L=0;
}
else
lines[L++]=c;
lines[L]=0;
Print(lines);
return 0;
}
初赛#4
#include <stdio.h>
#include <string.h>
#include <unistd.h>
const int bufsize=128*1024;
int bufL;
char buf[bufsize];
struct THashPoint
{
char *s;
int c;
THashPoint *next;
};
int MemoryID=0;
THashPoint **Hash,*Memory;
char *text;
int L,HashSize,minC;
void ReadFile()
{
text=new char[bufsize+5];
L=0;
int textL=bufsize+5;
while (1)
{
bufL=read(0,buf,bufsize);
if (bufL==0)
作者: 61.135.146.* 2005-10-20 16:43 回复此发言
3楼天城的比赛答题源码
break;
while (L+bufL>=textL)
{
char *t_text=text;
textL*=2;
text=new char[textL];
memcpy(text,t_text,L);
}
memcpy(text+L,buf,bufL);
L+=bufL;
}
text[L]=0;
}
bool Prime(int n)
{
for (int i=2;i*i<=n;i++)
if (n%i==0)
return false;
return true;
}
void Prepare()
{
int N=0,i;
for (i=0;i<L;i++)
if (text[i]==' ' || text[i]=='\t' || text[i]=='\n')
text[i]=0;
for (i=0;i<L;i++)
if ((i==0 || text[i-1]==0) && text[i]!=0)
N++;
for (HashSize=N*2+10;!Prime(HashSize);HashSize++);
Hash=new THashPoint* [HashSize];
for (i=0;i<HashSize;i++)
Hash[i]=NULL;
MemoryID=0;
Memory=new THashPoint[N+10];
}
int HashTable_function(char *s)
{
int address=strlen(s)%HashSize;
for (int i=0;s[i];i++)
address=(address*137+s[i]+128)%HashSize;
return address;
}
void HashTable_Insert(char *s)
{
int address=HashTable_function(s);
THashPoint *p;
for (p=Hash[address];p!=NULL;p=p->next)
if (strcmp(p->s,s)==0)
{
p->c++;
return;
}
p=&Memory[MemoryID++];
p->s=s;
p->c=1;
p->next=Hash[address];
Hash[address]=p;
}
bool Print(char *s)
{
int address=HashTable_function(s);
THashPoint *p;
for (p=Hash[address];p!=NULL;p=p->next)
if (strcmp(p->s,s)==0 && p->c==minC)
return false;
return true;
}
void Solve()
{
int i;
for (i=0;i<L;i++)
if ((i==0 || text[i-1]==0) && text[i]!=0)
HashTable_Insert(text+i);
minC=2000000000;
for (i=0;i<MemoryID;i++)
if (Memory[i].c<minC)
minC=Memory[i].c;
bool first=true;
for (i=0;i<L;i++)
if ((i==0 || text[i-1]==0) && text[i]!=0 && Print(text+i))
{
if (!first)
printf(" ");
first=false;
printf("%s",text+i);
}
}
int main()
{
freopen("corpus.txt","r",stdin);
ReadFile();
Prepare();
Solve();
return 0;
}
网上决赛#1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
const int maxn2=100000+5;
const int maxn=5000+5;
const int max_outputL=10000000;
const int oo=1000000000;
//buf
const int bufsize=256*1024;
int bufL,bufP;
char buf[bufsize];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -