Ural_1215. Exactness of Projectile Hit

  /*做了两天,终于AC了。各种参考啊,判段点是否在多边形内是参考的网上的代码;
求点到直线的距离是师兄传授的一套模板,只能说有好的模板就是好啊,自己写了好几遍
没过,用师兄的模板写了一遍过了。

思路:

1、用叉积判断点是否在多边形内。

2、求点到每个边的距离的最小值。
*/

//My Code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

const int N = 110;
const double eps = 1e-6;
const double inf = 1e+8;

struct point {
double x;
double y;
}p[N], c;

int n;

double cross_product(point a, point b){
return (c.x - a.x)*(b.y - a.y) - (b.x - a.x)*(c.y - a.y);
}

int in_circle() {
int i; p[n] = p[0]; p[n+1] = p[1];
for(i = 0; i < n; i++)
if(cross_product(p[i], p[i+1]) * cross_product(p[i+1], p[i+2]) < eps)
return false;
return true;
}

double distan(point a, point b) {
return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}

//好模板啊。。。
double dis(point pa, point pb) {
double A, B, C, l, s;

A = distan(pb, c);
if(A < eps) return 0;

B = distan(pa, c);
if(B < eps) return 0;

C = distan(pa, pb);
if(C < eps) return A;

if(B*B >= A*A + C*C) return A;
if(A*A >= B*B + C*C) return B;

l = (A+B+C)/2;
s = sqrt(l*(l-A)*(l-B)*(l-C));
return 2*s/C;
}

int main() {
//freopen("data.in", "r", stdin);

int i;
scanf("%lf%lf%d", &c.x, &c.y, &n);
for(i = 0; i < n; i++)
scanf("%lf%lf", &p[i].x, &p[i].y);
if(in_circle()){
printf("0.000\n"); return 0;
}

double ans = inf; p[n] = p[0];
for(i = 0; i < n; i++)
if(ans - dis(p[i], p[i+1]) > eps)
ans = dis(p[i], p[i+1]);
printf("%.3lf\n", 2*ans);
return 0;
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【1】项目代码完整且功能都验证ok,确保稳定可靠运行后才上传。欢迎下载使用!在使用过程中,如有问题或建议,请及时私信沟通,帮助解答。 【2】项目主要针对各个计算机相关专业,包括计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网等领域的在校学生、专业教师或企业员工使用。 【3】项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 【4】如果基础还行,或热爱钻研,可基于此项目进行二次开发,DIY其他不同功能,欢迎交流学习。 【注意】 项目下载解压后,项目名字和项目路径不要用中文,否则可能会出现解析不了的错误,建议解压重命名为英文名字后再运行!有问题私信沟通,祝顺利! 基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip基于C语言实现智能决策的人机跳棋对战系统源码+报告+详细说明.zip
用代码解决这个问题The program committee of the school programming contests, which are often held at the Ural State University, is a big, joyful, and united team. In fact, they are so united that the time spent together at the university is not enough for them, so they often visit each other at their homes. In addition, they are quite athletic and like walking. Once the guardian of the traditions of the sports programming at the Ural State University decided that the members of the program committee spent too much time walking from home to home. They could have spent that time inventing and preparing new problems instead. To prove that, he wanted to calculate the average distance that the members of the program committee walked when they visited each other. The guardian took a map of Yekaterinburg, marked the houses of all the members of the program committee there, and wrote down their coordinates. However, there were so many coordinates that he wasn't able to solve that problem and asked for your help. The city of Yekaterinburg is a rectangle with the sides parallel to the coordinate axes. All the streets stretch from east to west or from north to south through the whole city, from one end to the other. The house of each member of the program committee is located strictly at the intersection of two orthogonal streets. It is known that all the members of the program committee walk only along the streets, because it is more pleasant to walk on sidewalks than on small courtyard paths. Of course, when walking from one house to another, they always choose the shortest way. All the members of the program committee visit each other equally often. Input The first line contains the number n of members of the program committee (2 ≤ n ≤ 105). The i-th of the following n lines contains space-separated coordinates xi, yi of the house of the i-th member of the program committee (1 ≤ xi, yi ≤ 106). All coordinates are integers. Output Output the average distance, rounded down to an integer, that a member of the program committee walks from his house to the house of his colleague.
05-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值