AtCoder Beginner Contest 179

题目链接

A - Plural Form

/*
 * @Author       : nonameless
 * @Date         : 2020-09-19 20:00:41
 * @LastEditors  : nonameless
 * @LastEditTime : 2020-09-19 20:05:21
 */
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define sz(x) (int)x.size()
#define toStr(name) (#name)
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
const double eps = 1e-6;
const double PI  = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll LNF  = 0x3f3f3f3f3f3f3f3f;
inline int gcd(int a, int b) { return b ? gcd(b,a % b):a;}
inline ll  gcd(ll  a, ll  b) { return b ? gcd(b,a % b):a;}
inline int lcm(int a, int b) { return a * b / gcd(a, b); }

template<class T>
inline void read(T &x){
    x = 0;
    int f = 1;
    char c = getchar();
    while(c < '0' || c > '9')   { if(c == '-') f = -1;  c = getchar(); }
    while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
    x = x * f;
}

template<class T>
inline void out(string a, T x){ cout << a << " = " << x << endl; }


int main(){

    string s; cin >> s;
    int len = sz(s);
    if(s[len - 1] == 's') s = s + "es";
    else s = s + 's';
    cout << s << endl;
    return 0;
}

B - Go to Jail

/*
 * @Author       : nonameless
 * @Date         : 2020-09-19 20:05:42
 * @LastEditors  : nonameless
 * @LastEditTime : 2020-09-19 20:06:35
 */
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define sz(x) (int)x.size()
#define toStr(name) (#name)
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
const double eps = 1e-6;
const double PI  = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll LNF  = 0x3f3f3f3f3f3f3f3f;
inline int gcd(int a, int b) { return b ? gcd(b,a % b):a;}
inline ll  gcd(ll  a, ll  b) { return b ? gcd(b,a % b):a;}
inline int lcm(int a, int b) { return a * b / gcd(a, b); }

template<class T>
inline void read(T &x){
    x = 0;
    int f = 1;
    char c = getchar();
    while(c < '0' || c > '9')   { if(c == '-') f = -1;  c = getchar(); }
    while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
    x = x * f;
}

template<class T>
inline void out(string a, T x){ cout << a << " = " << x << endl; }


int main(){

    int n; cin >> n;
    int cnt = 0, mark = 0;
    for(int i = 1; i <= n; i ++){
        int x, y; cin >> x >> y;
        if(x == y) cnt ++;
        else cnt = 0;
        if(cnt == 3) mark = 1;
    }
    if(mark == 1) puts("Yes");
    else puts("No");
    return 0;
}

C - A x B + C

/*
 * @Author       : nonameless
 * @Date         : 2020-09-19 20:07:49
 * @LastEditors  : nonameless
 * @LastEditTime : 2020-09-19 20:09:15
 */
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define sz(x) (int)x.size()
#define toStr(name) (#name)
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
const double eps = 1e-6;
const double PI  = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll LNF  = 0x3f3f3f3f3f3f3f3f;
inline int gcd(int a, int b) { return b ? gcd(b,a % b):a;}
inline ll  gcd(ll  a, ll  b) { return b ? gcd(b,a % b):a;}
inline int lcm(int a, int b) { return a * b / gcd(a, b); }

template<class T>
inline void read(T &x){
    x = 0;
    int f = 1;
    char c = getchar();
    while(c < '0' || c > '9')   { if(c == '-') f = -1;  c = getchar(); }
    while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
    x = x * f;
}

template<class T>
inline void out(string a, T x){ cout << a << " = " << x << endl; }


int main(){

    int n; cin >> n;
    ll ans = 0;
    for(int a = 1; a <= n; a ++)
        for(int b = 1; b <= n / a; b ++){
            int t = a * b;
            if(n - t > 0) ans ++;
        }

    cout << ans << endl;

    return 0;
}

D - Leaping Tak

思路:

\(f[i]\) 表示走到 \(i\) 的方案数。

那么对于一个线段 \([a, b]\),显然:\(f[i] = f[i - b] + f[i-b+1] +...+f[i-a]\)

