AtCoder Beginner Contest 126~139 B問題埋め

ラムダ式と複数要素のソートを勉強しているのは必須だと感じました。

##[B - Good Distance](https://atcoder.jp/contests/abc133/tasks/abc133_b)
解説の回答のが正しいと思います。

```C++:C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<list>
#include<set>
#include<bitset>

#define rep(i,n) for(int i=0; i<(n); i++)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main() {
    int n, d;
    cin >> n >> d;
    
    int x[10][10]={0};
    rep(i, n){
        rep(j, d){
            cin >> x[i][j];
        }
    }
    
    int res=0;
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            double sum = 0.0f;
            rep(k, d){
                sum += pow(abs(x[i][k]-x[j][k]), 2);
            }
            
            sum = sqrt(sum);
            if(sum-(int)sum==0.0) res++;
        }
    }
    cout << res << endl;
     
    return 0;
}
```

##[B - Guidebook](https://atcoder.jp/contests/abc128/tasks/abc128_b)
AOJのITP2でtuple, get, ラムダ式を覚えていたので簡単にできました。

```C++:C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<list>
#include<set>
#include<bitset>

#define rep(i,n) for(int i=0; i<(n); i++)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main() {
    int n;
    cin >> n;
    
    vector<tuple<string, int, int>> vec(n);
    
    rep(i, n){
        string s;
        int p;
        cin >> s >> p;
        vec[i] = make_tuple(s, p, i+1);
    }
    sort(vec.begin(), vec.end(), []( const auto &x, const auto &y )
    {
        return get<0>( x ) == get<0>( y ) ? get<1>( x ) > get<1>( y ) : get<0>( x ) < get<0>( y );
    });
    
    rep(i, n){
        cout << get<2>(vec[i]) << endl;
    }
    
    return 0;
}
```

##[B - Power Socket](https://atcoder.jp/contests/abc139/tasks/abc139_b)

```C++:C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<list>
#include<set>
#include<bitset>

#define rep(i,n) for(int i=0; i<(n); i++)
#define fix(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main() {
    int a, b;
    cin >> a >> b;
    
    int sum=1;
    int res=0;
    while(b>sum){
        sum += (a-1);
        res++;
    }
    cout << res << endl;

    return 0;
}
```

##[B - Resistors in Parallel](https://atcoder.jp/contests/abc138/tasks/abc138_b)

```C++:C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<list>
#include<set>
#include<bitset>
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define fix_setprec(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9
 
using namespace std;
using ll =long long;
using P = pair<int,int>;
 
int main() {
    int n;
    cin >> n;
    
    double sum=0.0f;
    rep(i, n){
        double a;
        cin >> a;
        sum += 1.0f/a;
    }
    cout << fix_setprec(10) << 1.0f/sum << endl;
 
    return 0;
}
```

##[B - One Clue](https://atcoder.jp/contests/abc137/tasks/abc137_b)

```C++:C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<list>
#include<set>
#include<bitset>

#define rep(i,n) for(int i=0; i<(n); i++)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main() {
    int k, x;
    cin >> k >> x;
    
    for(int i=x-k+1; i<k+x; i++){
        cout << ' ' << i;
    }

    return 0;
}
```

##[B - 0 or 1 Swap](https://atcoder.jp/contests/abc135/tasks/abc135_b)

```C++:C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<list>
#include<set>
#include<bitset>

#define rep(i,n) for(int i=0; i<(n); i++)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main() {
    int n;
    cin >> n;
    int A[50]={0};
    int res=0;
    rep(i, n){
        cin >> A[i];
        if(A[i]!=i+1) res++;
    }
    
    if(res>2) cout << "NO" << endl;
    else cout << "YES" << endl;

    return 0;
}
```

##[B - Golden Apple](https://atcoder.jp/contests/abc134/tasks/abc134_b)

