2011/08/22

Codechef 2011 August Cook-off report

I forgot this contest, so I took part in this contest only last one hour.

First, I solved "Open the Dragon Scroll". Read once, and I wrote code. It's very simple! I solved this with using only 10 minutes!

Second, I solved "Vote for the Noodle Soup". It looks like "Popular Rice Recipe" which is one of May(2011) cook-off problem. However, it's not! First, I think I can solve with get max. But, if +3 and -2, the answer is 4! So, I retry to think algorithm and solve it with 35 minutes.

I think other problems is difficult for me. So, I solved only this two problems.

Score:2/5,Rank:140. Rate:1051.821->1137.42(Rank:269).
[Open the Dragon Scroll]
#include<stdio.h>

int main(void){
  unsigned int n,a,b,p;
  unsigned int count;
  unsigned int out;
  unsigned int i;
  scanf("%u",&p);
  while(p--){
    scanf("%u %u %u",&n,&a,&b);
    count=0;
    out=0;
    for(i=0;i<n;i++) count+=((a>>i)&1)+((b>>i)&1);
    if(count>n) count-=2*(count-n);
    for(i=0;i<count;i++) out+=(1<<n-i-1);
    printf("%u\n",out);
  }
  return 0;
}

[Vote for the Noodle Soup]
#include<stdio.h>
#include<stdlib.h>

int main(void){
  int vote[1000];
  char pm;
  int input;
  unsigned int n;
  unsigned int i;
  unsigned int count;

  while(scanf("%u%*c",&n) && n){
    count=0;
    for(i=0;i<n;i++){
      scanf("%c %d%*c",&pm,&input);
      input+=(pm=='P')?-1:1;
      vote[i]=input;
    }
    for(i=0;i<n;i++){
      if(count<abs(vote[i])){
count=abs(vote[i]);
      }else{
if(abs(vote[i])%2==count%2) continue;
count++;
      }
    }
    printf("%u\n",count);
  }
  return 0;
}

0 件のコメント:

コメントを投稿