2021-08-31学习成果

一. CCF CSP

  1. 卖菜
#include <iostream>
#include <set>
#include <utility>
#include <algorithm>
# include <algorithm>
#include <vector>

using namespace std;

const int MAX = 1010;
int n;
int a[MAX];
int b[MAX];
int main(){
    scanf("%d",&n);
    for(int i =1; i <=n; i++) scanf("%d",&a[i]);
    b[1] = (a[1] + a[2])/2;
    b[n] = (a[n-1] + a[n])/2;
    printf("%d",b[1]);
    for(int i =2; i <=n-1; i++) {
        b[i] = (a[i-1]+a[i]+a[i+1])/3;
        printf(" %d",b[i]);
    }
    printf(" %d",b[n]);
    return 0;
}
  1. 买菜
    参考下面博客;
    CCF 201809-2 买菜 C++代码
#include <iostream>
#include <set>
#include <utility>
#include <algorithm>
# include <algorithm>
#include <vector>

using namespace std;

const int MAX = 1000010;
int n;
int a,b;
int record[MAX];
int sum = 0;
int main(){
    scanf("%d",&n);
    for(int i = 1; i <= 2*n;i++){
        scanf("%d%d",&a,&b);
        for(int j = a;j < b ; j++){
            record[j]++;
        }
    }
    for(int i = 1;i <= MAX-1;i++){
        if(record[i]==2) sum++;
    }
    printf("%d",sum);
    return 0;
}
  1. 小明放学
    (一开始只有60分,把sum类型改成long long即得到100分)
#include <iostream>
#include <set>
#include <utility>
#include <algorithm>
# include <algorithm>
#include <vector>

using namespace std;

const int MAX = 100010;
int n;
int r,y,g;
int rec;
int k,t;
long long sum=0;
int temp;
int main(){
    scanf("%d%d%d",&r,&y,&g);
    scanf("%d",&n);
    rec = r + y + g;
    for(int i =1; i <= n;i++){
        scanf("%d%d",&k,&t);
        temp = sum % rec;
        switch (k){
            case 0:
                sum+=t;
                break;
            case 1:

                if(temp <= t) sum += t - temp;
                else{
                    if(temp > t && temp <= t + g) sum = sum;
                    else if(temp > t + g && temp <= t + g +y)
                        sum += t + g +y - temp + r;
                    else
                        sum += r - (temp - (t+g+y));
                }

                break;
            case 2:

                if(temp <= t) sum += t - temp + r ;
                else{
                    if(temp > t && temp <= t + r) sum += t + r - temp;
                    else if(temp > t + r && temp <= t + r +g)
                        sum = sum;
                    else
                        sum += y - (temp - (t+r+g)) + r;
                }
                break;
            case 3:

                if(temp <= t) sum = sum;
                else{
                    if(temp > t && temp <= t + y) sum += t + y - temp + r;
                    else if(temp > t + y && temp <= t + y + r)
                        sum += t + y + r - temp;
                    else
                        sum = sum ;
                }
                break;
        }
    }
    printf("%lld",sum);
    return 0;

}
  1. 二十四点
#include <iostream>
#include <set>
#include <utility>
#include <algorithm>
# include <algorithm>
#include <deque>

using namespace std;

const int MAX = 100010;
int a[10];
char b[10];
int n;
deque<int>q1;
deque<char>q2;
string st[110];
int temp;
int main() {
    scanf("%d", &n);
    for(int i =1; i <= n;i++){
    scanf("%d%c%d%c%d%c%d", &a[1], &b[1], &a[2], &b[2], &a[3], &b[3], &a[4]);
    if (b[1] == 'x') {
        temp = a[1] * a[2];
        q1.push_back(temp);
    } else if (b[1] == '/') {
        temp = a[1] / a[2];
        q1.push_back(temp);
    } else {
        q1.push_back(a[1]);
        q2.push_back(b[1]);
        q1.push_back(a[2]);
    }
    if (b[2] == 'x') {
        temp = q1.back();
        temp *= a[3];
        q1.pop_back();
        q1.push_back(temp);
    } else if (b[2] == '/') {
        temp = q1.back();
        temp /= a[3];
        q1.pop_back();
        q1.push_back(temp);
    } else {
        q1.push_back(a[3]);
        q2.push_back(b[2]);
    }
    if (b[3] == 'x') {
        temp = q1.back();
        temp *= a[4];
        q1.pop_back();
        q1.push_back(temp);
    } else if (b[3] == '/') {
        temp = q1.back();
        temp /= a[4];
        q1.pop_back();
        q1.push_back(temp);
    } else {
        q1.push_back(a[4]);
        q2.push_back(b[3]);
    }
    while (!q2.empty()) {
        a[1] = q1.front();
        q1.pop_front();
        a[2] = q1.front();
        q1.pop_front();
        b[1] = q2.front();
        q2.pop_front();
        if (b[1] == '+') {
            temp = a[1] + a[2];
            q1.push_front(temp);
        } else {
            temp = a[1] - a[2];
            q1.push_front(temp);
        }
    }
    temp = q1.front();
    if (temp == 24) st[i].assign("Yes");
    else st[i].assign("No");
    q1.clear();
    q2.clear();
}
    for(int i =1;i <= n-1;i++) printf("%s\n",st[i].c_str());
    printf("%s",st[n].c_str());
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值