源码力量

Math Algorithm Art

HDU 3694计算几何

/****************************************************************************************************
找四边形的Fermat点，对于任意多边形来说找Fermat点的方法就是模拟退火，但是这道题貌似故意卡模拟退火的精度，试了好多次

****************************************************************************************************/
#include <iostream>
#include <functional>
#include <algorithm>
//#include <hash_map>		//Visual C++ lib
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <sstream>
#include <utility>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <limits>
#include <memory>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;

#define LOWBIT(x) ( (x) & ( (x) ^ ( (x) - 1 ) ) )
#define CLR(x, k) memset((x), (k), sizeof(x))
#define CPY(t, s) memcpy((t), (s), sizeof(s))
#define SC(t, s) static_cast<t>(s)
#define LEN(s) static_cast<int>( strlen((s)) )
#define SZ(s) static_cast<int>( (s).size() )

typedef double LF;
//typedef long long LL;		//GNU C++
//typedef unsigned long long ULL;
typedef __int64 LL;		//Visual C++ 2010
typedef unsigned __int64 ULL;

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;

//typedef hash_map<int, int>::iterator HMI;
typedef map<int, int>::iterator MI;
typedef vector<int>::iterator VI;
typedef list<int>::iterator LI;
typedef set<int>::iterator SI;

template <typename T>
T sqa(const T &x)
{
return x * x;
}

const int INF_INT = 0x3f3f3f3f;
const LL INF_LL = 0x7fffffffffffffffLL;		//15f
const double oo = 10e9;
const double eps = 10e-9;
const double PI = acos(-1.0);

const int MAXN = 6;

struct Point
{
LF x, y;
Point()
{
x = y = 0.0;
}
Point(const LF &_x, const LF &_y)
{
x = _x;
y = _y;
}
}pnt[MAXN];
struct Seg
{
LF a, b, c;
Seg()
{
a = b = c = 0.0;
}
Seg(const LF &_a, const LF &_b, const LF &_c)
{
a = _a;
b = _b;
c = _c;
}
};
int n;

bool inline equals(const LF &a, const LF &b)
{
return fabs(a - b) < eps;
}
bool parallel(const Seg &sa, const Seg &sb)
{
return fabs(sa.a * sb.b - sa.b * sb.a) < eps;
}
LF dist(const Point &pa, const Point &pb)
{
return sqrt( sqa(pa.x - pb.x) + sqa(pa.y - pb.y) );
}
Seg getseg(const Point &pa, const Point &pb)
{
Seg sr(pb.y - pa.y, pa.x - pb.x, pa.y * pb.x - pa.x * pb.y);
return sr;
}
LF get_all_dist(const Point &pk, const int &n)
{
LF res = 0.0;
for (int i = 0; i < n; ++i)
{
res += dist(pk, pnt[i]);
}
return res;
}
Point cross(const Seg &sa, const Seg &sb)
{
Point pr;
pr.x = (sb.c * sa.b - sa.c * sb.b) / (sa.a * sb.b - sb.a * sa.b);
pr.y = (-sa.c - sa.a * pr.x) / sa.b;
return pr;
}
void ace()
{
n = 4;
bool end_sign;
LF mi;
Seg sa, sb;
while (true)
{
end_sign = true;
for (int i = 0; i < n; ++i)
{
cin >> pnt[i].x >> pnt[i].y;
if (!equals(-1.0, pnt[i].x) || !equals(-1.0, pnt[i].y))
{
end_sign = false;
}
}
if (end_sign)
{
break ;
}
mi = oo;
for (int i = 0; i < n; ++i)
{
mi = min(mi, get_all_dist(pnt[i], n));
}
sa = getseg(pnt[0], pnt[1]);
sb = getseg(pnt[2], pnt[3]);
if (!parallel(sa, sb))
{
mi = min(mi, get_all_dist( cross(sa, sb), n ) ) ;
}
sa = getseg(pnt[0], pnt[2]);
sb = getseg(pnt[1], pnt[3]);
if (!parallel(sa, sb))
{
mi = min(mi, get_all_dist( cross(sa, sb), n ) );
}
sa = getseg(pnt[0], pnt[3]);
sb = getseg(pnt[1], pnt[2]);
if (!parallel(sa, sb))
{
mi = min(mi, get_all_dist( cross(sa, sb), n ) );
}
printf("%.4lf\n", mi);
}
return ;
}
int main()
{
ace();
return 0;
}

HDU 1071 The area（计算几何）

2015-08-29 11:14:31

hdu 6127 Hard challenge (计算几何——斜率排序)

2017-08-16 13:25:40

hdu 4946 Area of Mushroom 计算几何（凸包）

2014-08-14 18:36:09

HDU - 2671(计算几何)

2017-09-02 20:17:02

HDU 1756 (计算几何 点在多边形内)

2015-11-10 17:18:11

HDU6055 Regular polygon(计算几何,2017 HDU多校联赛 第2场)

2017-07-27 18:45:03

hdu6055（计算几何）计算n个整数点中有多少个正方形

2017-07-27 20:23:51

ACM-计算几何之Shape of HDU——hdu2108

2014-04-21 12:04:48

HDU 1392 (计算几何 凸包)

2015-11-11 11:38:59

hdu2108Shape of HDU 计算几何

2016-08-10 15:54:50