POJ 1556 错误代码
来源:互联网 发布:金汇宝软件 编辑:程序博客网 时间:2024/06/09 16:43
POJ 1556 扔一个写错了代码 而且不知道那里错了
#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>#include <cmath>#include <queue>#include<iomanip>using namespace std;const int maxn = 1005;const double eps = 1e-8;const double INF = 1e9 + 7;int n;struct point { double x,y1,y2,y3,y4;}p[maxn];struct seg { double x1,y1,x2,y2;}segment[maxn];bool vis[maxn] = {0};double dd[maxn] = {0};int num = 0;int cnt = 0;struct node { double x,y;}points[maxn];int s,t;double d[maxn][maxn] = {0};double corss (double x1,double y1,double x2,double y2) { return x1 * y2 - x2 * y1;}double dist (double x1,double y1,double x2,double y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));}void spfa () { queue <int> q; q.push (s); for (int i = 0;i <= cnt; ++ i) { dd[i] = INF; } dd[s] = 0; while (!q.empty()) { int u = q.front(); q.pop(); for (int i = 1;i <= cnt; ++ i) { if (INF - d[u][i] > eps) { q.push (i); dd[i] = min(dd[i],dd[u] + d[u][i]); } } }}bool check (seg a,seg b) { if (!(max (a.x1,a.x2) > min (b.x1,b.x2) && max (b.x1,b.x2) > min (a.x1,a.x2) && max (a.y1,a.y2) > min (b.y1,b.y2) && max (b.y1,b.y2) > min (a.y1,a.y2))) return false; if (corss(b.x2 - b.x1, b.y2 - b.y1, a.x1 - b.x1, a.y1 - b.y1) * corss(b.x2 - b.x1, b.y2 - b.y1, a.x2 - b.x1, a.y2 - b.y1) < 0) { if (corss(a.x2 - a.x1, a.y2 - a.y1, b.x1 - a.x1, b.y1 - a.y1) * corss(a.x2 - a.x1, a.y2 - a.y1, b.x2 - a.x1, b.y2 - a.y1) < 0) return true; } return false;}bool judge (int p1,int p2) { seg temp = {points[p1].x,points[p1].y,points[p2].x,points[p2].y}; int flag = 1; for (int i = 0;i < num; ++ i) { if (check (temp,segment[i])) { flag = 0; break; } } if (flag) return true; return false;}int main () { ios_base :: sync_with_stdio(false); while (cin >> n) { if (n == -1) break; num = 0; cnt = 0; points[cnt ++] = {0,5}; for (int i = 0;i <= maxn; ++ i) { for (int j = 0;j <= maxn; ++ j) { d[i][j] = INF; } } for (int i = 1;i <= n; ++ i) { cin >> p[i].x >> p[i].y1 >> p[i].y2 >> p[i].y3 >> p[i].y4; points[cnt ++] = {p[i].x,p[i].y1}; points[cnt ++] = {p[i].x,p[i].y2}; points[cnt ++] = {p[i].x,p[i].y3}; points[cnt ++] = {p[i].x,p[i].y4}; segment[num ++] = {p[i].x,0,p[i].x,p[i].y1}; segment[num ++] = {p[i].x,p[i].y2,p[i].x,p[i].y3}; segment[num ++] = {p[i].x,p[i].y4,p[i].x,10}; } points[cnt] = {10,5}; for (int i = 0;i <= cnt; ++ i) { for (int j = i + 1;j <= cnt; ++ j) { if (judge (i,j)) { d[i][j] = dist(points[i].x, points[i].y, points[j].x, points[j].y); } } } s = 0,t = cnt; spfa (); if (INF - dd[t] < eps) { cout << -1 << endl; } else { cout<<fixed<<setprecision(2)<<dd[t]<<endl; } } return 0;}
阅读全文
0 0
- POJ 1556 错误代码
- 错误代码
- 错误代码!!!
- 错误代码
- 错误代码
- 错误代码
- ADO错误代码
- ASP错误代码
- IIS 错误代码
- 错误代码小结
- ASP错误代码
- .net错误代码
- 错误代码分析
- js错误代码
- C#错误代码
- HTTP错误代码
- 测试错误代码
- mysql 错误代码
- css中大div中的块级元素转为内联块产生的问题
- 数据结构——线性表——散列存储结构——哈希表知识点总结 原创 2017年05月14日 10:08:40 散列(hashing)是一种重要的存储方法,也是一种常见的查找方法。 基本思想:以结点的
- Keras的使用方法
- 跨域请求不被允许
- 安卓今日头条的框架的搭建
- POJ 1556 错误代码
- Codeforces 854A Fraction
- springboot-druid-mybatis多数据源使用
- 使用PullToRefresh实现下拉刷新和上拉加载
- 2017远景能源Java面试
- postman 简单教程-实现简单的接口测试
- python 网络上抓取数据处理并存入到Excel'中
- POJ
- HashMap解决hash冲突的方法