• 【POJ2318】—TOYS(计算几何)


    传送门

    看到都用二分,似乎没必要吧…
    直接枚举也能过

    二分边界什么的弄得我想死…

    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<cstdio>
    using namespace std;
    #define eps 1e-8
    inline int read(){
    	char ch=getchar();
    	int res=0,f=1;
    	while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
    	while(isdigit(ch))res=(res<<3)+(res<<1)+(ch^48),ch=getchar();
    	return res*f;	
    } 
    const int N=5005;
    struct point{
    	int x,y;
    	point(double a=0,double b=0){
    		x=a,y=b;
    	}
    	friend inline point operator -(const point &a,const point &b){
    		return point(a.x-b.x,a.y-b.y);
    	}
    	friend inline int operator *(const point &a,const point &b){
    		return a.x*b.y-a.y*b.x;
    	}
    };
    struct line{
    	point a,b;
    }p[N];
    int n,m,x1,x2,yx,y2;
    short ans[N];
    inline void calc(point a){
    	int l=0,r=n-1,res=n;
    	while(l<r){
    		int mid=(l+r)>>1;
    		if((a-p[mid].b)*(p[mid].a-p[mid].b)>0)l=mid+1;
    		else r=mid;
    	}
    	if((a-p[l].b)*(p[l].a-p[l].b)<0)ans[l]++;
    	else ans[l+1]++;
    }
    int main(){
    	n=read();
    	while(n){
    		m=read(),x1=read(),yx=read(),x2=read(),y2=read();
    		for(int i=0;i<n;i++){
    			p[i].a.x=read(),p[i].a.y=yx;
    			p[i].b.x=read(),p[i].b.y=y2;
    		}
    		memset(ans,0,sizeof(ans));
    		for(int i=1;i<=m;i++){
    			int x=read(),y=read();
    			calc(point(x,y));
    		}
    		for(int i=0;i<=n;i++)cout<<i<<": "<<ans[i]<<'
    ';puts("");
    		n=read();
    	}
    }
    
  • 相关阅读:
    在虚拟机安装Oracle EF步骤
    ORACLE数据库入门级及操作杂记
    软技能-代码之外的生存指南读后感
    RabbitMQ 使用demo
    RabbitMQ 应用学习随笔
    mysql 发生死锁时,解决方法
    GBase存过--工作实战
    Oracle存储过程--工作实战
    浅谈Oracle、MySQL和Gbase的使用体验(一)
    seajs学习笔记
  • 原文地址:https://www.cnblogs.com/stargazer-cyk/p/11145669.html
Copyright © 2020-2023  润新知