P13596 『GTOI - 1C』Top Miner
Genius_Star · · 题解
第一次见到交互库难度大于题目难度的。。。
思路:
不是题。
考虑皮克定理:
对于一个顶点坐标均为整点的简单多边形,其面积
A 与内部格点数I 和边界格点数B 的关系为:A = I + \frac{B}{2} - 1
于是我们对每个点使用
-
若等于
10^{-4} ,则在内部。 -
否则若大于
0 ,则在边界上。
注意精度要开
时间复杂度为
完整代码:
#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;
}