CSP-S C++ 阅读程序的程序(T1+T2)
  • 板块灌水区
  • 楼主小甲鱼
  • 当前回复3
  • 已保存回复3
  • 发布时间2021/9/19 12:14
  • 上次更新2023/11/4 06:19:26
查看原帖
CSP-S C++ 阅读程序的程序(T1+T2)
139605
小甲鱼楼主2021/9/19 12:14

T1

#include <iostream>
#include <cmath>
using namespace std;
const double r = acos(0.5);
int a1, b1, c1, d1;
int a2, b2, c2, d2;

inline int sq(const int x) { return x * x; }
inline int cu(const int x) { return x * x * x; }

int main(){
    cout.flags(ios::fixed);
    cout.precision(4);

    cin>>a1>>b1>>c1>>d1;
    cin>>a2>>b2>>c2>>d2;

    int t=sq(a1-a2)+sq(b1-b2)+sq(c1-c2); 
    if (t <= sq(d2 - d1)) cout << cu(min(d1, d2)) * r * 4;
    else if (t >= sq(d2 + d1)) cout << 0;
    else {
    double x = d1 - (sq(d1) - sq(d2) + t) / sqrt(t) / 2;
    double y = d2 - (sq(d2) - sq(d1) + t) / sqrt(t) / 2;
    cout << (sq(x) * (3 * d1 - x) + sq(y) * (3 * d2 - y)) * r;
    }
    cout << endl;
    return 0;
}

T2

#include <algorithm>
#include <iostream>
using namespace std;

int n, a[1005];

struct Node{
    int h, j, m, w;
    Node(const int _h, const int _j, const int _m, const int _w):
        h(_h), j(_j), m(_m), w(_w)
    {}

    Node operator+(const Node &o) const
    {
        return Node(
        max(h, w + o.h),
        max(max(j, o.j), m + o.h),
        max(m + o.w, o.m),
        w + o.w);  
    }
};

Node solve1(int h, int m)
{
    if(h > m)
        return Node(-1, -1, -1, -1);
    if(h == m)
        return Node(max(a[h], 0), max(a[h], 0), max(a[h], 0), a[h]);
    int j = (h+m) >> 1;
    return solve1(h, j) + solve1(j + 1, m);
}


int solve2(int h, int m){
    if(h > m) return -1;
    if(h == m)
        return max(a[h], 0);
    int j = (h+m)>>1; 
    int wh = 0, wm = 0;
    int wht = 0, wmt = 0; 
    for(int i = j; i >= h; i--){
        wht += a[i];
        wh = max(wh, wht);
    }
    for(int i = j + 1; i <= m; i++){
        wmt += a[i];
        wm = max(wm, wmt);
    }
    return max(max(solve2(h, j), solve2(j + 1, m)), wh + wm);
}

int main(){
    cin >> n;
    for(int i = 1; i <= n; i++) cin>>a[i];
    cout << solve1(1, n).j << endl;
    cout << solve2(1, n) << endl;
    return 0;
}

2021/9/19 12:14
加载中...