LoginSignup
0
0

More than 3 years have passed since last update.

Atcorder157 A~C問題 C++

Last updated at Posted at 2020-03-07

ABC157
https://atcoder.jp/contests/abc157

A問題

image.png

A問題.c++
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
const ll INF = 1e9 + 7;
typedef pair<int,int> P;// pair型は2つの値の組を表せる

int main(){
    int N; cin >> N;
    int ans=0;
    if (N%2==0) ans=N/2;
    else ans=N/2+1;
    cout << ans;
}

B問題

image.png

B問題.c++
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
const ll INF = 1e9 + 7;
typedef pair<int,int> P;// pair型は2つの値の組を表せる

int main(){
    int boo[3][3]; //ここで全ての値をfalseにすることはできない!
    int A[3][3]; //int型の記録をすることができるメモリ領域を確保しただけ!

    rep(i,3)rep(j,3){
        int a; cin >> a;
        A[i][j]=a;
        boo[i][j]=false; //ここで全ての値をfalseにする!
    }

    int N; cin >> N;
    rep(i,N){
        int b; cin >> b;
        rep(j,3)rep(k,3){
            if (A[j][k]==b) boo[j][k]=true;
        }
    }

    bool ans=false;
    // true falseの一致を確かめる時、&&でするのが直感的にいい!
    rep(i,3){
        if (boo[i][0] && boo[i][1] && boo[i][2]) ans=true;
        if (boo[0][i] && boo[1][i] && boo[2][i]) ans=true;
    }
    if (boo[0][0] && boo[1][1] && boo[2][2]) ans=true;
    if (boo[0][2] && boo[1][1] && boo[2][0]) ans=true;

    if(ans) cout << "Yes";
    else cout << "No";
}

C問題

image.png

C問題.c++
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
const ll INF = 1e9 + 7;
typedef pair<int,int> P;// pair型は2つの値の組を表せる

int main(){
    int n,m; cin >> n >> m; //桁数n,条件がm個
    vector<P> p(m);
    //p[i].firstが左から~桁目
    //p[i].secondがその桁の数値
    rep(i,m) cin >> p[i].first >> p[i].second;
    //候補0~999を試す
    rep(x,1000){
        string s=to_string(x);
        int keta=s.length();

        if (keta!=n) continue;
        bool ok=true;
        rep(i,m){
            if (s[p[i].first-1]!=p[i].second+'0') ok=false;
        }
        if(ok){
            cout << x << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;

}
0
0
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
0
0