1
1

yukicoder No.24 数当てゲーム 解説

Last updated at Posted at 2024-07-23

問題文

解説

いわれたとおりに素直に実装するタイプの問題。
まず、処理の都度残ったものの判定をする必要がある。
$ans_i$=解の選択肢に$i$が残っているか
$ans_i$=trueなら残っている
$ans_i$=falseなら残っていない
というものを作ろう。
今回は$R_i$で場合分けしよう。
・$R_i$がYESのとき
$A_i,b_i,c_i,d_i$以外をfalseにする
・$R_i$がNOのとき
$A_i,b_i,c_i,d_i$falseにする
これでただひとつtrueになったものを出力する。

C++での解答例

#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;cin>>n;
  vector<bool> ans(10,true);
  for(int i=0;i<n;i++){
    int a,b,c,d;string r;cin>>a>>b>>c>>d>>r;
    if(r=="YES")
      for(int j=0;j<10;j++){
        if(j==a||j==b||j==c||j==d)continue;
        ans[j]=false;
      }
    else{
      ans[a]=false;
      ans[b]=false;
      ans[c]=false;
      ans[d]=false;
    }
  }
  for(int i=0;i<10;i++)
    if(ans[i]){
      cout<<i<<endl;
      return 0;
    }
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1