題意:
給n個平面上的點,現在要在離點外l公尺處建城牆,使得城牆把所有點都包含進去且城牆的長度最短。
解析:韜哥出的某次訓練賽上a出的第一道計算幾何,算是大水題吧。
用convexhull演算法把凸包求出來,然後加加減減就a了。
計算見下圖:
好久沒玩畫圖了啊好開心。
**:
#include #include #include #include #include #include #include #include #include #include #define ll long long
using namespace std;
const int maxn = 1e3 + 10;
const int inf = 0x3f3f3f3f;
const double eps = 1e-10;
const double pi = 4 * atan(1.0);
struct point
};typedef point vector;
vector operator + (vector a, vector b)
vector operator - (vector a, vector b)
vector operator * (vector a, double p)
vector operator / (vector a, double p)
bool operator < (const point& a, const point& b)
int dcmp(double x)
else
}bool operator == (const point& a, const point& b)
double dot(vector a, vector b)
double length(vector a)
double angle(vector a, vector b)
double cross(vector a, vector b)
double area2(point a, point b, point c)
bool cmp(point a, point b)
int convexhull(point* p, int n, point* ch)
int k = m;
for (int i = n - 2; i >= 0; i--)
if (n > 1)
m--;
return m;
}int main()
point ch[maxn];
int index = convexhull(p, n, ch);
// for (int i = 0; i < index; i++)
// cout << ch[i].x << " " << ch[i].y << endl;
vector g[maxn];
double angle = 0;
double ans = 0;
for (int i = 0; i < index - 1; i++)
g[index - 1].x = ch[0].x - ch[index - 1].x;
g[index - 1].y = ch[0].y - ch[index - 1].y;
ans += length(g[index - 1]);
//cout << ans << endl;
for (int i = 0; i < index - 1; i++)
angle += angle(g[index - 1], g[0]);
//cout << angle << endl;
ans += pi * l * angle / pi;
printf("%.lf\n", ans);
}return 0;
}
凸包計算 POJ1113
題目中除了要計算凸包之外,還要求修理的城牆要和宮殿之間的距離不小於l,那麼也就是相對於宮殿長度之外,多了乙個一l為半徑的圓的距離,所以題目就得以解決 poj1113 include include include include using namespace std typedef long lo...
poj1113 求凸包 計算凸包周長
經典的求凸包題,模板題。要求用資源最少,那肯定這個多邊形是個凸多邊形,也就是凸包。所以先求出凸包,計算它的周長。還有就是這道題所說的,要離城牆l遠,其實就是在加上乙個圓的周長,圓的半徑就是l。都說到這了,這道題還差什麼?還差乙個經典的凸包模板!哈哈 如下 include include includ...
poj 1113 凸包模板
include include include include include include using namespace std define n 1050 define pi acos 1.0 int n,r struct point point operator point b const...