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- ...
 
随机推荐
- HDU 1890 Robotic Sort | Splay
			
Robotic Sort Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) [Pr ...
 - 自定义solr的search UI
			
solr使用apache的velocity来定义UI,在solr的search ui的基础上更改即可,主要改\example\solr\collection1\conf\velocity里的文件. 详 ...
 - AngularJs: Reload page
			
<a ng-click="reloadRoute()" class="navbar-brand" title="home" data- ...
 - 设置span的宽度
			
设置span的宽度 在默认的情况下,利用css样式对span进行宽度设定是无效,但有时为了某种排版的要求,需要对span进行宽度设定,那么如何在html中利用css样式设定span的宽度? 思路:这看 ...
 - drawRect & layoutSubviews  调用时间
			
首先两个方法都是异步执行.layoutSubviews方便数据计算,drawRect方便视图重绘. layoutSubviews在以下情况下会被调用: 1.init初始化不会触发layoutSub ...
 - mac地址静态捆绑,防止arp欺骗
			
arp -s 192.168.1.101 00-21-CC-D3-D5-FF 缺点,每次关机就还原,所以一般创建批处理文件,开机启动. ping 192.168.1.100 -l 65500 多台肉鸡 ...
 - msf常用命令
			
msf > search -r great -t exploits search命令查找rank为great的exploit msf > setg RHOST 192.168.1.102 ...
 - 制作windows镜像
			
下载包含windows驱动的iso: http://222.186.58.77/virtio-win-0.1-30.iso?fid=kF46uzxlPMrgvLDErP0ohhZYwAUASLoCAA ...
 - composer 的快速安装
			
Packagist 镜像 请各位使用本镜像的同学注意: 本镜像已经依照 composer 官方的数据源安全策略完全升级并支持 https 协议!请各位同学 按照下面所示的两个方法将 http://pa ...
 - SQL Server 事务及回滚事务的几种方法
			
第一种: declare @iErrorCount int set@iErrorCount=0 begintran Tran1 insertinto t1(Id, c1) values( ...