UVa 11168 Airport凸包與直線方程

2022-09-03 11:42:13 字數 1206 閱讀 6020

題意:給出平面上的n個點,求一條直線,使得所有點在該直線的同一側且所有點到該直線的距離和最小,輸出該距離和。

思路:要使所有點在該直線的同一側,明顯是直接利用凸包的邊更優。所以列舉凸包的沒條邊,然後求距離和。直線一般式為ax + by + c = 0.點(x0, y0)到直線的距離為

fabs(ax0+by0+c)/sqrt(a*a+b*b).由於所有點在直線的同一側,那麼對於所有點,他們的(ax0+by0+c)符號相同,顯然可以累加出sumx和sumy,然後統一求和。

1 #include2 #include3 #include4 #include5 #include6

using

namespace

std;

7#define inf 800000000

8int

sumx, sumy, n;

9struct point;

10 point p[10002], ch[10002

];11

bool

cmp(point a, point b)

14int

cross(point a, point b, point c)

17const

double eps = 1e-10;18

int dcmp(double

x)22

int convexhull()//

凸包23

30int k =m;

31for(int i = n-2; i >= 0; i--)

35if(n > 1)m--;

36return

m;37}38

double

getdist(point a, point b)

47double line(int

m)48

54return

minl;55}

56int

main()

5770 printf("

case #%d:

", cas++);

71if(n == 1 || n== 2

)75 printf("

%.3lf\n

", line( convexhull() ) / (n*1.0

));76}77

return0;

78 }

view code

UVA 木塊問題 101

uva 木塊問題 101,好開森好開森。雖然花了很長時間,不過能一次就ac也是蠻開心的,用c 寫效率就是不錯 疊木塊其實是乙個二維空間,每個木塊都有縱橫座標 include include includeusing namespace std block用於記錄木塊所在位置,x是位於哪一疊木塊,y是...

UVA 非常可樂

include include include include include using namespace std struct node int vis 205 205 注意vis陣列用於 int s,n,m int cup left 3 記錄三個杯子中每個杯子的剩餘狀態 int bfs fo...

UVa百題總結

總算刷夠 演算法競賽入門經典 100題了,就像教主所說,有了練acm的誠意,受自身水平和眼界所限,這總結難免會有一些個人色彩和不正確的地方,大牛勿噴。另外我的文筆可能極其拙劣,將就著看吧。按照教主的進度安排,最理想的情況是寒假學完前八章,下學期開始學動態規劃 數學和圖論的基礎,為暑假集訓打下基礎。暑...