标签:cross math 圆心 \n 理解 string 之间 algo lin
博客园的话插链接链接都是凉的= =
我理解成能不能看到这个圆,除了最后几个圆特殊以外都是等价的,然而我凉了,因为我把圆当成线段来处理,但是,有可能一个圆完全被遮住了,还有一个缝隙,就WA了
计算几何题这点最不好,WA了会想的第一件事就是垃圾OJ卡我精度,反复WA上几次才会知道,自己算法错了
那么首先每个圆的位置取决于能被左边的圆最远推到哪里,这个就是以两圆圆心距和竖直两条半径(是个梯形)算出来就行,能被推说明圆心距必然是半径之和,不断取max并同时记录是哪个圆推的它
最后取最后一个碰到某个圆的圆,并删除他们之间所有点,特判一下第一个碰到最远距离的圆pos[i] + r[i]的最大值所在的i并删除之后的圆
为什么我叙述那么混乱可能我太久没上语文课吧(手动再见)
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <cstring>
#include <ctime>
#include <map>
#include <algorithm>
#include <cmath>
#define MAXN 1005
#define eps 1e-8
//#define ivorysi
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long int64;
typedef double db;
int N,tot,ans[MAXN],touch[MAXN];
db R[MAXN],pos[MAXN];
bool dcmp(db a,db b) {
return fabs(a - b) < eps;
}
struct Point {
db x,y;
Point(){}
Point(db _x,db _y) {
x = _x;y = _y;
}
friend Point operator + (const Point &a,const Point &b) {
return Point(a.x + b.x,a.y + b.y);
}
friend Point operator - (const Point &a,const Point &b) {
return Point(a.x - b.x,a.y - b.y);
}
friend Point operator * (const Point &a,db d) {
return Point(a.x * d,a.y * d);
}
friend Point operator / (const Point &a,db d) {
return Point(a.x / d,a.y / d);
}
friend db operator * (const Point &a,const Point &b) {
return a.x * b.y - a.y * b.x;
}
friend db dot(const Point &a,const Point &b) {
return a.x * b.x + a.y * b.y;
}
db norm() {
return sqrt(x * x + y * y);
}
}P[MAXN];
struct Seg {
Point a,b;
db d;
Seg(){}
Seg(Point _a,Point _b) {
a = _a;b = _b;d = atan2(b.y - a.y,b.x - a.x);
}
friend Point Cross_Point(const Seg &s,const Seg &t) {
db S1 = (s.a - t.a) * (t.b - t.a);
db S2 = (s.b - t.b) * (t.a - t.b);
return s.a + (s.b - s.a) * (S1 / (S1 + S2));
}
friend bool operator < (const Seg &s,const Seg &t) {
return s.d < t.d;
}
}S[MAXN];
inline db o(db x) {return x * x;}
void Solve() {
//scanf("%d",&N);
tot = 0;
for(int i = 1 ; i <= N ; ++i) scanf("%lf",&R[i]);
db L = 0.0;
for(int i = 1 ; i <= N ; ++i) {
pos[i] = R[i];
touch[i] = 0;
for(int j = 1 ; j < i ; ++j) {
db x = pos[j] + sqrt(R[i] * R[j]) * 2;
if(x > pos[i] + eps) {
pos[i] = x;
touch[i] = j;
}
}
L = max(L,pos[i] + R[i]);
}
int last = 0;
while(1) {
if(dcmp(pos[last] + R[last],L)) {
for(int i = last + 1 ; i <= N ; ++i) ans[++tot] = i;
break;
}
int v = 0;
for(int i = last + 1 ; i <= N ; ++i) {
if(touch[i] == last) v = i;
}
for(int i = last + 1 ; i < v ; ++i) ans[++tot] = i;
last = v;
}
printf("%d\n",tot);
for(int i = 1 ; i <= tot ; ++i) {
printf("%d\n",ans[i]);
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
while(scanf("%d",&N) != EOF && N) {
Solve();
}
return 0;
}
标签:cross math 圆心 \n 理解 string 之间 algo lin
原文地址:https://www.cnblogs.com/ivorysi/p/9021566.html