ccfcsp-202303(1、2、3)

202303-1 田地丈量

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, a, b;
    cin >> n >> a >> b;
    int res = 0;
    while(n--){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        if (x1 > a || y1 > b || x2 < 0 || y2 < 0)//要注意边界
            continue;
        int x = min(a, x2) - max(0, x1);
        int y = min(b, y2) - max(0, y1);
        res += x * y;
    }
    cout << res;
    return 0;
}

202303-2 垦田计划

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m, k;
    cin >> n >> m >> k;
    int maxt = INT_MIN;
    vector<vector<int>> vec(n,vector<int>(2,0));
    vector<int> c(100001,0);//c[i]表示开垦时间为i天的土地全缩减耗时一天所需要的资源量
    for(int i = 0; i < n; i++){
        cin >> vec[i][0] >> vec[i][1];
        c[vec[i][0]] += vec[i][1];
        maxt = max(maxt, vec[i][0]);
    }
    int i;
    for(i = maxt; i > k; i--){
        if(m >= c[i]){
            m -= c[i];
            c[i - 1] += c[i];
        }else{
            cout << i;
            break;
        }
    }
    if(i == k)
        cout << k;
    return 0;
}

202303-3 LDAP

用数组存属性,70分

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> user(10000,vector<int>(10000, -1));
set<int> mset;

void caculate(string s,int n,set<int> &myset) {
    if (s[0] == '&' || s[0] == '|') {
        if (s[0] == '&') {
            set<int> set1;
            int i = 2;
            int j = i, flag = 0;
            while(s[j] != ')' || flag != 0){
                if(s[j] == '('){
                    flag++;
                }else if(flag && s[j] == ')')
                    flag--;
                j++;
            }
            caculate(s.substr(i, j - i), n, set1);

            set<int> set2;
            i = j + 2;
            j = i, flag = 0;
            while(s[j] != ')' || flag != 0){
                if(s[j] == '('){
                    flag++;
                }else if(flag && s[j] == ')')
                    flag--;
                j++;
            }
            caculate(s.substr(i, j - i), n, set2);

			//取交集
            set<int> intersection;
            set_intersection(set1.begin(), set1.end(),
                             set2.begin(), set2.end(),
                             std::inserter(intersection, intersection.begin()));
            myset = intersection;
        } else if (s[0] == '|') {
            set<int> set1;
            int i = 2;
            int j = i, flag = 0;
            while(s[j] != ')' || flag != 0){
                if(s[j] == '('){
                    flag++;
                }else if(flag && s[j] == ')')
                    flag--;
                j++;
            }
            caculate(s.substr(i, j - i), n, set1);

            set<int> set2;
            i = j + 2;
            j = i, flag = 0;
            while(s[j] != ')' || flag != 0){
                if(s[j] == '('){
                    flag++;
                }else if(flag && s[j] == ')')
                    flag--;
                j++;
            }
            caculate(s.substr(i, j - i), n, set2);

			//取并集
            set<int> unionSet;
            set_union(set1.begin(), set1.end(),
                           set2.begin(), set2.end(),
                           std::inserter(unionSet, unionSet.begin()));
            myset = unionSet;
        }
    }else {
        int t1 = s.find(':');
        int t2 = s.find('~');
        int t = t1 == -1 ? t2 : t1;
        int a = stoi(s.substr(0,t));
        int b = stoi(s.substr(t + 1));

        if (s[t] == ':') {
            for (int j = 0; j < n; j++) {
                if (user[j][a] == b) {
                    myset.insert(user[j][0]);
                }
            }
        } else if (s[t] == '~') {
            for (int j = 0; j < n; j++) {
                if (user[j][a] != b && user[j][a] > 0) {
                    myset.insert(user[j][0]);
                }
            }
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> user[i][0];
        cin >> m;
        while(m--){
            int a, b;
            cin >> a >> b;
            user[i][a] = b;
        }
    }

    cin >> m;
    string s;
    while(m--){
        cin >> s;
        mset.clear();
        caculate(s,n,mset);
        for(auto it : mset)
            cout << it << " ";
        cout << endl;
    }
    return 0;
}
相关推荐
iqay2 小时前
【C语言】填空题/程序填空题1
c语言·开发语言·数据结构·c++·算法·c#
程序猿编码2 小时前
自定义命令执行器:C++中命令封装的深度探索(C/C++实现)
linux·c语言·c++·网络安全·shell·命令行
wen__xvn4 小时前
每日一题洛谷B3865 [GESP202309 二级] 小杨的 X 字矩阵c++
c++·算法·矩阵
makabaka_T_T4 小时前
25寒假算法刷题 | Day1 | LeetCode 240. 搜索二维矩阵 II,148. 排序链表
数据结构·c++·算法·leetcode·链表·矩阵
学游戏开发的4 小时前
UE求职Demo开发日志#19 给物品找图标,实现装备增加属性,背包栏UI显示装备
c++·笔记·游戏引擎·unreal engine
c-c-developer6 小时前
C++ Primer 标准库类型string
开发语言·c++
宁静致远20216 小时前
Ubuntu下的Doxygen+VScode实现C/C++接口文档自动生成
c++·vscode·ubuntu
Bluesonli6 小时前
第 2 天:创建你的第一个 UE5 C++ 项目!
c++·学习·ue5·虚幻·虚幻引擎·unreal engine
比特在路上6 小时前
蓝桥杯之c++入门(四)【循环】
c++·职场和发展·蓝桥杯
pay顿7 小时前
C++基础day1
c++·学习·笔试