```C++:C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<list>
#include<set>
#include<bitset>

#define rep(i,n) for(int i=0; i<(n); i++)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main() {
    int n, d;
    cin >> n >> d;
    int res=0, pos=0;
    while(pos<n){
        pos=d+pos+1+d;
        res++;
    }
    cout << res << endl;
    return 0;
}
```

##[B - Ordinary Number](https://atcoder.jp/contests/abc132/tasks/abc132_b)

```C++:C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<list>
#include<set>
#include<bitset>

#define rep(i,n) for(int i=0; i<(n); i++)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main() {
    int n;
    cin >> n;
    int p[20]={0};
    rep(i, n){
        cin >> p[i];
    }
    int res=0;
    for(int i=1; i<n-1; i++){
        if(p[i-1]<p[i] && p[i]<p[i+1]) res++;
        if(p[i-1]>p[i] && p[i]>p[i+1]) res++;
    }
    cout << res << endl;
    return 0;
}
```

##[B - Bite Eating](https://atcoder.jp/contests/abc131/tasks/abc131_b)

```C++:C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<list>
#include<set>
#include<bitset>

#define rep(i,n) for(int i=0; i<(n); i++)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main() {
    int n, l;
    cin >> n >> l;
    
    int min_value=1e9+1;
    int value=0;
    for(int i=l; i<l+n; i++){
        if(abs(i)<abs(min_value)) min_value = i;
        value+=i;
    }
    cout << value-min_value << endl;
    
    return 0;
}
```

##[B - Bounding](https://atcoder.jp/contests/abc130/tasks/abc130_b)

```C++:C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<list>
#include<set>
#include<bitset>

#define rep(i,n) for(int i=0; i<(n); i++)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main() {
    int n, x;
    cin >> n >> x;
    
    int value=0;
    int res=1;
    for(int i=0; i<n; i++){
        int l;
        cin >> l;
        value+=l;
        if(value<=x) res++;
    }
    cout << res << endl;
    
    return 0;
}
```

##[B - Balance](https://atcoder.jp/contests/abc129/tasks/abc129_b)

```C++:C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<list>
#include<set>
#include<bitset>

#define rep(i,n) for(int i=0; i<(n); i++)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main() {
    int n;
    cin >> n;
    
    int w[100]={0};
    int sum1_w=0;
    rep(i, n){
        cin >> w[i];
        sum1_w+=w[i];
    }
    
    int value=sum1_w;
    int sum2_w=0;
    for(int i=0; i<n-1; i++){
        sum1_w -= w[i];
        sum2_w += w[i];
        value = min(value, abs(sum1_w-sum2_w));
    }
    cout << value << endl;
    
    return 0;
}
```

##[B - Algae](https://atcoder.jp/contests/abc127/tasks/abc127_b)

```C++:C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<list>
#include<set>
#include<bitset>

#define rep(i,n) for(int i=0; i<(n); i++)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main() {
    int r, d, x2000;
    cin >> r >> d >> x2000;
    
    for(int i=1; i<=10; i++){
        x2000 = r * x2000 - d;
        cout << x2000 << endl;
    }
    
    return 0;
}
```

##[B - YYMM or MMYY](https://atcoder.jp/contests/abc126/tasks/abc126_b)

```C++:C++
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<list>
#include<set>
#include<bitset>

#define rep(i,n) for(int i=0; i<(n); i++)
#define fixed_setprecision(n) fixed << setprecision((n))
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main() {
    string s;
    cin >> s;
    
    int front_value = atoi(s.substr(0, 2).c_str());
    int back_value = atoi(s.substr(2, 2).c_str());
    
    if(0<front_value && front_value<13){
        if(0<back_value && back_value<13){
            cout << "AMBIGUOUS" << endl;
        }else{
            cout << "MMYY" << endl;
        }
    }else{
        if(0<back_value && back_value<13){
            cout << "YYMM" << endl;
        }else{
            cout << "NA" << endl;
        }
    }
    
    return 0;
}
```