题目大意:果园里的树排列成矩阵,它们的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. Photoshop学习之路

    网易云课堂中有的提升课程:http://study.163.com/course/courseMain.htm?courseId=765016&6925ecaa9614a750=Individ ...

  2. Struts2 程序步骤

    1. 新建一个web project, 手动导入包: D:\Java\jar\struts-2.3.24.1\apps\struts2-blank\WEB-INF\lib copy到 WEB-INF/ ...

  3. 使用命令将logcat中的内容输出到文本文件中

    网上搜集的方法,自己只是试了一下第一种,很好用,如果是/mylogcat.txt 直接保存在了d盘,我猜是直接保存在了sdk所在的盘的根目录下,希望对大家有帮助 使用如下命令可以将logcat中的内容 ...

  4. Puzzles

    Puzzles Barney lives in country USC (United States of Charzeh). USC has n cities numbered from 1 thr ...

  5. mac地址静态捆绑,防止arp欺骗

    arp -s 192.168.1.101 00-21-CC-D3-D5-FF 缺点,每次关机就还原,所以一般创建批处理文件,开机启动. ping 192.168.1.100 -l 65500 多台肉鸡 ...

  6. Android里merge和include标签的使用

    1.使用<include /> 标签来重用layout代码 如果在一个项目中需要用到相同的布局设计,可以通过<include /> 标签来重用layout代码,该标签在andr ...

  7. ural1028 Stars

    Stars Time limit: 0.25 secondMemory limit: 64 MB Astronomers often examine star maps where stars are ...

  8. Linux下VNC配置多个桌面和修改密码 不会当系统重启vnc失效

    1:vncserver 2:iptables -I INPUT -p tcp --dport 5901 -j ACCEPT   客户端方式 3:iptables -I INPUT -p tcp --d ...

  9. git 与 github基本使用

    这里只对git 与 github的基本使用介绍,对于简单的步骤不做详细的说明,可以在网上搜索 一.git与github的安装与链接 1.git 安装:百度搜索"git",下载安装即 ...

  10. JQuery的插件开发——重点

    1.给JQuery全局对象扩展一个函数方法 $.log=function(){ /* 给全局对象$扩展一个函数*/ } $.log;//调用方法 2.给JQuery普通对象扩展一个函数方法 3.使用第 ...