click here~~
題意:
有乙個矩形的盒子,中間插了n個擋板,將盒子分成n+1個區域,然後給m個點,問最後每個區域落下多少個點。(點不會落到擋板上)
解題思路:
把矩形的右邊看成第n+1個擋板。
稍加分析,得到這個特點:若點 k 在擋板 i 的左邊,那麼 k 也一定在擋板 j 的左邊(i < j <= n+1)。
則對於每乙個點k,只要找到最小的擋板 i ,滿足點 k 在擋板 i 的左邊,則點 k 就在區域 i 中。
如此,即可轉換成二分的模型來求解。
#include #include #include #include using namespace std;
#define n 5005
const double eps = 1e-6;
struct point
point(int x,int y):x(x),y(y){}
}p,pp1,pp2,pp3,pp4;
struct rec
rec(point p1,point p2,point p3,point p4):p1(p1),p2(p2),p3(p3),p4(p4){}
}r[n];
int ans[n];
int sgn(double x)
double cross(const point& p1,const point& p2,const point& p3,const point& p4)
double area(const point& p1,const point& p2,const point& p3)
bool intri(const point& p,const point& p1,const point& p2,const point& p3)
bool inrec(const point& p,const point& p1,const point& p2,const point& p3,const point& p4)
int search(point p,int l,int r)
return r;
}int main()
{ int n,m,x1,x2,minx,maxy,maxx,miny;
bool first = true;
while(scanf("%d",&n),n)
{if(!first)
puts("");
else
first = false;
memset(ans,0,sizeof(ans));
scanf("%d%d%d%d%d",&m,&minx,&maxy,&maxx,&miny);
pp1 = point(minx,maxy);
pp2 = point(minx,miny);
for(int i=0;ips:判斷乙個點是否在三角形內部可以用面積法。
POJ 2318 TOYS 叉積 二分
題意 一些斜線將矩形劃分成若干個格仔,給出一些點,問每個格仔裡有多少點。對於乙個點和乙個線段,可以通過分別連線這個點與線段的兩個端點得到兩個向量 均是以那個點為起點指向兩個端點 然後作叉積得到該點位於線段在左側還是右側,叉積大於零為右側,小於零為左側。然後該題就可以利用此性質,發現點對於每個分隔線的...
poj2318 TOYS 叉積性質 二分
乙個矩形,n n 5e3 個玩具,m m 5e3 個擋板,問每個玩具在哪個區域,1號擋板左側為0號區域,右側為1號區域,以此類推 記向量p 隔板的上端點 玩具 向量q 隔板的上端點 隔板的下端點 那麼如果q旋轉到p為逆時針,即q p 0,說明玩具在隔板右側 二分找到最右的隔板,滿足玩具在隔板右側即可...
POJ 2318 TOYS(二分 叉積)
傳送門 設點a 假如a在乙個板子1的左邊 那他肯定也在乙個板子2左邊 而且板子還是按順序排的 滿足單調性 可以二分 考慮check 判斷點a在直線l左邊 只需判斷a到直線l的端點1 端點2兩個向量的叉積小不小於0 include include include include include def...