zoukankan      html  css  js  c++  java
  • POJ 1375

    可以通过顶角角度来计算切线与坐标轴的坐标

    开始还以为有公式可以算,谁知道原来是解二元一次方程,靠。。

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    
    using namespace std;
    const int MAX=1050;
    
    struct point{
    	double x;
    	int flag;
    	point(){ flag=0;}
    }p[MAX];
    
    double dist(double x1,double y1,double x2,double y2){
    	return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    }
    
    bool cmp(point A, point B){
    	if(A.x<B.x)return true;
    	else if(A.x==B.x){
    		if(A.flag<B.flag) return true;
    	}
    	return false;
    }
    
    int main(){
    	double lx,ly; int n; double x,y,r;
    	while(scanf("%d",&n)!=EOF){
    		if(n==0) break;
    		scanf("%lf%lf",&lx,&ly);
    		for(int i=0;i<n;i++){
    			scanf("%lf%lf%lf",&x,&y,&r);
    			double dis=dist(lx,ly,x,y);
    			double Agle=asin(r/dis); double Bgle=asin((lx-x)/dis);
    			double bx=lx-ly*tan(Agle+Bgle); 
    			double ex=lx-ly*tan(Bgle-Agle);
    			p[2*i].x=bx; p[2*i].flag=-1;
    			p[2*i+1].x=ex; p[2*i+1].flag=1;
    		}
    		sort(p,p+2*n,cmp);
    		int now=0; double L;
    		for(int i=0;i<2*n;i++){
    			if(now==0){
    			L=p[i].x;
    			}
    			now+=p[i].flag;
    			if(now==0)
    			printf("%0.2f %0.2f
    ",L,p[i].x);
    		}
    		printf("
    ");
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    Stimulsoft Reports筛选数据来绑定显示2个报表
    随便写点吧
    盒模型、文档流
    css选择器、权重
    css3转换
    html
    css新起点
    css里的那些事儿
    【谭老师讲堂】零基础如何学好Java——交流
    【谭老师讲堂】零基础如何学好Java——棒棒糖
  • 原文地址:https://www.cnblogs.com/jie-dcai/p/3874217.html
Copyright © 2011-2022 走看看