hdu4195Regular Convex Polygon poj2242The Circumference of the Circle

//hdu4195
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const double eps=1e-6;//这个错了可能wa
const double pi=acos(-1.0);
inline bool dcmp(double x){
    if(x<eps)return 0;
    return x>0?1:-1;
}
struct pt{
    double x,y;
    pt(){}
    pt(double xx,double yy):x(xx),y(yy){}
    friend pt operator -(pt a,pt b){
        return pt(a.x-b.x,a.y-b.y);
    }
    friend pt operator *(pt a,double b){
        return pt(a.x*b,a.y*b);
    }
};
inline bool isint(double x){
    return fabs(x-(int)(x+0.5))<eps;
}
inline double dis(pt a,pt b){
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
inline double cross(pt a,pt b){
    return a.x*b.y-a.y*b.x;
}
inline pair<pt,int> circle(pt a,pt b,pt c){
    pt ret,t1=(b-a)*2,t2=(c-b)*2;
    double t3=b.x*b.x+b.y*b.y-a.x*a.x-a.y*a.y,t4=c.x*c.x+c.y*c.y-b.x*b.x-b.y*b.y;
    ret.x=(t1.y*t4-t2.y*t3)/(t1.y*t2.x-t2.y*t1.x);
    ret.y=(t2.x*t3-t1.x*t4)/(t1.y*t2.x-t2.y*t1.x);
    return make_pair(ret,dis(ret,a));
}
inline double angle(pt a,pt b,pt o){
    double ao=atan2(a.y-o.y,a.x-o.x);
    double bo=atan2(b.y-o.y,b.x-o.x);
    return fabs(ao-bo)>=pi?(pi*2-fabs(ao-bo)):fabs(ao-bo);
}
int main(){
    pt p[3],o;
    double r;
    char s[50];
    while(gets(s)&&strcmp(s,"END")){
        sscanf(s,"%lf%lf",&p[0].x,&p[0].y);
        scanf("%lf%lf",&p[1].x,&p[1].y);
        scanf("%lf%lf",&p[2].x,&p[2].y);
        getchar();
        pair<pt,int> tmp=circle(p[0],p[1],p[2]);
        o=tmp.first;r=tmp.second;
        double a=180*angle(p[0],p[1],o)/pi,b=180*angle(p[1],p[2],o)/pi;
        double c=180*angle(p[0],p[2],o)/pi;
        //cout<<a<<' '<<b<<endl;
        int cnt=3;
        for(;cnt<1000;cnt++){
            if(isint(a*cnt/360)&&isint(b*cnt/360)&&isint(c*cnt/360)) break;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

poj2242

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const double eps=1e-8;
const double pi=3.141592653589793;
struct pt{
    double x,y;
    pt(){}
    pt(double xx,double yy):x(xx),y(yy){}
    friend pt operator -(pt a,pt b){
    return pt(a.x-b.x,a.y-b.y);
    }
    friend pt operator *(pt a,double k){
        return pt(a.x*k,a.y*k);
    }
};
inline double dis(pt a,pt b){
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
inline double circum(pt a,pt b,pt c){
    pt t1=(b-a)*2,t2=(c-b)*2,ret;
	double t3=b.x*b.x+b.y*b.y-a.x*a.x-a.y*a.y,t4=c.x*c.x+c.y*c.y-b.x*b.x-b.y*b.y;
	ret.x=(t1.y*t4-t2.y*t3)/(t1.y*t2.x-t2.y*t1.x);
	ret.y=(t2.x*t3-t1.x*t4)/(t1.y*t2.x-t2.y*t1.x);
	return 2*pi*dis(ret,a);
}
int main(){
    pt p[3];
    int i;
    while(scanf("%lf%lf%lf%lf%lf%lf",&p[0].x,&p[0].y,&p[1].x,&p[1].y,&p[2].x,&p[2].y)!=EOF){
        //for(int i=0;i<3;i++)printf("%.2f %.2f\n",p[i].x,p[i].y);
        printf("%.2f\n",circum(p[0],p[1],p[2]));
       // getchar();
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值