poj 2826(好坑,线段相交问题)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 11576 | Accepted: 1760 |
Description
Your mission is to calculate how much rain these two boards can collect.
Input
Each test case consists of 8 integers not exceeding 10,000 by absolute value, x1, y1, x2, y2, x3, y3, x4, y4. (x1, y1), (x2, y2) are the endpoints of one board, and (x3, y3), (x4, y4) are the endpoints of the other one.
Output
each test case output a single line containing a real number with
precision up to two decimal places - the amount of rain collected.
Sample Input
2
0 1 1 0
1 0 2 1 0 1 2 1
1 0 1 2
Sample Output
1.00
0.00
一点都不easy...
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAwAAAAFSCAIAAADKOi8MAAATP0lEQVR4nO3dXYKiuhYGUMfFgBiPo3EyDIZ+ULsQAqICSdhrvdx7qvyJJOz9dUTr0gMABHPJPQAAgKMJQABAOAIQABCOAAQAhCMAAQDhCEAAQDgCEAAQjgAEAIQjAAEA4QhAAEA4AhAAEI4ABACEIwABAOEIQABAOAIQABCOAAQAhCMAAQDhCEAAQDgCEAAQjgAEAIQjAAEA4QhAAEA4AhAAEI4ABACEIwABAOEIQEDdLk+5BwLURMkAKnZ5lXs4QDXUC6BWl4ncIwKqoV4AVZqmHwEIWE+9AOoj/QA/UjKAykg/wO9UDaAm0g+wCYUDqIb0A2xF7QCqIf0AW1E+gDpIP8CGVBCgAt78AralggClk36AzSkiQNGkH2AP6ghQLukH2IlSApQoGX2kH2ArqglQHOkH2JuCApRF+gEOoKYABZF+gGMoK0AppB/gMCoLUATpBziS4gLkJ/rUxRxxApYvkJn0UxczxTlYu0BO0k91TBbnYO0C2Ug/1TFfnIa1C+Qh/dTIfHEali+QgfRTI1PGmVi+wNGknxqZMk7GCgYOJf1UyqxxMlYwcBzpp1JmjfOxiIGDSD/1Mmucj3UMHEH6qZeJ45SsY2B30k/VTBynZCkD+5J+qmbuOCtLGdiR9FM1c8eJWc3AXqSf2pk+Tsxq5lcqI0nST+1MH+dmQfOT3+uj2npK0s8JmD7Oz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kIEABOSl7gAZCEBAXuoOkIEABOSl7gAZCEBAXuoOkIf0A2Sk9AAA4QhAAEA4AhAAEI4ABACEIwABAOEIQABAOAIQABCOAAQAhCMAAQDhCEAAQDgCEAAQjgAEAIQjAAEA4QhAAEA4AhAAEI4ABACEIwABAOEIQABAOAIQABCOAAQAhCMAAQDhCEAAQDgCEAAQjgAEAIQjAAEA4QhAAEA4AhAAEI4ABACEIwABAOEIQABAOAIQABCOAAQAhCMAAQDhCEAAQDgCEAAQjgAEAIQjAAEA4QhAAEA4AhAAEI4ABACEIwABAOEIQABAOAIQABCOAAQAhCMAAQDhCEAAQDgCEAAQjgAEAIQjAAEA4QhAAEA4AhAAEI4ABACEIwABAOEIQABAOAIQABCOAAQAhCMAAQDhCEAAQDgCEAAQjgAEAIQjAAEA4QhAAEA4AhAAEI4ABACEIwABAOEIQABAOAIQABCOAAQAhCMAAQDh/AOmrETXblNPPQAAAABJRU5ErkJggg==" alt="" width="439" height="193" />没能AC的看看吧。。
discuss里面参考数据:
9
样例一:
6259 2664 8292 9080 1244 2972 9097 9680
答案:6162.65 样例二:
0 1 1 0
1 0 2 1
答案:1.00 样例三:
0 1 2 1
1 0 1 2
答案:0.00 样例四:
0 0 10 10
0 0 9 8
答案:0.00 样例五:
0 0 10 10
0 0 8 9
答案:4.50 样例六: //这组数据其实我没过也AC了
0.9 3.1 4 0
0 3 2 2
答案:0.50 样例七:
0 0 0 2
0 0 -3 2
答案:3.00 样例八:
1 1 1 4
0 0 2 3
答案:0.75 样例九:
1 2 1 4
0 0 2 3
答案:0.00
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
const double eps = 1e-;
struct Point
{
double x,y;
};
double cross(Point a,Point b,Point c)
{
return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);
}
///规范相交
bool isCross(Point a,Point b,Point c,Point d)
{
if(cross(c,b,a)*cross(b,d,a)<-eps) return false; ///这里要改成eps我上面的那组数据才能为0.5..不过是0也能AC。。so strange
if(cross(a,d,c)*cross(d,b,c)<-eps) return false;
return true;
}
///计算两条直线的交点
Point intersection(Point a,Point b,Point c,Point d)
{
Point p = a;
double t = ((a.x-c.x)*(c.y-d.y)-(a.y-c.y)*(c.x-d.x))/((a.x-b.x)*(c.y-d.y)-(a.y-b.y)*(c.x-d.x));
p.x +=(b.x-a.x)*t;
p.y +=(b.y-a.y)*t;
return p;
}
int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--)
{
Point a,b,c,d;
scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y);
scanf("%lf%lf%lf%lf",&c.x,&c.y,&d.x,&d.y);
if(a.y==b.y||c.y==d.y||!isCross(a,b,c,d)) ///排除水平放置还有不相交的情况
{
printf("0.00\n");
continue;
}
Point p = intersection(a,b,c,d); ///交点
double y = min(max(a.y,b.y),max(c.y,d.y));
if(y<=p.y) ///上面的y不可能小于交点,不然接不到水
{
printf("0.00\n");
continue;
}
///我只要y上面的点
Point t1,t2;
if(a.y>b.y) t1 = a;
else t1 = b;
if(c.y>d.y) t2 = c;
else t2 = d;
///两个向量极角大的x坐标必定小于极角小的,不然雨水没办法流进去
if(cross(t1,t2,p)>&&t1.x>t2.x||cross(t2,t1,p)>&&t2.x>t1.x)
{
double k,B,x,x0;
if(y==t1.y)
{
x = t1.x;
if(t2.x==p.x) ///这里略坑
{
x0 = p.x;
}
else
{
k = (t2.y- p.y)/(t2.x - p.x);
B = t2.y-k*t2.x;
x0 = (y-B)/k;
}
}
else
{
x = t2.x;
if(t1.x==p.x)
{
x0 = p.x;
}
else
{
k = (t1.y- p.y)/(t1.x - p.x);
B = t1.y-k*t1.x;
x0 = (y-B)/k;
} }
double l = fabs(x-x0);
double h = fabs(y-p.y);
printf("%.2lf\n",l*h/);
continue;
}
printf("0.00\n");
}
return ;
}
poj 2826(好坑,线段相交问题)的更多相关文章
- POJ 1066 Treasure Hunt(线段相交判断)
Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4797 Accepted: 1998 Des ...
- POJ 2653 Pick-up sticks(线段相交)
题意:给定n个木棍依次放下,要求最终判断没被覆盖的木棍是哪些. 思路:快速排斥以及跨立实验可以判断线段相交. #include<algorithm> #include<cstdio& ...
- poj 3304(直线与线段相交)
传送门:Segments 题意:线段在一个直线上的摄影相交 求求是否存在一条直线,使所有线段到这条直线的投影至少有一个交点 分析:可以在共同投影处作原直线的垂线,则该垂线与所有线段都相交<==& ...
- [poj 1127]Jack Straws[线段相交][并查集]
题意: 给出一系列线段,判断某两个线段是否连通. 思路: 根据线段相交情况建立并查集, 在同一并查集中则连通. (第一反应是强连通分量...实际上只要判断共存即可, 具体的方向啊是没有关系的..) 并 ...
- POJ 2653 Pick-up sticks [线段相交 迷之暴力]
Pick-up sticks Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 12861 Accepted: 4847 D ...
- POJ 1066--Treasure Hunt(判断线段相交)
Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7857 Accepted: 3247 Des ...
- POJ 1127 Jack Straws (线段相交)
题意:给定一堆线段,然后有询问,问这两个线段是不是相交,并且如果间接相交也可以. 析:可以用并查集和线段相交来做,也可以用Floyd来做,相交就是一个模板题. 代码如下: #pragma commen ...
- TTTTTTTTTTTTTT poj 1127 Jack Straws 线段相交+并查集
题意: 有n个木棍,给出木棍的两个端点的x,y坐标,判断其中某两个线段是否连通(可通过其他线段连通) #include <iostream> #include <cstdio> ...
- POJ 1039 直线和线段相交
题意: 题意很好理解,从左边射过来的光线,最远能经过管道到右边多少距离. 分析: 光线一定经过一个上端点和一个下端点,这一点很容易想到.然后枚举上下端点即可 #include <iostream ...
随机推荐
- android自定义View绘制圆形头像与椭圆头像
要实现这两种效果,需要自定义View,并且有两种实现方式. 第一种: public class BitmapShaders extends View { private BitmapSh ...
- mysql 5.7 Access denied for user 'root'@'localhost' solution
sudo vim /etc/mysql/debian.cnf # Automatically generated for Debian scripts. DO NOT TOUCH! [client] ...
- red入门学习笔记
删除以name开头的所有键值. 查找开头和结尾相同,中间字符不同
- WebService使用介绍(二)
Soap soap是什么 SOAP 是一种网络通信协议 SOAP即Simple Object Access Protocol简易对象访问协议 SOAP 用于跨平台应用程序之间的通信 SOAP 被设计用 ...
- BZOJ4584 APIO2016赛艇(动态规划+组合数学)
如果值域不大,容易想到设f[i][j]为第i个学校选了j的方案数,枚举上一个学校是哪个选了啥即可,可以前缀和优化.于是考虑离散化,由于离散化后相同的数可能可以取不同的值,所以枚举第一个和其所选数(离散 ...
- [洛谷P3567][POI2014]KUR-Couriers
题目大意:给一个数列,每次询问一个区间内有没有一个数出现次数超过一半.有,输出这个数,否则输出$0$ 题解:主席树,查询区间第$\bigg\lfloor\dfrac{len+1}{2}\bigg\rf ...
- 活泼的CSS 3动态气泡按钮制作
这一次,我们正在创造一个有用的设置与对CSS3的多重背景和动画的力量动画按钮.通过此按钮包,您可以很容易地变成一个动画按钮,在您的网页上的任何链接只是指定一个类名.没有必要JavaScript.四色主 ...
- Java的外部类为什么不能使用private、protected进行修饰
对于顶级类(外部类)来说,只有两种修饰符:public和默认(default).因为外部类的上一单元是包,所以外部类只有两个作用域:同包,任何位置.因此,只需要两种控制权限:包控制权限和公开访问权限, ...
- 学习python类
类:Python 类提供了面向对象编程的所有基本特征: 允许多继承的类继承机制, 派生类可以重写它父类的任何方法, 一个方法可以调用父类中重名的方法. 对象可以包含任意数量和类型的数据成员. 作为模块 ...
- JS知识总结
1.javascript继承机制 原型继承,访问对象属性时,如果对象内部有就返回,找不到就会从对象原型指向的对象原型中查找,一层一层的查找,直到最顶层的对象原型还找不到,就返回undefined. 2 ...