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;
}


内容概要:本文围绕“栅格内牛耕”策略与A星(A*)算法相结合的全覆盖路径规划方法展开研究,提出了一种适用于栅格化环境的高效路径规划方案。通过引入系统性的“牛耕式”扫描策略,确保对区域内所有有效栅格的无遗漏覆盖,并融合A*算法进行路径优化,提升路径的合理性与执行效率。该方法特别适用于需完成全域遍历任务的智能设备,如清洁机器人、农业自动化机械和巡检无人机等。文中详细阐述了算法的设计思路、关键实现步骤及启发式函数的改进机制,并借助Matlab平台进行了仿真实验,验证了该方法在复杂障碍环境下的有效性与鲁棒性。; 适合人群:具备一定Matlab编程基础,从事路径规划、智能机器人、自动化控制等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于扫地机器人、无人农场农机、巡检机器人等需实现区域全覆盖作业的设备路径规划;②帮助研究人员深入理解A*算法在全覆盖场景中的改进策略,掌握覆盖优先级、方向约束与回溯机制的设计方法;③作为教学与科研案例,辅助学习启发式搜索算法与系统性覆盖策略的融合应用。; 阅读建议:建议读者结合提供的Matlab代码进行实践操作,重点分析A*算法在覆盖完整性与路径最优化之间的平衡机制,通过调整环境地图、障碍物分布及起始点位置开展多组仿真实验,深入探究算法性能影响因素与优化方向。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值