[TC6194] AllWoundUp

被卡掉一个点海星qwq

题意

给出n个点,x轴上有另外一点A。有一点依次在n个点间运动,顺时针绕过点A一圈ans—,逆时针绕一圈ans++。求ans最大值。

思路

容易观察结论得,由运动路径截x轴划分的区间内答案一定。

然后取每段区间中点。

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
class AllWoundUp
{
private:
typedef double db;
static const int N = 1010,M = 10010,bs = 20000;
const db eps = 1e-8,pi = acos(-1);
int n,ban[N],ans = -0x3f3f3f3f;
struct point{int x,y;}po[N];
std::vector<db> co;
inline db cr(db x1,db y1,db x2,db y2){return x1 * y2 - x2 * y1;}
int solve(db x)
{
db r = 0.;int a = 0;
for(int i = 1;i <= n;i++)
{
int j = i % n + 1;
db A1 = 1. * po[i].x,B1 = 1. * po[i].y,A2 = 1. * po[j].x,B2 = 1. * po[j].y;
db al = atan2(B1,A1 - x),be = atan2(B2,A2 - x);
db d = std::fabs(be - al);
if(d + eps > pi) d = 2 * pi - d;
if(cr(A1 - x,B1,A2 - x,B2) < eps) d *= -1.;
r += d;
if(r + eps> 2 * pi) a++,r -= 2 * pi;
if(r < -2 * pi + eps) a--,r += 2 * pi;
}
return a;
}
public:
int maxWind(const std::vector<int> &v1,const std::vector<int> &v2)
{
n = v1.size();
memset(ban,0,sizeof(ban));
for(int i = 1;i <= n;i++) po[i] = (point){v1[i - 1] + bs,v2[i - 1]};
for(int i = 1;i <= n;i++)
{
int j = i % n + 1;
if(po[i].y * po[j].y > 0) continue;
if(!(po[i].y || po[j].y))
{
int a = po[i].x,b = po[j].x;
co.push_back(a);co.push_back(b);
if(a > b) std::swap(a,b);
for(int i = a;i <= b;i++) ban[i] = 1;
continue;
}
int a = (po[i].y * po[j].x - po[i].x * po[j].y),b = (po[i].y - po[j].y);
co.push_back(1. * a / b);
}
co.push_back(0.);co.push_back(2. * bs);
std::sort(co.begin(),co.end());
co.erase(std::unique(co.begin(),co.end()),co.end());
for(int i = 0,cs = co.size();i < cs - 1;++i)
{
db mid = (co[i] + co[i + 1]) / 2;
if(ban[(int)ceil(mid)] && ban[(int)floor(mid)]) continue;
ans = std::max(ans,solve(mid));
}
return ans;
}
};