首页 > 编程语言 >“山大地纬杯”第十二届山东省ICPC大学生程序设计竞赛(正式赛)

“山大地纬杯”第十二届山东省ICPC大学生程序设计竞赛(正式赛)

时间:2023-04-09 10:22:05浏览次数:147  
标签:const Point int 纬杯 第十二届 ICPC ++ return Line

C

计算几何,每次延长内部多边形的边与外侧多边形形成新的多边形,求这些多边形的最大面积。

C++ Code
#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

using Real = double;
using Point = complex<Real>;

#define x real
#define y imag

constexpr Real eps = 1E-9;

int sign(const Real &x) {
    return x < -eps ? -1 : x > eps ? 1 : 0;
}

struct Line {
    Point a, b;
    Line() = default;
    Line(const Point &a, const Point &b) : a(a), b(b) {}
};

struct Segment : Line {
    Segment() = default;
    using Line::Line;
};

Real cross(const Point &a, const Point &b) {
    return (conj(a) * b).y();
}

Real dot(const Point &a, const Point &b) {
    return (conj(a) * b).x();
}

int onLeft(const Point &p, const Line &l) {
  	return sign(cross(l.b - l.a, p - l.a));
}

Real area(const Point &a, const Point &b, const Point &c) {
  return abs(cross(b - a, c - a));
}

Point cpoints(const Line &l, const Segment &s) {
  	return {s.a + (s.b - s.a) * cross(l.b - l.a, l.b - s.a) / cross(l.b - l.a, s.b - s.a)};
}

Real area(const vector<Point> &g) {
    int SIZE = g.size();
    Real res = 0;
    for (int i = 1; i < SIZE - 1; i++) {
        res += area(g[0], g[i], g[i + 1]);
    }
    return res;
}

bool intersect(const Line &l, const Segment &s) { 
    return cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) <= 0; 
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    int n;
    cin >> n;
    vector<Point> a(n);
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        a[i] = Point(x, y);
    }
    int m;
    cin >> m;
    vector<Point> b(m);
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        b[i] = Point(x, y);
    }
    Real ans = 0;
    for (int i = 0; i < m; i++) {
        vector<Point> g;
        Line L(b[i], b[(i + 1) % m]);
        for (int j = 0; j < n; j++) {
            Segment S(a[j], a[(j + 1) % n]);
            if (onLeft(a[j], L) == -1) {
                g.push_back(a[j]);
            }
            if (intersect(L, S)) {
                g.push_back(cpoints(L, S));
            }
        }
        ans = max(ans, area(g));
    }
    cout << ans / 2.0 << '\n';
    return 0;
}
## E 注意分类讨论。
C++ Code
#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

constexpr int P = 998244353;

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

    int n, x;
    cin >> n >> x;

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }    

    if (x == 0) {
        i64 ans = 0;
        int l = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] == 0) {
                ans += 1LL * (i + 1 - l) * (n - i);
                l = i + 1;
            }
        }
        cout << ans << '\n';
        return 0;
    }

    map<int, int> mp;
    i64 ans = 0;
    i64 now = 1;
    mp[x]++;
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) {
            mp.clear();
            mp[x]++;
            now = 1;
        } else {
            now *= a[i];
            now %= P;
            ans += mp[now];
            mp[now * x % P]++;
        }
    }
    cout << ans << '\n';        


    return 0;
}
## K dp。
C++ Code
#include "bits/stdc++.h"

using namespace std;
using i64 = long long;

constexpr int N = 2E6;

int A[N + 1];
int B[N + 1];

void init() {
    for (int i = 1; i <= N; i++) {
        A[i] = -1;
    }
    for (int i = 2; i <= N; i++) {
        if (A[i - 2] != -1) {
            A[i] = A[i - 2] + 1;
        }
        if (i >= 3 && A[i - 3] != -1) {
            A[i] = A[i - 3] + 1;
        }
        if (i >= 17 && A[i - 17] != -1) {
            A[i] = A[i - 17] + 1;
        }
        if (i >= 19 && A[i - 19] != -1) {
            A[i] = A[i - 19] + 1;
        }
    }
    for (int i = 1; i <= N; i++) {
        B[i] = -1;
    }
    for (int i = 5; i <= N; i++) {
        if (B[i - 5] != -1) {
            B[i] = B[i - 5] + 1;
        }
        if (i >= 7 && B[i - 7] != -1) {
            B[i] = B[i - 7] + 1;
        }
        if (i >= 11 && B[i - 11] != -1) {
            B[i] = B[i - 11] + 1;
        }
        if (i >= 13 && B[i - 13] != -1) {
            B[i] = B[i - 13] + 1;
        }
    }
    for (int i = 0; i <= N; i++) {
        if (A[i] == -1) {
            A[i] = 2E9;
        }
        if (B[i] == -1) {
            B[i] = 2E9;
        }
    }
}

