原题链接:信息学奥赛一本通T1439-传送带
#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #include<bitset> #define PI acos(-1.0) #define INF 0x3f3f3f3f #define LL long long #define Pair pair<int,int> const double EPS = 1E-10; const int MOD = 1E9+7; const int N = 10000+5; const int dx[] = {-1,1,0,0,-1,-1,1,1}; const int dy[] = {0,0,-1,1,-1,1,-1,1}; using namespace std; struct Node{ double x,y; Node(){} Node(double x,double y):x(x),y(y){} }a,b,c,d; double p,q,r; double getDis(double x1,double y1,double x2,double y2){ return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } double judge(Node e){ Node left(c.x,c.y),right(d.x,d.y); int times=100;//控制三分次数 while(times--){ Node lmid,rmid; lmid.x=left.x+(right.x-left.x)/3; lmid.y=left.y+(right.y-left.y)/3; rmid.x=right.x-(right.x-left.x)/3; rmid.y=right.y-(right.y-left.y)/3; double dis1=getDis(lmid.x,lmid.y,d.x,d.y)/q+getDis(lmid.x,lmid.y,e.x,e.y)/r; double dis2=getDis(rmid.x,rmid.y,d.x,d.y)/q+getDis(rmid.x,rmid.y,e.x,e.y)/r; if(dis1<dis2){ right.x=rmid.x; right.y=rmid.y; } else{ left.x=lmid.x; left.y=lmid.y; } } return getDis(left.x,left.y,d.x,d.y)/q+getDis(left.x,left.y,e.x,e.y)/r+getDis(e.x,e.y,a.x,a.y)/p; } int main(){ scanf("%lf%lf",&a.x,&a.y); scanf("%lf%lf",&b.x,&b.y); scanf("%lf%lf",&c.x,&c.y); scanf("%lf%lf",&d.x,&d.y); scanf("%lf%lf%lf",&p,&q,&r); Node left(a.x,a.y),right(b.x,b.y); int times=100;//控制三分次数 while(times--){ Node lmid,rmid; lmid.x=left.x+(right.x-left.x)/3; lmid.y=left.y+(right.y-left.y)/3; rmid.x=right.x-(right.x-left.x)/3; rmid.y=right.y-(right.y-left.y)/3; if(judge(lmid)<judge(rmid)){ right.x=rmid.x; right.y=rmid.y; } else{ left.x=lmid.x; left.y=lmid.y; } } printf("%.2lf",judge(left)); return 0; }
0.0分
0 人评分
C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程
发表评论 取消回复