AtCoder 生活　71日目

[前回](https://qiita.com/flandrescarlet237/items/0958d9e7c1cbe98c6ac5)

#71日目
今回は茶色diffの問題を1問解き、とバーチャル参加を2回し、ABC169に参加しました。

|問題|難易度|自力で解けた|かかった時間|
|:-:|:-:|:-:|---|---|
|ABC158|D|✕|114分21秒|

ABC168
![スクリーンショット 2020-05-31 12.58.54.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/606053/f4106a15-c7e5-7ddf-7f32-afb77b7358e7.png)
ABC167
![スクリーンショット 2020-05-31 17.44.22.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/606053/1e49a4c5-23bc-5cbc-2567-9d26e9cd285f.png)
ABC169
![スクリーンショット 2020-05-31 22.40.39.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/606053/846e19d4-7bf7-3d70-f752-2460260e9436.png)


##[ABC168](https://atcoder.jp/contests/abc168)

###A

```c++

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;

const int INF = 2e9;

int main(){
    int n;
    cin >> n;
    n %= 10;
    if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9 ) cout << "hon"  << endl;
    else if (n == 0 || n == 1 || n == 6 || n == 8 ) cout << "pon" << endl;
    else cout << "bon" << endl;
}

```

###B


```c++

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pil = pair<pii,int>;

const int INF = 2e9;

int main(){
    int  k;
    string s;
    cin >> k >> s;
    int t = s.size();
    if(k < t) cout << s.substr(0,k) << "..." << endl;
    else cout << s << endl;
}

```

###C

```c++

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;

const int INF = 2e9;
const double pi = 3.141592653589793238;

int main(){
    int a,b,h,m;
    cin >> a >> b >> h >> m;
    double s = h*30 + m*0.5;
    double t = m*6;
    double x = min(abs(s-t),(360 - abs(s-t)));
    double c = cos(x/180.0*pi);
    double y = a*a + b*b - 2*a*b*c;
    double ans = pow(y,0.5);
    cout << fixed << setprecision(10) << ans << endl; 
}

```


##[ABC167](https://atcoder.jp/contests/abc167)

###A

```c++

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;

const int INF = 2e9;

int main(){
    string s;
    string t;
    cin >> s >> t;
    int a = s.size();
    t = t.substr(0,a);
    if(s == t)cout << "Yes" << endl;
    else cout << "No" << endl;
}

```

###B


```c++

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pil = pair<pii,int>;

const int INF = 2e9;

int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int s = min(a,k);
    if(k>a)k-= a;
    else k = 0;
    int t = min(b,k);
    if(k>b)k-= b;
    else k = 0;
    int r = min(k,c);
    cout << s - r << endl;
}

```

###C

```c++

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;

const int INF = 2e9;

int main(){
    int n,m,x;
    cin >> n >> m >> x;
    vector c(n,0);
    vector<vector<int>> a(n,vector<int>(m));
    rep(i,n){
        cin >> c[i];
        rep(j,m) cin >> a[i][j];
    }
    int ans = INF;
    rep(i,1<<n){
        vector d(m,0);
        sum = 0;
        rep(j,n){
            if(i >> j & 1){
                sum += c[j];
                rep(s,m) d[s] += a[j][s];
            }
        }
        bool ok = true;
        rep(s,m)if(d[s] < x)ok = false;
        if(ok) ans = min(sum,ans);
    }
    if(ans != INF) cout << ans << endl;
    else cout << -1 << endl;
}

```


##[ABC169](https://atcoder.jp/contests/abc169)

###A

```c++

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;

const int INF = 2e9;

int main(){
    int a,b;
    cin >> a >> b;
    cout << a*b << endl;
}

```

##[ABC158_D](https://atcoder.jp/contests/abc158/tasks/abc158_d)

```c++

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pil = pair<pii,char>;

int main(){
    string s;
    cin >> s;
    int q;
    cin >> q;
    deque<char> que;
    rep(i,s.size()) que.push_back(s[i]);
    bool r = 0;
    rep(i,q){
        int a;
        cin >> a;
        if(a == 1){
            r = 1 - r;
        }
        else if(a == 2){
            int b;
            char c;
            cin >> b >> c;
            if(b == 1 && !r) que.push_front(c);
            if(b == 1 && r) que.push_back(c);
            if(b == 2 && !r) que.push_back(c);
            if(b == 2 && r) que.push_front(c);
        }
    }
    if(r) reverse(que.begin(),que.end());
    for(auto q : que){
        cout << q;
    }
    cout << endl;
}


```

解くのにかかった時間：114分21秒
感想：queueを使うかどうかが鍵


###最後に
今回のABCのC問題が何故解けなかったのかを徹底的に復習したい。
B問題はどうしたらオーバーフローを回避しつつ答えにたどり着けるのかを確認したい