int getA(int n) {
    if (n <= N) {
        return A[n];
    } else {
        return A[n - ((n - N) / 19 + 1) * 19] + ((n - N) / 19 + 1);
    }
}

int getB(int n) {
    if (n <= N) {
        return B[n];
    } else {
        return B[n - ((n - N) / 13 + 1) * 13] + ((n - N) / 13 + 1);
    }
}

void solve() {
    int n;
    cin >> n;

    int a = getA(n);
    int b = getB(n);

    if (a == b && b != 2E9) {
        cout << "both\n"; 
    } else if (a == 2E9 && b == 2E9) {
        cout << -1 << '\n';
    } else if (a < b) {
        cout << "A\n";
    } else {
        cout << "B\n";
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    init();
    
    int t;
    cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}

标签:const,Point,int,纬杯,第十二届,ICPC,++,return,Line
From: https://www.cnblogs.com/kiddingma/p/17299903.html

相关文章

  • 2018icpc青岛F . Tournament
    题目链接:https://codeforces.com/gym/104270/problem/F题意:有n个武士,编号1~n,要进行k轮比赛,每轮比赛中所有武士都要出现,然后两名武士之间会发生决斗,并且一名武士在一轮比赛中只会与另外一名武士决斗,发生决斗的这两名武士,在其他轮比赛中,将不会再次决斗。问能否构造出来符合题......
  • 最大值(第十二届 国赛 T4)
      这是一道周赛题目,完全背包模板,但是打周赛的时候眼一瞎,手一抖,看成了01模板,写出了01模板,嘤嘤嘤,来复习一下完全背包动态转移方程:f[i][j]=max(f[i-1][j],f[i][k-p[i]]+k[i]);对了再顺便讲一下压缩版f[i,j]=max(f[i-1,j],f[i-1,j-v]+w,f[i-1,j-2*v]+2*w,f[i-1,j-3*......
  • 2022icpc ec-final 游了记
    目录3.23day-13.24day03.25day13.26day23.27day3承上NOI2021退役记(密码123456):https://www.cnblogs.com/gmh77/p/15079696.html老年人的大学生活3.23day-1下午鸽......
  • 求和比较(第十二届 省赛 T4)
     题目 那么先把A1,A2所组成的等式列出来: 解出A1:       之后,我们可以发现问题变成了求1~n之间任意和为A1的可能性——01背包。顺便看一眼,要用long......
  • DP 新疆大学ACM-ICPC程序设计竞赛五月月赛(同步赛)勤奋的杨老师
    链接:https://www.nowcoder.com/acm/contest/116/C来源:牛客网时间限制:C/C++1秒,其他语言2秒空间限制:C/C++32768K,其他语言65536K64bitIO......
  • 2023 ICPC香港区域赛(UCup) D Shortest Path Query
    啊对对对,下次题解写详细一点好不好。首先考虑naive的\(O(n^2)\),记\(dp[i][j]\)表示从\(1\)走到\(i\),恰好走了\(j\)条黑边的时候走过白边的最少数量。\(O(nm)\)......
  • 第46届ICPC亚洲区域赛(昆明)(正式赛)B Blocks
    题目链接不会求概率,队友写的概率,他传给我一个二进制状态sta我只负责check一下是否合法他推的公式如下在这题进行线段树扫描线的时候遇到了之前没遇到的问题,如果l和r重......
  • 2019 ICPC Asia-East Continent Final
    D考虑树形DP,记\(f[u],g[u]\)分别为最终回到u/停在子树中的最晚第一次到达u的时间。原本以为在枚举了最后一个的情况下,遍历子树的顺序是以f升序的,(因为只有最后一个不对后面......
  • 【补题】2022-2023 ACM-ICPC German Collegiate Programming Contest (GCPC 2022)
    题目链接https://codeforces.com/gym/104059A.AlternativeArchitecture思路简单题,但要注意细节。给的方格很干扰思考,事实上注意到顶点指的是四个角上的圆圈,我们将长......
  • HDU-5112-A Curious Matt (2014ACM/ICPC北京赛区现场赛A题!)
    http://acm.hdu.edu.cn/showproblem.php?pid=5112排序之后计算就好开始用cin超时了#include<stdio.h>#include<iostream>#include<math.h>#include<stdlib.h>#......