题目大意:果园里的树排列成矩阵,它们的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的更多相关文章

  1. UVA - 143 Orchard Trees (点在三角形内)

    题意: 给出三角形的三个点的坐标(浮点数),     问落在三角形内及三角形边上的整点有多少? 思路:所有点暴力判断(点的范围1-99,三角形可能是0-100,因为这个WA了一下orz) AC代码: ...

  2. hud 1633 Orchard Trees 点是否在三角形内模板 *

    Orchard Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  3. 【例题 6-7 UVA - 122 】Trees on the level

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 二叉树的话,直接用数组存就好了. 写个bfs记录一下答案. [代码] #include <bits/stdc++.h> ...

  4. UVa 10562 Undraw the Trees 看图写树

    转载请注明: 仰望高端玩家的小清新 http://www.cnblogs.com/luruiyuan/ 题目大意: 题目传送门:UVa 10562Undraw the Trees 给定字符拼成的树,将 ...

  5. UVA题解三

    UVA题解三 UVA 127 题目描述:\(52\)张扑克牌排成一列,如果一张牌的花色或者数字与左边第一列的最上面的牌相同,则将这张牌移到左边第一列的最上面,如果一张牌的花色或者数字与左边第三列的最上 ...

  6. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  7. Uva 10007 / HDU 1131 - Count the Trees (卡特兰数)

     Count the Trees  Another common social inability is known as ACM (Abnormally Compulsive Meditation) ...

  8. UVA.122 Trees on the level(二叉树 BFS)

    UVA.122 Trees on the level(二叉树 BFS) 题意分析 给出节点的关系,按照层序遍历一次输出节点的值,若树不完整,则输出not complete 代码总览 #include ...

  9. Trees on the level UVA - 122 复习二叉树建立过程,bfs,queue,strchr,sscanf的使用。

    Trees are fundamental in many branches of computer science (Pun definitely intended). Current state- ...

随机推荐

  1. tomcat配置文件server.xml参数说明

    元素名 属性 解释 server port 指定一个端口,这个端口负责监听关闭tomcat 的请求 shutdown 指定向端口发送的命令字符串 service name 指定service 的名字 ...

  2. tcp 的6个控制位

    原文:http://blog.chinaunix.net/uid-26413668-id-3376762.html TCP(Transmission Control Protocol) 传输控制协议 ...

  3. 我也谈javascript闭包的原理理解

    参考原文:http://www.oschina.net/question/28_41112 前言:还是一篇入门文章.Javascript中有几个非常重要的语言特性——对象.原型继承.闭包.其中闭包 对 ...

  4. Qt5:窗口居中显示

    QDesktopWidget* desktop = QApplication::desktop(); // =qApp->desktop();也可以move((desktop->width ...

  5. 树列复选框Extjs

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  6. 用apache配置多个tomcat webapp

    The Apache HTTP Server Project is an effort to develop and maintain an open-source HTTP server for m ...

  7. Python异常处理体系

    1.Python内建异常体系结构 The class hierarchy for built-in exceptions is: BaseException  +-- SystemExit  +-- ...

  8. PAT (Advanced Level) 1029. Median (25)

    scanf读入居然会超时...用了一下输入挂才AC... #include<cstdio> #include<cstring> #include<cmath> #i ...

  9. [转] Eclipse中已安装的插件如何卸载

    转自 : http://blog.csdn.net/macong01/article/details/7631105 最近在Eclipse中安装了一个插件,导致Eclipse使用的时候有些问题,就找了 ...

  10. js 如何动态添加数组_百度知道

    1.数组的创建var arrayObj = new Array(); //创建一个数组var arrayObj = new Array([size]); //创建一个数组并指定长度,注意不是上限,是长 ...