首页 > 其他 > 详细

AtCoder Beginner Contest 084

时间:2021-02-09 10:16:49      阅读:21      评论:0      收藏:0      [点我收藏+]

A - New Year

#include<bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;
typedef long long LL;
int n;
int main(){
    cin >> n;
    cout << 24 - n + 24 << endl;
    return 0;
}

B - Postal Code

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;
typedef long long LL;
int a, b;
int main() {
    cin >> a >> b;
    string s;
    cin >> s;
    if (s[a] != ‘-‘) {
        cout << "No" << endl;
        return 0;
    }
    if (s.size() != a + b+1) {
        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i < a; i++) {
        if (s[i] < ‘0‘ || s[i] > ‘9‘) {
            cout << "No" << endl;
            return 0;
        }
    }
    for (int i = a+1; i <= a+b; i++) {
        if (s[i] < ‘0‘ || s[i] > ‘9‘) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

C - Special Trains

#include<bits/stdc++.h>
using namespace std;
const int MAXN=505;
int C[MAXN],S[MAXN],F[MAXN];

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<n-1;i++)
        {
            scanf("%d%d%d",&C[i],&S[i],&F[i]);
        }
        for(int i=0;i<n;i++)
        {
            int t=0;
            for(int j=i;j<n-1;j++)
            {
                if(t<S[j])       t=S[j];
                else if(t%F[j])  t=t+F[j]-t%F[j];
                t+=C[j];
            }
            printf("%d\n",t);
        }
    }
    return 0;
}

D - 2017-like Number

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;
typedef long long LL;
int sum[N];
bool is_prime(int x) {
    if (x < 2) return false;
    for (int i = 2; i <= x / i; ++i)
        if (x % i == 0) return false;
    return true;
}
int main() {
    for (int i = 1; i < 100005; i++) {
        sum[i] = sum[i - 1];
        if(i%2)
            if (is_prime(i) && is_prime((i + 1) / 2)) sum[i]++;
    }
    int q;
    cin >> q;
    while(q--){
        int x, y;
        cin >> x >> y;
        cout << sum[y] - sum[x - 1] << endl;
    }
    return 0;
}

AtCoder Beginner Contest 084

原文:https://www.cnblogs.com/dyhaohaoxuexi/p/14391844.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!