제출 #1280034

#제출 시각아이디문제언어결과실행 시간메모리
1280034knhatdevPlanine (COCI21_planine)C++20
0 / 110
3 ms568 KiB
#include<bits/stdc++.h>
#define int long long
#define ii pair<int,int>
#define dd pair<double, double>
#define fi first
#define se second
#define task ""
using namespace std;

const int N = 1e6 + 5, oo = 1e18;

#define EPS  0.00001
struct point2d{
    double x, y;
    point2d() {}
    point2d(double x, double y): x(x), y(y) {}

    point2d operator + (point2d t){
        return point2d(x + t.x, y + t.y);
    }
    point2d operator - (point2d t){
        return point2d(x - t.x, y - t.y);
    }
};
struct line2d{
    double a, b, c;
    line2d(double a, double b, double c): a(a), b(b), c(c) {}
    line2d(point2d &u, point2d &v) :  a(u.y - v.y), b(v.x - u.x), c(u.x * v.y - v.x * u.y) {};
};

double cross(point2d a, point2d b){ //tich co huong
    return a.x * b.y - a.y * b.x;
}
double dot(point2d a, point2d b){ // tich vo huong
    return a.x * b.x + a.y * b.y;
}
double len(point2d a, point2d b){ // do dai
    return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}
double abs(point2d a) {
    return sqrt(a.x * a.x + a.y * a.y);
}
double angle(point2d a, point2d b){ // goc giua 2 vector
    return acos(dot(a, b) / abs(a) / abs(b));
}
point2d get_intersect(line2d x, line2d y) {
    double d = x.a * y.b - x.b * y.a;
    //Neu d == 0: 2 duong song song hoac trung nhau
    point2d t;
    t.x = (x.b * y.c - y.b * x.c) / d;
    t.y = (y.a * x.c - x.a * y.c) / d;
    return t;
}
double triangle_area(point2d a, point2d b, point2d c){ // dt tam giac
    point2d v = a - b;
    point2d u = c - b;
    return abs(cross(v, u)) / 2;
}
double dis(point2d p, line2d d){ // kc 1 diem -> 1 duong thang
    return abs((d.a * p.x + d.b * p.y + d.c)/sqrt(d.a*d.a + d.b*d.b));
}
int ccw(point2d a, point2d b, point2d c) {
    double t = cross(b - a, c - b);
    if (abs(t) < EPS) return 0;
    if (t < 0) return -1;
        else return 1;
}

int n;
double h;
point2d a[N];
dd b[N];

main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(fopen(task ".inp", "r")){
        freopen(task ".inp", "r", stdin);
        freopen(task ".out", "w", stdout);
    }
    cin >> n >> h;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i].x >> a[i].y;
    }
    line2d tmp(0, 1, -h);
    int m = 0;
    vector<int> v;
    v.push_back(1);
    v.push_back(2);
    for(int i = 3; i < n; i += 2)
    {
        while(v.size() >= 2 && ccw(a[v[v.size() - 2]], a[v[v.size() - 1]], a[i]) >= 0)
        {
            v.pop_back();
        }

        v.push_back(i);
        if(i % 2 == 1)
        {
            point2d x = get_intersect(line2d(a[i], a[v.size() - 2]), tmp);
            b[++m].fi = x.x;
        }
        // cout << b[m].fi << ' ' << b[m].se << '\n';
    }
    int j = m;
    v.clear();
    v.push_back(n);
    v.push_back(n - 1);
    for(int i = n - 2; i >= 3; i--)
    {
         while(v.size() >= 2 && ccw(a[v[v.size() - 2]], a[v[v.size() - 1]], a[i]) <= 0)
        {
            v.pop_back();
        }
        v.push_back(i);
        if(i % 2 == 1)
        {
            point2d x = get_intersect(line2d(a[i], a[v.size() - 2]), tmp);
            b[j--].se = x.x;
        }
    }


    sort(b + 1, b + 1 + m, [](dd x, dd y)
    {
        return (x.se < y.se) || (x.se == y.se && x.fi < y.fi);
    });
    double last_pos = -1e18;
    int ans = 0;
    for(int i = 1; i <= m; i++)
    {
        if(b[i].fi - EPS > last_pos)
        {
            ans++;
            last_pos = b[i].se;
        }
    }
    cout << ans;
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp:74:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   74 | main(){
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         freopen(task ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         freopen(task ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...