hdu4723--(How Long Do You Have to Draw)
2017-05-03 13:51
471 查看
题目大意:给出两条平行于x轴的直线y1和y2,y1上有n个点,y2上有m个点,用线段连接这些点,在使构成的三角形最多的情况下,线段总长度最小。题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4723。
大体思路:用c[maxn]、d[maxn]分别存储y1和y2直线上的点的横坐标,利用勾股定理求每条线段的长度,从左边数起,连接两条直线的第一个点,再计算y1直线的第二个点和y2直线的第一个点的水平距离,y2直线的第二个点和y1直线的第一个点的水平距离,比较两者大小,决定选取哪个点连接线段。
以下是ac代码:
大体思路:用c[maxn]、d[maxn]分别存储y1和y2直线上的点的横坐标,利用勾股定理求每条线段的长度,从左边数起,连接两条直线的第一个点,再计算y1直线的第二个点和y2直线的第一个点的水平距离,y2直线的第二个点和y1直线的第一个点的水平距离,比较两者大小,决定选取哪个点连接线段。
以下是ac代码:
#include<iostream> #include<sstream> #include<malloc.h> #include<map> #include<list> #include<bitset> #include<cctype> #include<iomanip> #include<utility> #include<stdlib.h> #include<functional> #include<stdio.h> #include<stack> #include<queue> #include<deque> #include<algorithm> #include<string> #include<string.h> #include<math.h> #include<set> #include<vector> using namespace std; const int maxn=1e5+5; double c[maxn],d[maxn]; double a,b; int main(){ int t; scanf("%d",&t); for(int Case=1;Case<=t;Case++){ scanf("%lf%lf",&a,&b); double n,m; scanf("%lf%lf",&n,&m); for(int i=0;i<n;i++) scanf("%lf",&c[i]); for(int i=0;i<m;i++) scanf("%lf",&d[i]); double sum=0; int i=0,j=0; double k=(a-b)*(a-b); while(i<n&&j<m){ sum+=sqrt(k+(c[i]-d[j])*(c[i]-d[j])); if(i==n-1) j++; else if(j==m-1) i++; else if(fabs(c[i+1]-d[j])<fabs(d[j+1]-c[i])) i++; else j++; } printf("Case #%d: %.2lf\n",Case,sum); } return 0; }
相关文章推荐
- hdu4723 How Long Do You Have to Draw 贪心
- HDU4723-How Long Do You Have to Draw
- HDU 4723 How Long Do You Have to Draw 解题报告
- hdu-4724-How Long Do You Have to Draw-贪心
- hdu 4723 How Long Do You Have to Draw(贪心)
- HDU 4723 How Long Do You Have to Draw
- hdu 4723 How Long Do You Have to Draw(贪心)
- hdoj-4723-How Long Do You Have to Draw
- HDU 4723 How Long Do You Have to Draw
- How to resolve: You do not have a license to use this ActiveX control
- how to solve the problem when you have chmod the directory to 777 but the apache still can not write file
- Http请求403错误:You do not have permission to get URL
- It appears as though you do not have permission to view information you requested........
- How to solve the problem : "You have been logged on with a temporary profile"
- VMware vCenter 5.5 – You do not have permission to login to the server
- How do you get the server to recognize changes to groups immediately?
- runInstaller-- you do not have sufficient permissions to access the inventory
- How To Find What You Love To Do
- VMware vCenter 5.5 – You do not have permission to login to the server