Toys (fork)

tags: Calculate geometry

#include<bits/stdc++.h>
#define ll long long
#define x first 
#define y second
using namespace std;
typedef pair<ll,ll> pll;
const int N=5010;
int n,m;
pll a[N],b[N];
int ans[N];
ll cross(ll x1,ll y1,ll x2,ll y2){
	return x1*y2-x2*y1;
}
ll area(pll a,pll b,pll c){
	return cross(b.x-a.x,b.y-a.y,c.x-a.x,c.y-a.y);
}
int find(ll x,ll y){
	int l=0,r=n;
	while(l<r){
		int mid=l+r>>1;
		if(area(b[mid],a[mid],{x,y})>0) r=mid;
		else l=mid+1;
	}
	return l;
}
int main(){
	bool f=true;
	while(scanf("%d",&n),n){
		ll x1,y1,x2,y2;
		scanf("%d%lld%lld%lld%lld",&m,&x1,&y1,&x2,&y2);
		for(int i=0;i<n;i++){
			ll u,l;scanf("%lld%lld",&u,&l);
			a[i]={u,y1},b[i]={l,y2};
		}
		a[n]={x2,y1},b[n]={x2,y2};
		if(f) f=false;
		else puts("");
		memset(ans,0,sizeof ans);
		while(m--){
			ll x,y;scanf("%lld%lld",&x,&y);
			ans[find(x,y)]++;
		}
		for(int i=0;i<=n;i++){
			printf("%d: %d\n",i,ans[i]);
		}
	}
	return 0;
}

 

Intelligent Recommendation

A - TOYS

Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a problem - their child John never puts his toys away when he is finished playing with them. They gave Joh...

TOYS

Calculate the number of toys that land in each bin of a partitioned toy box.  Mom and dad have a problem - their child John never puts his toys away when he is finished playing with them. They ga...

poj2318 TOYS

Portal Use the cross product to determine which side of the line, the two-point answer....

Toys (toy)

Title Description Stores are selling small C series favorite toy, the next n weeks, where each week will sell Paragraph, with a toy will not be repeated. Because it is a small C's favorite series, as ...

A. Stickers and Toys

time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Your favorite shop sells nn Kinder Surprise chocolate eggs. You know that exactl...

More Recommendation

TOYS-POJ2318

The main question is to determine a given point in the region of the piece. Original title is given straight lines n, n + 1 into a rectangular area soon. We can each given point it is determined in th...

1023BPair of Toys

B. Pair of Toys http://codeforces.com/problemset/problem/1023/B Tanechka is shopping in the toy shop. There are exactly nn toys in the shop for sale, the cost of the ii-th toy is i...

[DP] toys

Stores are selling small C series favorite toy, the next n weeks, a weekly sell them, with a toy will not be repeated. Because it is a small C's favorite series, as much as he wants to buy these toys,...

poj2318——TOYS

Calculated on the basis of geometric entry problems, geometric problems have a strange sense of fear, has not done how geometry problem, so from now on brush geometry. Generally meaning of problems: i...

Smart toys

day95 - smart toys task day96 - smart toys task day97 - smart toys task day98 - smart toys task day99 - smart toys task...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top