ccfcsp-202309(1、2、3)

202309-1 坐标变换(其一)

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

    int n, m;
    cin >> n >> m;
    int x, y;
    int opx = 0, opy = 0;
    for(int i = 0; i < n; i++){
        cin >> x >> y;
        opx += x;
        opy += y;
    }
    for(int i = 0; i < m; i++){
        cin >> x >> y;
        cout << x + opx << " " << y + opy << endl;
    }
    return 0;
}

202309-2 坐标变换(其二)

80分超时解

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

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

    int n, m;
    cin >> n >> m;
    vector<vector<double>> operation(n, vector<double>(2));
    double x, y;
    for(int i = 0; i < n; i++){
        cin >> operation[i][0] >> operation[i][1];
    }
    int i, j;
    for(int t = 0; t < m; t++){
        cin >> i >> j >> x >> y;
        double xx = x, yy = y;
        double angle = 0, k = 1;
        i--;
        for(;i < j; i++){
            if(operation[i][0] == 1){
                k *= operation[i][1];
            }else if(operation[i][0] == 2){
                angle += operation[i][1];
            }
        }
        if(k != 1){
            x *= k;
            y *= k;
        }
        if(angle != 0){
            xx = x * cos(angle) - y * sin(angle);
            yy = x * sin(angle) + y * cos(angle);
            cout << fixed << setprecision(3) << xx << " " << yy << endl;
        }else{
            cout << fixed << setprecision(3) << x << " " << y << endl;
        }
    }
    return 0;
}

100分解

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

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

    int n, m;
    cin >> n >> m;
    vector<double> A(n + 1, 1);//拉伸k倍
    vector<double> B(n + 1, 0);//旋转角度
    double x, y;
    for(int i = 1; i <= n; i++){
        int a; double b;
        cin >> a >> b;
        if(a == 1){
            A[i] = b*A[i - 1];
            B[i] = B[i - 1];
        }else{
            A[i] = A[i - 1];
            B[i] = b + B[i - 1];
        }
    }
    int i, j;
    for(int t = 0; t < m; t++){
        cin >> i >> j >> x >> y;
        double xx = x, yy = y;
        double k = A[j]/A[i - 1], angle = B[j] - B[i - 1];
        if(k != 1){
            x *= k;
            y *= k;
        }
        if(angle != 0){
            xx = x * cos(angle) - y * sin(angle);
            yy = x * sin(angle) + y * cos(angle);
            cout << fixed << setprecision(3) << xx << " " << yy << endl;
        }else{
            cout << fixed << setprecision(3) << x << " " << y << endl;
        }
    }

    return 0;
}

202309-3 梯度求解

cpp 复制代码
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mod = 1e9 + 7;

int main() {
    vector<string> vec;
    stack<map<ll, ll>> st;
    int n, m, k;
    cin >> n >> m;
    string str, s;
    vector<int> a(n + 1, 0);//变量的值

    getchar();
    getline(cin, str);
    std::stringstream ss(str);
    while(ss >> s){
        vec.push_back(s);
    }
    while(m--){
        cin >> k;
        str = "x" + to_string(k);//求导变量
        for(int i = 1; i <= n; i++)
            cin >> a[i];
        for(int i = 0; i < vec.size(); i++){
            s = vec[i];
            map<ll, ll> mp;
            if(s == str){ //是求导变量
                mp[1] = 1;
                st.push(mp);
            }else if(s[0] == 'x'){ //是其他变量
                int d = stoi(s.substr(1));
                mp[0] = a[d] % mod;
                st.push(mp);
            }else if(s == "+" || s == "-" || s == "*"){//是运算符
                map<ll,ll> mp2 = st.top();
                st.pop();
                map<ll,ll> mp1 = st.top();
                st.pop();

                if(s == "+"){
                    mp = mp1;
                    for(auto it : mp2){
                        mp[it.first] = (mp[it.first] + it.second) % mod;
                    }
                }else if(s == "-"){
                    mp = mp1;
                    for(auto it : mp2){
                        mp[it.first] = (mp[it.first] - it.second) % mod;
                    }
                }else{
                    for(auto it1 : mp1){
                        for(auto it2 : mp2){
                            mp[it1.first + it2.first] += it1.second * it2.second;
                            mp[it1.first + it2.first] %= mod;
                        }
                    }
                }
                mp1.clear();
                mp2.clear();
                st.push(mp);
            }else{ //是数字
                ll d = stoll(s);
                mp[0] = d % mod;
                st.push(mp);
            }
        }
        map<ll,ll> mp = st.top(); //获得结果的一元表达式
        st.pop();
        ll ans = 0;
        for(auto it : mp){
            ll e = it.first, c = it.second;
            if(e > 0){
                ans = ans + c * e * pow(a[k], e - 1);
                ans %= mod;
            }
        }
        cout << (ans + mod) % mod << endl;
        mp.clear();
    }
    return 0;
}
相关推荐
古月-一个C++方向的小白5 小时前
C++11之lambda表达式与包装器
开发语言·c++
tanyongxi667 小时前
C++ AVL树实现详解:平衡二叉搜索树的原理与代码实现
开发语言·c++
斯是 陋室9 小时前
在CentOS7.9服务器上安装.NET 8.0 SDK
运维·服务器·开发语言·c++·c#·云计算·.net
tju新生代魔迷10 小时前
C++:list
开发语言·c++
HHRL-yx10 小时前
C++网络编程 5.TCP套接字(socket)通信进阶-基于多线程的TCP多客户端通信
网络·c++·tcp/ip
tomato0910 小时前
河南萌新联赛2025第(一)场:河南工业大学(补题)
c++·算法
每一天都要努力^13 小时前
C++拷贝构造
开发语言·c++
NoirSeeker14 小时前
在windows平台上基于OpenHarmony sdk编译三方库并暴露给ArkTS使用(详细)
c++·windows·arkts·鸿蒙·交叉编译
落羽的落羽14 小时前
【C++】(万字)一文看懂“类与对象”
c++
闻缺陷则喜何志丹15 小时前
【带权的并集查找】 P9235 [蓝桥杯 2023 省 A] 网络稳定性|省选-
数据结构·c++·蓝桥杯·洛谷·并集查找