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 ...
随机推荐
- boost::assign(标准容器填充库)
boost::assign通过对"+="和","的重载非常方便的填充标准容器(std::vector,std::set,std::list,std::map), ...
- Zip4J最简单用法
package com.chentao.MicroMessage.bussiness; import java.io.File; import java.util.ArrayList; import ...
- C++ 头文件系列(set)
简介 头文件包含set.multiset两个类模版,这里要描述的概念与map非常相似,甚至连成员函数都几乎一样,所以这篇随笔会很短. set set如果翻译成中文应该是集合的意思,这里更确切的说是唯一 ...
- Git 企业开发者教程
为什么要写这样一个面向企业开发者的Git教程?这个问题也困扰我自己很久.其实我使用git的时间也不短了,但是就和正在阅读本文的每一位一样,常用的基本就是那么几个(git clone, git pu ...
- 解决linux重启后无法开启nginx问题“var/run/nginx/nginx.pid" no such file or directory问题
起因:每次重启虚拟机后,var/run/nginx/目录都会被删除,所以无法在这个目录创建nginx.pid文件, 可以自己创建var/run/nginx/目录,然后可以运行,但治标不治本,下次虚拟机 ...
- Servlet与Jsp的结合使用实现信息管理系统一
PS:1:先介绍一下什么是Servlet? Servlet(Server Applet)是Java Servlet的简称,称为小服务程序或服务连接器,用Java编写的服务器端程序,主要功能在于交互式地 ...
- js必须掌握的基础
好多人想要学习前端……自学或者培训那么我们在学习过程中到底需要掌握那些基础知识呢!下面分类了JS中必备的知识也是必须要了解学会的!看一看你是否已经将JS的基础知识都了如指掌了呢? 事件: onmous ...
- C#-判断Shift,Alt,Ctrl是否被按下,确定所按下的组合键
在创建接受用户击键的应用程序时,您还可能希望监视 SHIFT.ALT 和 CTRL 键等组合键.当一个组合键与其他键同时按下,或在单击鼠标的同时按下时,您的应用程序能够做出适当响应:字母 S 可能仅导 ...
- 80 行代码爬取豆瓣 Top250 电影信息并导出到 CSV 及数据库
一.下载页面并处理 二.提取数据 观察该网站 html 结构 可知该页面下所有电影包含在 ol 标签下.每个 li 标签包含单个电影的内容. 使用 XPath 语句获取该 ol 标签 在 ol 标签中 ...
- TPYBoard实例之利用WHID为隔离主机建立隐秘通道
本文作者:xiaowuyi,来自FreeBuf.COM(MicroPythonQQ交流群:157816561,公众号:MicroPython玩家汇) 0引言 从2014年BADUSB出现以后,USB- ...