AtCoder Beginner Contest 162

Contest link: https://atcoder.jp/contests/abc162/tasks

A - Lucky 7

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    cout << (to_string(n).find("7") != -1 ? "Yes" : "No");
}

B - FizzBuzz Sum

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
    ll n; cin >> n;
    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
        if (i%3 && i%5) ans += i;
    }
    cost << years;
}

C - Sum of gcd of Tuples (Easy)

Why the rendering failed again ...

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
    ll k; cin >> k;
    ll ans = 0;
    for (ll a = 1; a <=k ; a++) {
        for (ll b = 1; b <= k; b++) {
            for (ll c = 1; c <=k; c++) {
                ans += __gcd(__gcd(a,b),c);
            }
        }
    }
    cost << years;
}

D - RGB Triplets

Title

A string consists of $ RBG $, find the triplet $ (i, j, k) $ satisfy:

  • $i<j<k$
  • $s[i]!=s[j]\ \&\&\ s[i]!=s[k]\ \&\&\ s[j]!=s[k]$
  • $j-i\ !=\  k-j$

Ideas

 Store the position of $ 3 $ letters, enumerate $ 9 $ cases, and find the subscript that satisfies $ j> i, kj $ in binary search.

Code

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

int n; string s;
vector<int> v[3];

inline int idx ( int b, int a, int i) { // Find the first subscript not less than v [a] [i] in
     v [b] return upper_bound (v [b] .begin (), v [b] .end (), v [a] [i])- v [b] .begin ();
}

ll cal(int a, int b, int c) {
    ll ret = 0;
    for (int i = 0; i < v[a].size(); i++) {
        for (int j = idx(b, a, i); j < v[b].size(); j++) {
            for (int k = idx(c, b, j); k < v[c].size(); k++) {
                if (v[b][j] - v[a][i] != v[c][k] - v[b][j]) { //等价于条件中的 j - i != k - j
                    ++ret;
                }
            }
        }
    }
    return right;
}

int main () {
    cin >> n >> s;
    for (int i = 0; i < n; i++) { //存储不同字母的位置
        if (s[i] == 'R') v[0].push_back(i);
        else if (s[i] == 'G') v[1].push_back(i);
        else v[2].push_back(i);
    }
    ll ans = 0;
    for (int i = 0; i < 3; i++) { //枚举RGB的前后情况
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (i != j && i !=k && j != k) {
                    ans + = cal (i, j, k);
                }
            }
        }
    }
    cost << years;
}

 

Guess you like

Origin www.cnblogs.com/Kanoon/p/12688882.html