URAL 1647 Divide an Island!
2014-09-27 18:43
218 查看
题目链接:点击打开链接
#include <cstdio> #include <iostream> #include <iomanip> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const long double eps = 1e-13; #define y1 Y1 long double area(long double x1, long double y1, long double x2, long double y2) { return x1*y2-x2*y1; } long double dist(long double x1, long double y1, long double x2, long double y2) { return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } void work(long double x1, long double y1, long double x2, long double y2, long double d) { long double dx = x2 - x1, dy = y2 - y1; long double k = sqrt((dx * dx + dy * dy)/ d / d); cout << setprecision(20) << (dx / k + x1 + eps) << " " << (dy / k + y1 + eps) << endl; //printf("%.12f %.12f\n", dx / k + x1 + eps, dy / k + y1 + eps); } long double x1, x2, x3; long double y1, y2, y3; int main() { while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3) { long double a = dist(x2, y2, x3, y3); long double b = dist(x1, y1, x3, y3); long double c = dist(x1, y1, x2, y2); long double l = a+b+c; long double ansx, ansy; if(l*l-8*a*b > -eps) { ansx = (l - sqrt(l*l-8*a*b))/4.0; ansy = l / 2.0 - ansx; if(ansx > eps && ansx < a + eps && ansy > eps && ansy < b + eps) { puts("YES"); work(x3, y3, x2, y2, ansx); work(x3, y3, x1, y1, ansy); continue; } ansx = (l + sqrt(l*l-8*a*b))/4.0; ansy = l / 2.0 - ansx; if(ansx > eps && ansx < a + eps && ansy > eps && ansy < b + eps) { puts("YES"); work(x3, y3, x2, y2, ansx); work(x3, y3, x1, y1, ansy); continue; } } if(l*l-8*a*c > -eps) { ansx = (l - sqrt(l*l-8*a*c))/4.0; ansy = l / 2.0 - ansx; if(ansx > eps && ansx < a+ eps && ansy > eps && ansy < c+ eps) { puts("YES"); work(x2, y2, x3, y3, ansx); work(x2, y2, x1, y1, ansy); continue; } ansx = (l + sqrt(l*l-8*a*c))/4.0; ansy = l / 2.0 - ansx; if(ansx > eps && ansx <= a && ansy > eps && ansy <= c) { puts("YES"); work(x2, y2, x3, y3, ansx); work(x2, y2, x1, y1, ansy); continue; } } if(l*l-8*c*b > -eps) { ansx = (l - sqrt(l*l-8*c*b))/4.0; ansy = l / 2.0 - ansx; if(ansx > eps && ansx <= c && ansy > eps && ansy <= b) { puts("YES"); work(x1, y1, x2, y2, ansx); work(x1, y1, x3, y3, ansy); continue; } ansx = (l + sqrt(l*l-8*c*b))/4.0; ansy = l / 2.0 - ansx; if(ansx > eps && ansx <= c && ansy > eps && ansy <= b) { puts("YES"); work(x1, y1, x2, y2, ansx); work(x1, y1, x3, y3, ansy); continue; } } puts("NO"); } return 0; }
相关文章推荐
- Divide and Conquer:215. Kth Largest Element in an Array
- Ural 1671 - Anansi's Cobweb 倒过来做...并查集维护..
- 215. Kth Largest Element in an Array(divide and conquer)
- A story happened on an island 孤岛上的故事
- Ural1671-Anansi's Cobweb
- Divide and Conquer-215-Kth Largest Element in an Array
- leetcode_c++:Divide and Conquer:Kth Largest Element in an Array(215)
- URAL 1777 D - Anindilyakwa 暴力
- Economic Development of an Island Country
- No Man Is An Island(write by John Donne)
- URAL 1671 Anansi's Cobweb (并查集)
- Divide and Conquer (1) -- Kth Largest Element in an Array,Different Ways to Add Parentheses
- LeetCode OJ|Divide and Conquer|Kth Largest Element in an Array
- Divide and Conquer -- Leetcode problem215: Kth Largest Element in an Array
- Ural 1671 Anansi's Cobweb
- 【算法】【Divide and conquer】Kth Largest Element in an Array
- Ural 1671. Anansi's Cobweb
- leetCode刷题归纳-Divide and Conquer(215. Kth Largest Element in an Array)
- Ural 1671. Anansi's Cobweb(并查集)
- divide an integer into X parts (as even as possible)