显然这是一个关于 \(f\) 的前缀和数组。所以再加一个 \(sum\) 数组可以在线性时间内求出。

代码:
/*
 * @Author       : nonameless
 * @Date         : 2020-09-19 20:19:51
 * @LastEditors  : nonameless
 * @LastEditTime : 2020-09-19 20:30:48
 */
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define sz(x) (int)x.size()
#define toStr(name) (#name)
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
const double eps = 1e-6;
const double PI  = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll LNF  = 0x3f3f3f3f3f3f3f3f;
inline int gcd(int a, int b) { return b ? gcd(b,a % b):a;}
inline ll  gcd(ll  a, ll  b) { return b ? gcd(b,a % b):a;}
inline int lcm(int a, int b) { return a * b / gcd(a, b); }

template<class T>
inline void read(T &x){
    x = 0;
    int f = 1;
    char c = getchar();
    while(c < '0' || c > '9')   { if(c == '-') f = -1;  c = getchar(); }
    while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
    x = x * f;
}

template<class T>
inline void out(string a, T x){ cout << a << " = " << x << endl; }

const int K = 15, N = 2e5 + 10;

const int mod = 998244353;

ll f[N], sum[N];
PII s[K];

int main(){

    int n, k; cin >> n >> k;
    for(int i = 1; i <= k; i ++) cin >> s[i].x >> s[i].y;
    f[1] = 1;
    sum[1] = 1;
    for(int i = 2; i <= n; i ++){
        for(int j = 1; j <= k; j ++){
            int a = s[j].x, b = s[j].y;
            if(a >= i) continue;
            a = i - a;
            b = max(0, i - b - 1);
            f[i] = (f[i] + sum[a] - sum[b] + mod) % mod;
        }
        sum[i] = (sum[i - 1] + f[i]) % mod;
    }
    cout << f[n] << endl;
    return 0;
}

E - Sequence Sum

思路:

打表以下可以发现循环节,所以直接暴力找循环节就好。

代码:
/*
 * @Author       : nonameless
 * @Date         : 2020-09-19 20:36:30
 * @LastEditors  : nonameless
 * @LastEditTime : 2020-09-19 21:26:22
 */
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define sz(x) (int)x.size()
#define toStr(name) (#name)
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
const double eps = 1e-6;
const double PI  = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll LNF  = 0x3f3f3f3f3f3f3f3f;
inline int gcd(int a, int b) { return b ? gcd(b,a % b):a;}
inline ll  gcd(ll  a, ll  b) { return b ? gcd(b,a % b):a;}
inline int lcm(int a, int b) { return a * b / gcd(a, b); }

template<class T>
inline void read(T &x){
    x = 0;
    int f = 1;
    char c = getchar();
    while(c < '0' || c > '9')   { if(c == '-') f = -1;  c = getchar(); }
    while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
    x = x * f;
}

template<class T>
inline void out(string a, T x){ cout << a << " = " << x << endl; }


int main(){

    ll n, x, m, a;
    cin >> n >> x >> m;
    vector<ll> vec;
    map<ll, int> mp;
    ll idx = n;
    ll ans = 0;
    a = x;
    int yy = n;
    for(int i = 1; i <= n; i ++){
        yy = i;
        if(mp[a]) { idx = mp[a] - 1; break; }
        mp[a] = i;
        ans += a;
        vec.pb(a);
        a = a * a  % m;
    }
    vector<ll> vec2;
    for(int i = 0; i < sz(vec); i ++) if(i >= idx) vec2.pb(vec[i]);
    ll cnt = n - yy + 1;
    ll sum = 0;
    for(auto it : vec2) sum += it;
    if(sz(vec2)){
        ans += cnt / sz(vec2) * sum;
        for(int i = 0; i < cnt % sz(vec2); i ++) ans += vec2[i];
    } 
    cout << ans << endl;
    
    return 0;
}
posted @ 2020-09-19 21:37  nonameless  阅读(223)  评论(2编辑  收藏  举报