UVa 143 - Orchard Trees
题目大意:果园里的树排列成矩阵,它们的x和y坐标均是1~99的整数。输入若干三角形,依次统计每一个三角形内部和边界上共有多少棵树。
三角形P0P1P2有向面积为A:2A = x0y1 + x2y0 + x1y2 - x2y1 - x0y2 - x1y0。如果三角形的三个顶点呈逆时针排列,那么有向面积为正,如果是顺时针排列,则有向面积为负。假设输入三角形为ABC,待判断点为O,则O在三角形ABC内部或边界上当且仅当SABC = SOAB + SOBC + SOAC。通过对有向面积取绝对值可以避免三个顶点是否是逆时针的判断,同时要注意计算x、y的最大值和最小值时要限制在[1, 99]的范围内。
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define EPS 1e-9 double area2(double x0, double y0, double x1, double y1, double x2, double y2)
{
return fabs(x0*y1 + x2*y0 + x1*y2 - x2*y1 - x0*y2 - x1*y0);
} int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
double x1, x2, x3, y1, y2, y3;
while (scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3) != EOF)
{
if ((x1 || x2 || x3 || y1 || y2 || y3) == ) break;
int x_min = ceil(min(x1, min(x2, x3)));
x_min = max(, x_min);
int x_max = max(x1, max(x2, x3));
x_max = min(, x_max);
int y_min = ceil(min(y1, min(y2, y3)));
y_min = max(, y_min);
int y_max = max(y1, max(y2, y3));
y_max = min(, y_max);
double S = area2(x1, y1, x2, y2, x3, y3);
int ans = ;
for (int x = x_min; x <= x_max; x++)
for (int y = y_min; y <= y_max; y++)
{
double S1 = area2(x1, y1, x2, y2, x, y);
double S2 = area2(x2, y2, x3, y3, x, y);
double S3 = area2(x3, y3, x1, y1, x, y);
if (fabs(S-S1-S2-S3) < EPS) ans++;
}
printf("%4d\n", ans);
}
return ;
}
在取最大值和最小值时,如果min向下取整,max用ceil向上取整,那么考察的范围将会扩大,按理说应该没什么影响,可是那样的话会WA,为什么呢?唉,难懂的浮点数啊...
UVa 143 - Orchard Trees的更多相关文章
- UVA - 143 Orchard Trees (点在三角形内)
题意: 给出三角形的三个点的坐标(浮点数), 问落在三角形内及三角形边上的整点有多少? 思路:所有点暴力判断(点的范围1-99,三角形可能是0-100,因为这个WA了一下orz) AC代码: ...
- hud 1633 Orchard Trees 点是否在三角形内模板 *
Orchard Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 【例题 6-7 UVA - 122 】Trees on the level
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 二叉树的话,直接用数组存就好了. 写个bfs记录一下答案. [代码] #include <bits/stdc++.h> ...
- UVa 10562 Undraw the Trees 看图写树
转载请注明: 仰望高端玩家的小清新 http://www.cnblogs.com/luruiyuan/ 题目大意: 题目传送门:UVa 10562Undraw the Trees 给定字符拼成的树,将 ...
- UVA题解三
UVA题解三 UVA 127 题目描述:\(52\)张扑克牌排成一列,如果一张牌的花色或者数字与左边第一列的最上面的牌相同,则将这张牌移到左边第一列的最上面,如果一张牌的花色或者数字与左边第三列的最上 ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- Uva 10007 / HDU 1131 - Count the Trees (卡特兰数)
Count the Trees Another common social inability is known as ACM (Abnormally Compulsive Meditation) ...
- UVA.122 Trees on the level(二叉树 BFS)
UVA.122 Trees on the level(二叉树 BFS) 题意分析 给出节点的关系,按照层序遍历一次输出节点的值,若树不完整,则输出not complete 代码总览 #include ...
- Trees on the level UVA - 122 复习二叉树建立过程,bfs,queue,strchr,sscanf的使用。
Trees are fundamental in many branches of computer science (Pun definitely intended). Current state- ...
随机推荐
- jquery 延迟执行实例介绍
代码如下: $(function(){ var $inputs = $('input[type=button]') .delay(500) .queue(function(){$(this).hide ...
- 客户调查(client)
客户调查(client) 题目描述 公司派你去和几位客户面谈,以了解他们对公司产品的意见.你逐个打电话与客户联系,得知他们一般都很忙,不过他们还是可以为你抽出一点时间.现在的问题是有些客户的时间有冲突 ...
- android脚步---不同activity之间参数传递
现在有两个activity,一个是mainactivity,一个是detectactivity 后者需要调用前者的一个参数,这里用到了intent getextras(); putextras(); ...
- Source
转载自:http://blog.csdn.net/u014084081/article/details/44617707 Guide iOS Developer Library 教程 Ray Wend ...
- 关于数据结构的10个面试题(c语言实现)
关于数据结构的10个面试题(c语言实现) 2010-04-21 22:17 5702人阅读 评论(0) 收藏 举报 数据结构面试c语言bttree 1. 输入一个链表的头结点,从尾到头 ...
- 微信小程序登陆流程
#1:session_key和openId是什么?session_key 官方说明为:session_key是微信服务器生成的针对用户数据进行加密签名的密钥session_key的用途(1)对wx.g ...
- IFields Interface 定义一个字段集合对象
Description The Fields object represents a collection of columns in a table. The term field is synon ...
- 用free -m查看的结果:
用free -m查看的结果: # free -m total used free shared buffers cached Mem: ...
- PAT (Advanced Level) 1022. Digital Library (30)
简单模拟题. 写的时候注意一些小优化,小心TLE. #include<iostream> #include<cstring> #include<cmath> #in ...
- Polipo
polipo代理服务器简介 HTTP代理polipo的配置与使用:http://wuwei5460.blog.51cto.com/2893867/1407369/