LA 3263 尤拉定理

2021-07-10 05:57:47 字數 1642 閱讀 9952

#include#include#includeusing namespace std;

const double eps = 1e-10;

int dcmp(double x)

struct point

};typedef point vector;

vector operator + (const vector& a, const vector& b)

vector operator - (const point& a, const point& b)

vector operator * (const vector& a, double p)

bool operator < (const point& a, const point& b)

bool operator == (const point& a, const point &b)

double dot(const vector& a, const vector& b)

double cross(const vector& a, const vector& b)

point getlineintersection(const point& p, const vector& v, const point& q, const vector& w)

bool segmentproperintersection(const point& a1, const point& a2, const point& b1, const point& b2)

bool onsegment(const point& p, const point& a1, const point& a2)

const int maxn = 300 + 10;

point p[maxn], v[maxn*maxn];

int main()

n--;

int c = n, e = n;

for(int i = 0; i < n; i++)

for(int j = i+1; j < n; j++)

if(segmentproperintersection(p[i], p[i+1], p[j], p[j+1]))

v[c++] = getlineintersection (p[i], p[i+1]-p[i], p[j], p[j+1]-p[j]);

sort(v, v+c);

c = unique(v, v+c) - v;

for(int i = 0; i < c; i++)

for(int j = 0; j < n; j++)

if(onsegment(v[i], p[j], p[j+1])) e++;

printf("case %d: there are %d pieces.\n", ++kase, e+2-c);

} return 0;

}

書上的**:

尤拉定理:

設平面圖的頂點數 v ,邊數 e ,面數 f ,則 f = e+2-v

分析:1:算出頂點數,包括交點,有可能三條線段交於一點,需要去重。

2:算出線段數,如果原來的線段新增加乙個點,那麼一條線段一為二,所以一條線段每新增乙個點就多出一條線段。

即可

LA 3263 尤拉定理

include include include include include include using namespace std const int maxn 310 const int maxe 100000 const int inf 0x3f3f3f struct point 建構函式 ...

LA 3263 計算幾何,尤拉定理

題目大意 有n個點組成的一筆畫,問這個圖形把平面分成了幾個部分 題目解析 先把那些直線相交得出的點算出來得出點數,再把 邊數算出來,有乙個點在原來的線段上並且不與端點重合邊數就加一,因為一條線段變成了兩條線段,最後根據尤拉定理f e 2 v算出面數 ac includeusing namespace...

LA 3263 細節處理,尤拉定理

大概就是給你若干個點描述乙個軌跡,這個軌跡的終點一定是和起點重合的 然後問你分成了幾個平面區域 這個問題用到了尤拉定理,妙啊!平面圖的尤拉定理 不得不說尤拉牛逼啊 e是稜的個數,其實可以理解成邊,f是區域的個數,這裡理解為邊劃分成的區域,e是頂點,也就是圖論中的頂點。至於什麼是平面圖,不解釋了 然後...