跳到正文

题解

P13596 『GTOI - 1C』Top Miner

Genius_Star约 4 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 4 分钟
获赞
1
题目
P13596

版本

  1. v1当前

第一次见到交互库难度大于题目难度的。。。

思路:

不是题。

考虑皮克定理:

对于一个顶点坐标均为整点的简单多边形,其面积 AA 与内部格点数 II 和边界格点数 BB 的关系为:

A=I+B2−1A = I + \frac{B}{2} - 1

于是我们对每个点使用 10−2×10−210^{-2} \times 10^{-2} 的矩形探测仪包住它,询问与这个简单多边形的面积交:

  • 若等于 10−410^{-4},则在内部。

  • 否则若大于 00,则在边界上。

注意精度要开 10−1010^{-10} 左右。

时间复杂度为 O(N2)O(N^2)。

完整代码:

C++
#include<bits/stdc++.h>
#define ls(k) k << 1
#define rs(k) k << 1 | 1
#define fi first
#define se second
#define add(x, y) ((x + y >= mod) ? (x + y - mod) : (x + y))
#define dec(x, y) ((x - y < 0) ? (x - y + mod) : (x - y))
#define popcnt(x) __builtin_popcount(x)
#define open(s1, s2) freopen(s1, "r", stdin), freopen(s2, "w", stdout);
using namespace std;
typedef __int128 __;
typedef long double lb;
typedef double db;
typedef unsigned long long ull;
typedef long long ll;
bool Begin;
inline ll read()
{
    ll x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9')
    {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9')
    {
        x = (x << 1) + (x << 3) + (c ^ 48);
        c = getchar();
    }
    return x * f;
}

inline void write(ll x)
{
    if(x < 0)
    {
        putchar('-');
        x = -x;
    }
    if(x > 9) write(x / 10);
    putchar(x % 10 + '0');
}
int main(){
    cout.setf(ios::fixed);
    cout<<setprecision(5);
    int I = 0, B = 0;
    const db EPS  = 1e-10;
    for(int x = 0; x < 100; ++x){
        for(int y = 0; y < 100; ++y){
            db xl = x - 0.005, yl = y - 0.005;
            db xr = x + 0.005, yr = y + 0.005;
            cout << "? "
                 << xl << ' ' << yl << ' '
                 << xr << ' ' << yl << ' '
                 << xr << ' ' << yr << ' '
                 << xl << ' ' << yr << '\n';
            cout.flush();
            db ret;
            if(!(cin >> ret))
			  return 0;
            if(fabs(ret - 1e-4) < EPS)
              ++I;
            else if(ret > EPS)
              ++B;
        }
    }
    lb area = (lb)I + (lb)B * 0.5 - 1.0;
    cout.setf(ios::fixed);
    cout<<setprecision(10);
    cout << "! " << (double)area << '\n';
    cout.flush();
    return 0;
}
原文