An Easy Problem?!(细节题,要把所有情况考虑到)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 10505 | Accepted: 1584 |
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
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 题解:判断可以接多少水,如果两直线可以接水的话,求三角形面积
下面给出一些计算几何最基础的结论(常用)
两向量点乘: a*b*cosO = x1*y1+x2*y2 用来 1 :计算夹角 2:计算投影
两向量叉乘: a*b*sinO = x1*y1-x2*y2 用来 1:计算面积 2:判断点在直线的哪边,右手法则
这个题输出的时候要注意,用G++交题的时候要最后输出ans+eps;
下面是代码:
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std; #define N 105
#define eps 1e-6//精度太小会导致出错,精度太大会增加计算量,自己权衡
struct point {
double x, y;
point(){}
point(double x, double y):x(x), y(y){}
point operator + (const point o) const{
return point(x+o.x, y+o.y);
}
point operator - (const point o) const{
return point(x-o.x, y-o.y);
} double operator * (const point o) const{
return x*o.y - o.x*y;
} double operator ^ (const point o) const{//点乘
return x*o.x + y*o.y;
} point operator * (const double a) const{
return point(a*x, a*y);
} double len2()
{
return x*x + y*y;
}
}a, b, s, t; point Intersection(point a, point b, point c, point d)
{
double t = ((d - a)*(c - a))/((b - a)*(d - c));
return a + (b-a)*fabs(t);
} int main()
{
point a, b, c, d;
int T;
scanf("%d", &T);
while(T--)
{
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(fabs(a.y - b.y) < eps || fabs(c.y - d.y) < eps)//有水平线
{
puts("0.00");
continue;
} if(a.y < b.y) swap(a, b);
if(c.y < d.y) swap(c, d); if(fabs((b.y-a.y)*(d.x-c.x) - (d.y-c.y)*(b.x-a.x)) < eps) //两条线平行
{
puts("0.00");
continue;
} if(((b-a)*(c-a))*((b-a)*(d-a)) > || ((d-c)*(a-c))*((d-c)*(b-c)) > )//两条线段根本没有交点
{
puts("0.00");
continue;
}
point p = Intersection(a, b, c, d);
point up = point(,);
if(((a-p)*(up)) * ((c-p)*(up)) > )//能收集雨水的部分在竖直线的同一侧
{
if((a-p)*(c-p) > && c.x- a.x>= -eps)
{
puts("0.00");
continue;
}
if((a-p)*(c-p) < && a.x- c.x>= -eps)
{
puts("0.00");
continue;
}
}
point t1, t2;
t1.y = t2.y = min(a.y, c.y);
t1.x = a.x + (b.x - a.x)*(t1.y - a.y)/(b.y-a.y);
t2.x = c.x + (d.x - c.x)*(t2.y - c.y)/(d.y-c.y);
double ans = fabs((t1.x - t2.x) * (t1.y-p.y)/2.0);
printf("%.2f\n", ans+eps); //控制精度,
}
return ;
}
An Easy Problem?!(细节题,要把所有情况考虑到)的更多相关文章
- HDU 5475:An easy problem 这题也能用线段树做???
An easy problem Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDOJ(HDU) 2123 An easy problem(简单题...)
Problem Description In this problem you need to make a multiply table of N * N ,just like the sample ...
- UESTC 1591 An easy problem A【线段树点更新裸题】
An easy problem A Time Limit: 2000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others ...
- HDU 5475 An easy problem 线段树
An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDOJ(HDU) 2132 An easy problem
Problem Description We once did a lot of recursional problem . I think some of them is easy for you ...
- Codeforces Round #392 (Div. 2)-758D. Ability To Convert(贪心,细节题)
D. Ability To Convert time limit per test 1 second Cmemory limit per test 256 megabytes input standa ...
- CJOJ 2485 UVa 11991 生日礼物 / UVa 11991 Easy Problem from Rujia Liu?
CJOJ 2485 UVa 11991 生日礼物 / UVa 11991 Easy Problem from Rujia Liu? Description (原题来自刘汝佳<训练指南>Pa ...
- hdu2601 An easy problem(数学)
题目意思: http://acm.hdu.edu.cn/showproblem.php? pid=2601 给出一个数N,求N=i*j+i+j一共同拥有多少种方案. 题目分析: 此题直接暴力模拟就可以 ...
- [poj 2453] An Easy Problem
An Easy Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8371 Accepted: 5009 D ...
随机推荐
- Hosts文件实际应用 配置内部服务器提高访问效率和速度
一 hosts文件的作用和介绍 https://jingyan.baidu.com/article/335530da45485e19cb41c3d6.html https://www.cnblogs. ...
- 小白的Python之路 day4 生成器
一.列表生成式 看下面例子: 列表生成式的作用:主要是让代码更简洁(还有装X的效果) 二.生成器 通过列表生成式,我们可以直接创建一个列表.但是,受到内存限制,列表容量肯定是有限的.而且,创建一个包 ...
- Python下载一张图片与有道词典
1.下载一张图片代码1 import urllib.request response = urllib.request.urlopen('http://photocdn.sohu.com/201009 ...
- Find Unique pair in an array with pairs of numbers 在具有数字对的数组中查找唯一对
给定一个数组,其中每个元素出现两次,除了一对(两个元素).找到这个唯一对的元素. 输入:第一行输入包含一个表示测试用例数的整数T.然后T测试用例如下.每个测试用例由两行组成.每个测试用例的第一行包含整 ...
- bzoj 3670: [Noi2014]动物园
Description 近日,园长发现动物园中好吃懒做的动物越来越多了.例如企鹅,只会卖萌向游客要吃的.为了整治动物园的不良风气,让动物们凭自己的真才实学向游客要吃的,园长决定开设算法班,让动物们学习 ...
- shell 踩坑记
变量赋值时,等号两边不能有空格: 在判断表达式中,不论是 [ -n "$1" ] 还是 [ -f "$1" ] 都要在变量两侧加上双引号: 在使用与或非判断式 ...
- Effective Java 第三版——12. 始终重写 toString 方法
Tips <Effective Java, Third Edition>一书英文版已经出版,这本书的第二版想必很多人都读过,号称Java四大名著之一,不过第二版2009年出版,到现在已经将 ...
- Linux下磁盘监控及系统版本-CPU-内存等查看
1.磁盘IO监控工具 iotop 输入命令:iotop 主要查看程序使用的磁盘IO的信息 安装:yum -y install iotop 第一行:10:01:23 — 当前系统时间126 days ...
- oracle自动备份_expdp_Linux
[oracle@hbsjxtdb1 ~]$ crontab -e 0 4 * * * /backup/script/backupexpdp.sh [oracle@hbsjxtdb1 ~]$ cront ...
- ThreadLocal从源码到应用
最早接触到ThreadLocal是在阅读dianping的Cat-client,当时对它不是很理解,就搜索了一下,大概了解是一种解决线程安全问题的机制.现在再次阅读<实战java高并发程序设计& ...