結果

問題 No.202 1円玉投げ
ユーザー akakimidori
提出日時 2018-08-30 04:26:26
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 67 ms / 5,000 ms
コード長 947 bytes
コンパイル時間 250 ms
コンパイル使用メモリ 22,144 KB
実行使用メモリ 32,896 KB
最終ジャッジ日時 2024-12-22 11:33:41
合計ジャッジ時間 2,878 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘run’:
main.c:20:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |   scanf("%d",&n);
      |   ^~~~~~~~~~~~~~
main.c:33:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   33 |     scanf("%d%d",&t.x,&t.y);
      |     ^~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

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

#define M 2000

#define POS(i,j) ((i)*(M+1)+(j))

typedef struct point2d{
  int x,y;
} point;

int distance(const point *a,const point *b){
  int dx=a->x-b->x;
  int dy=a->y-b->y;
  return dx*dx+dy*dy;
}

void run(void){
  int n;
  scanf("%d",&n);
  const int m=M;
  point *bucket=(point *)calloc((m+1)*(m+1),sizeof(point));
  int i,j;
  for(i=0;i<=m;i++){
    for(j=0;j<=m;j++){
      bucket[POS(i,j)].x=-20;
      bucket[POS(i,j)].y=-20;
    }
  }
  int cnt=0;
  while(n--){
    point t;
    scanf("%d%d",&t.x,&t.y);
    int x=t.x/10;
    int y=t.y/10;
    int flag=1;
    int i,j;
    for(i=-2;i<=2;i++){
      if(!(0<=x+i && x+i<=m)) continue;
      for(j=-2;j<=2;j++){
	if(!(0<=y+j && y+j<=m)) continue;
	if(distance(bucket+POS(x+i,y+j),&t)<20*20){
	  flag=0;
	}
      }
    }
    if(flag){
      cnt++;
      bucket[POS(x,y)]=t;
    }
  }
  printf("%d\n",cnt);
}

int main(void){
  run();
  return 0;
}
0