poj2826An Easy Problem?!
繁琐细节题。
1、线段无交点时,ans=0;
2、如图 假设过p3.y的水平线与p1p2相交

因为雨是垂直下落的,左图的情况是无法收集到雨水的,而这种情况有一种简便的判定方式 cross(p1-p2,p3-p4)与cross((p1+(0,1))-p1,p1,p3)同号
对于右边的,阴影部分即为ans,求出水平交点tp,p1p2与p3p4的交点pp,ans = fabs(cross(tp-pp,p3-pp))/2;
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100000
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct point
{
double x,y;
point(double x=,double y=):x(x),y(y) {}
} p[];
typedef point pointt;
pointt operator -(point a,point b)
{
return pointt(a.x-b.x,a.y-b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
}
double cross(point a,point b)
{
return a.x*b.y-a.y*b.x;
}
bool cmp(point a,point b)
{
return a.y>b.y;
} bool intersection1(point p1, point p2, point p3, point p4, point& p) // 直线相交
{
double a1, b1, c1, a2, b2, c2, d;
a1 = p1.y - p2.y;
b1 = p2.x - p1.x;
c1 = p1.x*p2.y - p2.x*p1.y;
a2 = p3.y - p4.y;
b2 = p4.x - p3.x;
c2 = p3.x*p4.y - p4.x*p3.y;
d = a1*b2 - a2*b1;
if (!dcmp(d)) return false;
p.x = (-c1*b2 + c2*b1) / d;
p.y = (-a1*c2 + a2*c1) / d;
return true;
}
double solve(point p1,point p2,point p3,point p4,point pp,point tp)
{
double ans;
point p11 = point(p1.x,p1.y+);
if(dcmp(cross(p11-p1,p1-p3))==)
{
ans = ;
//cout<<",";
}
else
{
if(dcmp(cross(p11-p1,p1-p3))*dcmp(cross(p1-p2,p3-p4))<)
{
ans = fabs(cross(p3-pp,tp-pp))/;
//cout<<",";
}
else ans = ;
}
return ans;
}
int on_segment( point p1,point p2 ,point p )
{
double max=p1.x > p2.x ? p1.x : p2.x ;
double min =p1.x < p2.x ? p1.x : p2.x ;
double max1=p1.y > p2.y ? p1.y : p2.y ;
double min1=p1.y < p2.y ? p1.y : p2.y ;
if( p.x >=min && p.x <=max &&
p.y >=min1 && p.y <=max1 )
return ;
else
return ;
}
int main()
{
int t,i;
cin>>t;
while(t--)
{
for(i = ; i <= ; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
sort(p+,p+,cmp);
sort(p+,p+,cmp);
point pp;
if(intersection1(p[],p[],p[],p[],pp))
{
if(!on_segment(p[],p[],pp)||!on_segment(p[],p[],pp))
{
puts("0.00");
continue;
}
}
//cout<<pp.x<<" "<<pp.y<<endl;
double ans;
point p1 = point(p[].x-,p[].y),p2;
point p3 = point(p[].x-,p[].y);
if(intersection1(p[],p[],p[],p1,p2)&&on_segment(p[],p[],p2))
{ ans = solve(p[],p[],p[],p[],pp,p2);
}
else
{
intersection1(p[],p[],p[],p3,p2);
// cout<<p2.x<<" "<<p2.y<<endl;
ans = solve(p[],p[],p[],p[],pp,p2);
}
printf("%.2f\n",ans+eps); }
return ;
}
poj2826An Easy Problem?!的更多相关文章
- UVA-11991 Easy Problem from Rujia Liu?
Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for ...
- An easy problem
An easy problem Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- UVa 11991:Easy Problem from Rujia Liu?(STL练习,map+vector)
Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...
- POJ 2826 An Easy Problem?!
An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7837 Accepted: 1145 ...
- hdu 5475 An easy problem(暴力 || 线段树区间单点更新)
http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...
- 【暑假】[实用数据结构]UVa11991 Easy Problem from Rujia Liu?
UVa11991 Easy Problem from Rujia Liu? 思路: 构造数组data,使满足data[v][k]为第k个v的下标.因为不是每一个整数都会出现因此用到map,又因为每 ...
- HDU 5475 An easy problem 线段树
An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- UVA 11991 Easy Problem from Rujia Liu?(vector map)
Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...
- 数据结构(主席树):HDU 4729 An Easy Problem for Elfness
An Easy Problem for Elfness Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65535/65535 K (J ...
随机推荐
- Android Studio解决unspecified on project app resolves to an APK archive which is not supported
出现该问题unspecified on project app resolves to an APK archive which is not supported as a compilation d ...
- [xcode]instruments来检验你的app
原文网址:http://www.cocoachina.com/industry/20140114/7696.html 比较了好多关于instruments 还是发现老外写的比较牛逼.于是果 ...
- springMVC配置freemarker
这里呢,我首先来说明一下写该篇的目的. 我最近要用到freemarker因此研究了一下这个东西. 先来说说如何配置吧. 1.jar包.地址见下链接. http://pan.baidu.com/s/1j ...
- Session案例:简易的购物车
三个jsp和两个Servlet组成:在WebContent下边建立一个shoppingcart文件夹,将三个jsp文件放在里面: 1.建立一个step1.jsp文件,出现一个表格,是一个复选框,可以选 ...
- 2015-11-04 报表(c#部分)(Datatable 查询,弹出日期控件,输入是否整数)
using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq ...
- 刚体Collider包围测试
测试结果为会自动排出修正坐标(之前位于中心): 2016/2/29补充: 如果外面大的Cube相对小的Cube质量很高,会弹出且不出现移动(已锁住弹出物旋转,如果不锁会飞出去): 如果没有足够的空间排 ...
- Behavior Designer中的内置消息机制
最近在用Behavior Designer,其中需要用到消息机制,看了一下其中自带了这套东西 注册 Owner.RegisterEvent<string>("Message&qu ...
- 对torch的一点感想
torch是一个基于LuaJIT的科学计算框架,知乎上有个人回答说torch比较适合科研用途, torch与matlab的很多函数很相似
- Prompt isNaN 数组 function DOM window.open/close/location/history
1.prompt的利用 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Defa ...
- 【MySQL】MySQL的group_concat使用例子
> 参考的优秀文章 GROUP_CONCAT(expr) > 简单的例子 此函数的功能,是拼接group分组多行的数据为一行,并可以指定去重.排序.分隔符. 例子: select t.na ...