本記事はソースのみです。忙しくて、レポートを書いている暇がないのでご了承ください。
There are sources which I made at the next contest.
次のコンテストで作成したソースです。
・Codechef September Long/Short
・Codeforces #87 (Div.2) / #88
・Topcoder SRM 518(Div.2)
・UVa The Seventh Hunan Collegiate Programming Contest Semilive
・UAPC 7th
[Codechef September Long]
<BIT magazine(C)>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef unsigned int u_int;
int main(void){
u_int pages[1024];
u_int tore,page,i,j,k,t,m;
double sum,tmp;
scanf("%u",&t);
while(t--){
scanf("%u",&page);
memset(pages,0,sizeof(pages));
for(i=0;i<page;i++) pages[i/2]+=(i+1);
page++;
page>>=1;
for(scanf("%u",&m),i=0;i<m;i++){
scanf("%u",&k);
pages[(k-1)/2]-=k;
}
sum=0;
scanf("%u",&tore);
tmp=1-(double)tore/page;
for(i=0;i<page;i++) sum+=pages[i]*tmp;
printf("%.4lf\n",sum,tmp);
}
return 0;
}
[Codechef September Short]
<Hotel Bytelandia (C++)>
#include<iostream>
using namespace std;
int main(void){
int t,n,st[100],en[100],maxs,sum;
cin>>t;
while(t--){
cin>>n;
maxs=0;
for(int i=0;i<n;i++) cin>>st[i];
for(int i=0;i<n;i++) cin>>en[i];
for(int i=1;i<=1000;i++){
for(int j=0,sum=0;j<n;j++) if(st[j]<=i && i<en[j]) sum++;
if(maxs<sum) maxs=sum;
}
cout<<maxs<<endl;
}
return 0;
}
[Codeforces #87(Div.2)]
<Problem.A(C++)>
#include<iostream>
using namespace std;
int main(void){
int n,maxs=0,now=0,in1,in2;
cin>>n;
while(n--){
cin>>in1>>in2;
now-=in1;
now+=in2;
if(maxs<now) maxs=now;
}
cout<<maxs<<endl;
return 0;
}
<Problem.C(C)>
#include<stdio.h>
int emp[2000];
int searchsup(int n,int floor);
int main(void){
int i,n,m=1,tmp;
scanf("%d",&n);
for(i=0;i<n;i++) scanf("%d",&emp[i]);
for(i=0;i<n;i++) --emp[i];
for(i=0;i<n;i++){
tmp=searchsup(i,1);
if(tmp>m) m=tmp;
}
printf("%d\n",m);
return 0;
}
int searchsup(int n,int floor){
if(emp[n]<0) return floor;
return searchsup(emp[n],floor+1);
}
<Problem.D(C,WA)>
#include<stdio.h>
#define MAX(x,y) (((x)<(y))?(y):(x))
#define MIN(x,y) (((x)<(y))?(x):(y))
int main(void){
int n,m,i,j,k,now=0;
char map[160][161];
int count=0,right[160],left[160],lastline=-1;
scanf("%d %d%*c",&n,&m);
for(i=0;i<160;i++) right[i]=left[i]=-1;
for(i=0;i<n;i++) scanf("%s%*c",map[i]);
for(i=0;i<n;i++){
for(j=0;j<m;j++){
if(map[i][j]=='G') continue;
left[i]=j;
break;
}
for(j=m-1;j>=0;j--){
if(map[i][j]=='G') continue;
right[i]=j;
break;
}
}
for(i=n-1;i>=0;i--){
if(left[i]==-1) continue;
lastline=i;
break;
}
for(i=0;i<n;i++,count++){
if(i==lastline){
if(i%2==0) count+=right[i]-now;
else count+=now-left[i];
break;
}
if(i%2==0){
if(right[i]!=-1 && right[i+1]!=-1) k=MAX(right[i],right[i+1]);
else if(right[i]==-1 && right[i+1]==-1) continue;
else if(right[i]==-1) k=right[i+1];
else k=right[i];
count+=k-now;
now=k;
}else{
if(left[i]!=-1 && left[i+1]!=-1) k=MIN(left[i],left[i+1]);
else if(left[i]==-1 && left[i+1]==-1) continue;
else if(left[i]==-1) k=left[i+1];
else k=left[i];
count+=now-k;
now=k;
}
}
if(count<0 || lastline<0) count=0;
printf("%d\n",count);
return 0;
}
[Codeforces #88]
<Problem.A(C)>
#include<stdio.h>
int main(void){
int m,n,s,f,t,mode,ans,now,add;
scanf("%d %d",&n,&m);
while(n--){
scanf("%d %d %d",&s,&f,&t);
if(s==f){
printf("%d\n",t);
continue;
}
mode=t/(m-1)%2;
if(mode==1){
now=m-t%(m-1);
if(s<=now) add=now-s;
else{
add=(now-1)+(s-1);
mode=0;
}
}else{
now=t%(m-1)+1;
if(s>=now) add=s-now;
else{
add=(m-now)+(m-s);
mode=1;
}
}
if(mode==1){
if(s>f) ans=s-f;
else ans=(s-1)+(f-1);
}else{
if(s<f) ans=f-s;
else ans=(m-s)+(m-f);
}
printf("%d\n",ans+add+t);
}
return 0;
}
[Topcoder SRM 518(Div.2)]
<250-score(C++)>
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
class TwiceString{
public:
string getShortest(string s){
char str[51],substr[101];
strcpy(str,s.c_str());
int l;
l=strlen(str);
for(int i=l-1;i>0;i--){
if(strncmp(str,str+(l-i),i)==0){
strcpy(substr,str);
strcat(substr,str+i);
string ret=substr;
return ret;
}
}
strcpy(substr,str);
strcat(substr,str);
string rets=substr;
return rets;
}
};
<500-score(C++)>
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
class LargestSubsequence{
public:
string getLargest(string s){
char str[51],substr[51];
int nstr=0,flg=0,l;
strcpy(str,s.c_str());
l=strlen(str);
for(int i=0;i<l-1;i++){
flg=0;
for(int j=i;j<l;j++){
if(str[i]<str[j]){
flg=1;
break;
}
}
if(flg==1) continue;
substr[nstr++]=str[i];
}
substr[nstr++]=str[l-1];
substr[nstr]='\0';
string ret=substr;
return ret;
}
};
[UVa The Seventh HCPC Semilive]
<A.One-Two-Three(C)>
#include<stdio.h>
#include<string.h>
int main(void){
int n,one,two;
char input[8];
scanf("%d",&n);
while(n--){
scanf("%s%*c",input);
if(strlen(input)==5){
puts("3");
continue;
}
one=0;
two=0;
if(input[0]=='o') one++;
if(input[1]=='n') one++;
if(input[2]=='e') one++;
if(input[0]=='t') two++;
if(input[1]=='w') two++;
if(input[2]=='o') two++;
printf("%d\n",(one<two)?2:1);
}
return 0;
}
<B.Counting Game(C)>
#include<stdio.h>
#include<string.h>
int have7(int n);
int main(void){
int n,m,k;
int count=0;
int i,j,num;
while(scanf("%d %d %d",&n,&m,&k) && n && m && k){
if(m==1){
count=0;
num=1;
for(i=0;count<k;i++){
if(num%7==0 || have7(num)==0) count++;
num+=2*(n-1);
}
num-=2*(n-1);
}else if(m==n){
count=0;
num=n;
for(i=0;count<k;i++){
if(num%7==0 || have7(num)==0) count++;
num+=2*(n-1);
}
num-=2*(n-1);
}else{
count=0;
num=m;
for(i=0;count<k;i++){
if(num%7==0 || have7(num)==0) count++;
num+=(i%2)?(m-1)*2:(n-m)*2;
}
num-=(--i%2?m-1:n-m)<<1;
}
printf("%d\n",num);
}
return 0;
}
int have7(int n){
char str[16];
sprintf(str,"%d\0",n);
if(strchr(str,'7')!=NULL) return 0;
return 1;
}
[UAPC 7th]
<A.Popularity Estimation(C)>
#include<stdio.h>
#include<string.h>
int main(void){
struct data{
char name[11];
unsigned int point;
unsigned char times[31];
}person[20];
unsigned int i,j,k,m,n,t,num;
while(scanf("%u%*c",&n) && n){
for(i=0;i<n;i++){
scanf("%s%*c",person[i].name);
person[i].point=0;
for(j=0;j<31;j++) person[i].times[j]=0;
scanf("%u%*c",&m);
for(j=0;j<m;j++){
scanf("%u%*c",&t);
person[i].times[t]=1;
}
}
for(i=0;i<31;i++){
num=0;
for(j=0;j<n;j++) num+=person[j].times[i];
for(j=0;j<n;j++) if(person[j].times[i]) person[j].point+=n-num+1;
}
num=0;
for(i=1;i<n;i++) if(person[i].point<person[num].point || (person[i].point==person[num].point && strcmp(person[i].name,person[num].name)<0) ) num=i;
printf("%u %s\n",person[num].point,person[num].name);
}
return 0;
}
<D.The Greatest Summer Contest(C)>
#include<stdio.h>
#define MIN(x,y) ((x<y)?(x):(y))
int main(void){
unsigned int math,algo,code;
unsigned int input[6],sum;
unsigned int i,j,k,min;
unsigned int contest,mcon,acon,ccon;
while(1){
for(i=0;i<6;i++) scanf("%u",&input[i]);
sum=input[0];
for(i=1;i<6;i++) sum+=input[i];
if(sum==0) break;
math=input[0]+input[3];
algo=input[1]+input[4];
code=input[2]+input[5];
mcon=math/3;
acon=algo/3;
ccon=code/3;
contest=mcon+acon+ccon;
math%=3;
algo%=3;
code%=3;
min=MIN(MIN(math,algo),code);
math-=min;
algo-=min;
code-=min;
contest+=min;
if(ccon>=1 && math==2 && algo==2) contest++;
else if(mcon>=1 && algo==2 && code==2) contest++;
else if(acon>=1 && code==2 && math==2) contest++;
printf("%u\n",contest);
}
return 0;
}
0 件のコメント:
コメントを投稿