POJ 2318 2398 計算幾何

2022-05-24 03:54:07 字數 1763 閱讀 5477

poj 2318題意:

有乙個大箱子,由n個板分為n+1塊,標號為0~n

已知盒子左上角和右下角的座標及每個板上下兩端的橫座標(板不會交錯,且按順序給出)

然後給出玩具的座標,統計每塊空間內玩具個數(保證玩具一定落在空間內,且沒有落在隔板上的點)

題解:二分位置,叉積判斷在左側還是右側

view code

1 #include 2 #include 3 #include 4 #include 5 #include 6

7#define n 1000089

using

namespace

std;

1011

structp12

b[n],c[n];

1516

intn,m,sx,sy,tx,ty;

17int

up[n],low[n],sw[n],sq[n];

18int

ans[n];

1920 inline void

read()

2127

28 inline int cross(int ax,int ay,int bx,int

by)29

3233 inline int getnum(int

i)34

42return

r;43}44

45 inline void

go()

4653

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

%d: %d\n

",i,ans[i]);

54 puts(""

);55}56

57int

main()

58

poj 2398題意同上

唯一不同的是隔板沒有按順序給出,人工排序即可~

view code

1 #include 2 #include 3 #include 4 #include 5 #include 6

7#define n 1000089

using

namespace

std;

1011

structp12

b[n];

1516

intn,m,sx,sy,tx,ty;

17int

up[n],low[n],sw[n],sq[n];

18int

ans[n],ss[n];

1920 inline bool cmp(const p &a,const p &b)

2124

25 inline void

read()

2633

34 inline int cross(int ax,int ay,int bx,int

by)35

3839 inline int getnum(int

i)40

48return

r;49}50

51 inline void

go()

5260 puts("

box"

);61

for(int i=0;i<=n;i++) ss[ans[i]]++;

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

63if(ss[i]) printf("

%d: %d\n

",i,ss[i]);64}

6566

intmain()

67

poj1696 計算幾何

運用叉積判斷是否是逆時針,因為同一直線上也行,所以有n個植物就可以吃掉n個植物 include include include include include define dist a,b sqrt 1.0 a.x b.x a.x b.x 1.0 a.y b.y a.y b.y define cr...

poj1106 計算幾何

求在可以旋轉的給定圓心和半徑的半圓中最多點的個數 include include include include include define dist a,b sqrt 1.0 a.x b.x a.x b.x 1.0 a.y b.y a.y b.y define cross a,b,c 1.0 b...

POJ 1106 計算幾何

解法 通過列舉每乙個點,然後判斷這個點的左邊和右邊分別有多少個點,然後統計乙個最大值就好了 在判斷的時候用斜率來判斷比較好 斜率大於k的一定在直線的左邊,反之就在左邊 include include define eps 1e 8 struct point point p 1005 point s ...