結果

問題 No.355 数当てゲーム(2)
ユーザー face4face4
提出日時 2018-08-28 21:38:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,004 bytes
コンパイル時間 555 ms
コンパイル使用メモリ 68,580 KB
実行使用メモリ 35,784 KB
最終ジャッジ日時 2023-09-23 16:16:33
合計ジャッジ時間 7,165 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;

int hit = 0, blow = 0;

int getNext(int arr[4], int pos){
    int next = (arr[pos] + 1)%10;
    while(1){
        bool judge = true;
        for(int i = 0; i < 4; i++)  if(arr[i] == next)  judge = false;
        if(judge)   break;
        else        next = (next+1)%10;
    }
    return next;
}

void ask(int arr[4]){
    cout << arr[0] << " " << arr[1] << " " << arr[2] << " " << arr[3] << flush;
    cin >> hit >> blow;
    if(hit == 4)    exit(0);
}

int main(){
    int arr[4];
    arr[0] = 0, arr[1] = 1, arr[2] = 2, arr[3] = 3;

    ask(arr);
    int before = hit + blow;

    int now = 0;

    while(before != 4){
        int tmp = arr[now];
        arr[now] = getNext(arr, now);
        ask(arr);
        if(hit + blow < before){
            arr[now] = tmp;
            now++;
            before = hit + blow;
        }
    }

    sort(arr, arr+4);

    do{
        ask(arr);
    }while(next_permutation(arr, arr+4));

    return 0;
}
0