carry a cheese 0107
- 方針:
- 筋道:バブルソートを使ってみたかった.まあ数が3つしかないのでソートとかしなくていいとおもう.
3種類の対角線の長さを計算して円の半径よりも小さい値が一つでもあればおkである.バブルソートはほぼコピペ
- code:.c
//carry a cheese 0107 AOJ #include <stdio.h> #define MAX 10000 int BubSort(int cheese[], int n) { int i, j, temp; for (i = 0; i < n - 1; i++) { for (j = n - 1; j > i; j--) { if (cheese[j - 1] > cheese[j]) { /* 前の要素の方が大きかったら */ temp = cheese[j]; /* 交換する */ cheese[j] = cheese[j - 1]; cheese[j - 1]= temp; } } } } int main() { int cheese[3]; //チーズのx,y,h int n; //入り口の個数 int r[MAX]; //それぞれの入り口の半径 int i,j; while (1) { scanf ("%d %d %d", &cheese[0], &cheese[1], &cheese[2]); if (cheese[0]==0 && cheese[1]==0 && cheese[2]==0) break; scanf ("%d",&n); for (i = 0; i < n; i++){ scanf ("%d",&r[i]); } BubSort(cheese, 3); for (j = 0; j < n; j++){ if (cheese[0]*cheese[0] + cheese[1]*cheese[1] < (2*r[j]) * (2*r[j]) ) { printf ("OK\n"); }else printf ("NA\n"); } } return 0; }