2011/09/09

Codeforces Beta Round #83 & #86 (Div.2) Report

I write about two competition because I haven't written codeforces #83.

<Codeforces Beta Round #83 (Div.2)>
Because I was tired, I could solve only one problem!

I solved A, at 00:04. And it's all of this contest.

B: I think the case is YES if Max of bit is smaller than twice of second-max. However, It's wrong at system test!

And then, I was very sleepy, and I began to be sleep.

Score=492, Standings=465/1179.

<Codeforces Beta Round #86 (Div.2)>
I think I'm slumpa now!

A: I didn't understand first, however, second reading made me to understand. I solved at 00:04, and it is all accepted of this contest.

B: I read and tried to solve. I submitted, and WA on pretest. Then, I notice my reading miss. So, I gave up this. If you want to know how I made miss, please read source.

C: I solved, however, I forgot
"A sentence is either exactly one valid language word or exactly one statement.".
So, I get WA. I get accepted after the contest, and the source is correct source.

E: I think, it is Fermat's 4N+1 theorem. I write my code very simply, it was TLE. If I had more time, I try other algorithm.

Score=492, Standings=377/1337, Rate:1418->1452.
This contest was a little difficult??

[#83 A(Correct)]

#include<stdio.h>

int main(void){
  int hh,mm;
  scanf("%d:%d",&hh,&mm);
  do{
    mm++;
    if(mm==60){
      mm=0;
      hh++;
    }
    if(hh==24) hh=0;
  }while(!(mm/10==hh%10 && hh/10==mm%10));
  printf("%02d:%02d\n",hh,mm);
  return 0;
}


[#83 B(Wrong)]

#include<stdio.h>
#include<stdlib.h>
#define MAX(x,y) (((x)<(y))?(y):(x))

int main(void){
  unsigned int *data;
  unsigned int n,max=0;
  unsigned int i,j,k;

  scanf("%u",&n);
  data=(unsigned int *)calloc(n,sizeof(unsigned int));
  for(i=0;i<n;i++) scanf("%u",data+i);
  for(i=0;i<n;i++) max=MAX(max,*(data+i));
  for(i=0;i<n;i++){
    if(max<=*(data+i)) continue;
    if(max<2*(*(data+i))){
      puts("YES");
      return 0;
    }
  }
  puts("NO");
  free(data);
  return 0;
}


[#86 A(Correct)]

#include<stdio.h>

typedef unsigned int u_int;

int main(void){
  u_int i,n,k;
  scanf("%u",&k);
  scanf("%u",&n);
  for(i=0;n!=1;i++,n/=k){
    if(n%k!=0){
      puts("NO");
      return 0;
    }
  }
  printf("YES\n%u\n",i-1);
  return 0;
}



[#86 B(Wrong)]

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct {
  char name[11];
  int group;
} mem;

void ssort(mem member[],int size);

int main(void){
  mem member[16];
  char name[2][11];
  int n,m,i,j,k,g=1;
  int tmpg,num[2];
  scanf("%u %u",&n,&m);
  for(i=0;i<n;i++) scanf("%s%*c",member[i].name);
  for(i=0;i<n;i++) member[i].group=0;
  ssort(member,n);
  for(i=0;i<m;i++){
    scanf("%s %s%*c",name[0],name[1]);
    for(j=0;j<n;j++){
      if(strcmp(name[0],member[j].name)==0) num[0]=j;
      else if(strcmp(name[1],member[j].name)==0) num[1]=j;
    }
    if(member[num[0]].group==0 && member[num[1]].group==0){
      member[num[0]].group=g;
      member[num[1]].group=g;
      g++;
    }else if(member[num[0]].group==0){
      member[num[0]].group=member[num[1]].group;
    }else if(member[num[1]].group==0){
      member[num[1]].group=member[num[0]].group;
    }else{
      tmpg=member[num[1]].group;
      for(j=0;j<n;j++){
if(member[j].group==tmpg) member[j].group=member[num[0]].group;
      }
    }
  }
  g=0;
  for(i=0;i<n;i++){
    if(member[i].group==0){
      g++;
    }else if(member[i].group>0){
      g++;
      for(j=i+1;j<n;j++){
if(member[j].group==member[i].group) member[j].group=-1;
      }
    }
  }
  printf("%d\n",g);
  for(i=0;i<n;i++) if(member[i].group>=0) puts(member[i].name);
  return 0;
}

void ssort(mem member[],int size){
  int i,j,place;
  mem tmp;
  for(i=0;i<size;i++){
    place=i;
    for(j=i+1;j<size;j++) if(strcmp(member[place].name,member[j].name)>0) place=j;
    tmp=member[i];
    member[i]=member[place];
    member[place]=tmp;
  }
}

[#86 C(Correct)]


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int types(char *str);

int main(void){
  char str[100002],*p;
  int gender,now,tmp;
  int flg=0,inwhile=0;

  fgets(str,sizeof(str),stdin);
  str[strlen(str)-1]='\0';
  p=strtok(str," ");
  tmp=types(p);
  if(tmp==0){
    puts("NO");
    return 0;
  }
  gender=tmp%2;
  now=(tmp-1)/2;
  if(now==1) flg=1;
  while(1){
    p=strtok(NULL," ");
    if(p==NULL) break;
    inwhile=1;
    tmp=types(p);
    if(tmp==0 || tmp%2!=gender || now>(tmp-1)/2 || (now==1 && (tmp-1)/2==1)){
      puts("NO");
      return 0;
    }
    now=(tmp-1)/2;
    if(now==1) flg=1;
  }
  if(flg==1 || inwhile==0) puts("YES");
  else puts("NO");
  return 0;
}

int types(char *str){
  int len;
  len=strlen(str);
  if(len<3) return 0;
  if(strcmp(str+len-4,"lios")==0) return 1;
  if(strcmp(str+len-5,"liala")==0) return 2;
  if(strcmp(str+len-3,"etr")==0) return 3;
  if(strcmp(str+len-4,"etra")==0) return 4;
  if(strcmp(str+len-6,"initis")==0) return 5;
  if(strcmp(str+len-6,"inites")==0) return 6;
  return 0;
}


[#86 E(Time Limit Exceeded)]

#include<stdio.h>

int prime(int p){
  int i;
  if(p==1) return 0;
  for(i=3;i*i<=p;i+=2) if(p%i==0) return 0;
  return 1;
}

int main(void){
  int l,r,i,j,k,count=0;
  scanf("%d %d",&l,&r);
  if(l<=2 && r>=2) count++;
  switch(l%4){
  case 0:
    l++;
    break;
  case 2:
    l+=3;
    break;
  case 3:
    l+=2;
    break;
  }
  for(i=l;i<=r;i+=4) if(prime(i)) count++;
  printf("%d\n",count);
  return 0;
}

0 件のコメント:

コメントを投稿