結果
問題 | No.594 壊れた宝物発見機 |
ユーザー |
![]() |
提出日時 | 2019-04-16 13:15:34 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 116 ms / 2,000 ms |
コード長 | 3,255 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 31,744 KB |
実行使用メモリ | 25,476 KB |
平均クエリ数 | 25.05 |
最終ジャッジ日時 | 2024-07-16 17:08:02 |
合計ジャッジ時間 | 3,888 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
#include <float.h>#include <limits.h>#include <math.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>// 内部定数#define D_VAL_MIN -100 // 最小値#define D_VAL_MAX 100 // 最大値#define D_DIM_CNT 3 // 次元数// 内部変数static FILE *szpFpI; // 入力static int si1Len[D_VAL_MAX - D_VAL_MIN + 5]; // 距離static int si1Pos[D_DIM_CNT]; // 宝物の座標// 内部変数 - テスト用#ifdef D_TESTstatic int siRes;static FILE *szpFpA;static int siTNo;#endif// 出力intfOut(char *pcpLine // <I> 1行){char lc1Buf[1024];#ifdef D_TESTfgets(lc1Buf, sizeof(lc1Buf), szpFpA);if (strcmp(lc1Buf, pcpLine)) {siRes = -1;}#elseprintf("%s", pcpLine);fflush(stdout);#endifreturn 0;}// 距離 - 取得intfGetLen(int piDNo // <I> 次元 0~, int piVal // <I> 値){int i;char lc1Buf[1024], lc1Out[1024];// 対象位置int liVal = piVal - D_VAL_MIN;// 未取得if (si1Len[liVal] < 0) {// 質問strcpy(lc1Out, "?");for (i = 0; i < D_DIM_CNT; i++) {if (i == piDNo) {sprintf(lc1Buf, " %d", piVal);}else {strcpy(lc1Buf, " 0");}strcat(lc1Out, lc1Buf);}strcat(lc1Out, "\n");fOut(lc1Out);// 回答fgets(lc1Buf, sizeof(lc1Buf), szpFpI);sscanf(lc1Buf, "%d", &si1Len[liVal]);}return si1Len[liVal];}// 実行メインintfMain(){int i;char lc1Buf[1024], lc1Out[1024];// 宝物の座標 - セットfor (i = 0; i < D_DIM_CNT; i++) {// 初期化int liMin = D_VAL_MIN;int liMax = D_VAL_MAX;memset(si1Len, -1, sizeof(si1Len));// 算出while (1) {int liHalf = (liMax - liMin) / 2;// 距離 - 取得int liLenMin = fGetLen(i, liMin);int liLenMax = fGetLen(i, liMax);if (liHalf < 1) {if (liLenMin < liLenMax) {si1Pos[i] = liMin;}else {si1Pos[i] = liMax;}break;}else {if (liLenMin < liLenMax) {liMax -= liHalf;}else if (liLenMin > liLenMax) {liMin += liHalf;}else {si1Pos[i] = liMin + liHalf;break;}}}}// 出力strcpy(lc1Out, "!");for (i = 0; i < D_DIM_CNT; i++) {sprintf(lc1Buf, " %d", si1Pos[i]);strcat(lc1Out, lc1Buf);}strcat(lc1Out, "\n");fOut(lc1Out);return 0;}// 1回実行intfOne(){int liRet;char lc1Buf[1024];// 入力 - セット#ifdef D_TESTsprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);szpFpI = fopen(lc1Buf, "r");sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);szpFpA = fopen(lc1Buf, "r");siRes = 0;#elseszpFpI = stdin;#endif// 実行メインliRet = fMain();// 残データ有無#ifdef D_TESTlc1Buf[0] = '\0';fgets(lc1Buf, sizeof(lc1Buf), szpFpA);if (strcmp(lc1Buf, "")) {siRes = -1;}#endif// テストファイルクローズ#ifdef D_TESTfclose(szpFpI);fclose(szpFpA);#endif// テスト結果#ifdef D_TESTif (siRes == 0) {printf("OK %d\n", siTNo);}else {printf("NG %d\n", siTNo);}#endifreturn 0;}// プログラム開始intmain(){#ifdef D_TESTint i;for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {siTNo = i;fOne();}#elsefOne();#endifreturn 0;}