题意:

 给出三角形的三个点的坐标(浮点数),
    问落在三角形内及三角形边上的整点有多少?

思路:所有点暴力判断(点的范围1-99,三角形可能是0-100,因为这个WA了一下orz)

AC代码:

 #include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const double eps = 1e-;
const double pi = acos(-1.0);
const int maxp = ;
int sgn(double x)
{
if(fabs(x) < eps) return ;
else return x < ? - : ;
}
struct Point{
double x, y;
Point(){}
Point(double _x, double _y){
x = _x, y = _y;
}
void input(){
scanf("%lf%lf", &x, &y);
}
bool operator == (Point b) const{
return sgn(x - b.x) == && sgn(y - b.y) == ;
}
bool operator < (Point b)const{
return sgn(x - b.x) == ? sgn(y - b.y < ) : x < b.x;
}
Point operator - (const Point &b)const{
return Point(x - b.x, y - b.y);
}
//²æ»ý
double operator ^(const Point &b){
return x * b.y - y * b.x;
}
//µã»ý
double operator *(const Point &b){
return x * b.x + y * b.y;
}
double len(){
return hypot(x, y);
}
double len2(){
return x * x + y * y;
}
double distant(Point p){
return hypot(x - p.x, y - p.y);
}
Point operator + (const Point &b)const{
return Point (x + b.x, y + b.y);
}
Point operator * (const double &k)const{
return Point(x * k, y * k);
}
Point operator / (const double &k)const{
return Point(x / k, y / k);
}
};
struct Line{
Point s, e;
Line(){}
Line(Point _s, Point _e){s = _s, e = _e;}
bool operator == (Line v){
return (s == v.s) && (e == v.e);
}
bool pointonseg(Point p){
return sgn((p - s)^(e - s)) == && sgn((p - e)*(p - s)) <= ;
} };
struct polygon{
int n;
Point p[maxp];
Line l[maxp];
void add(Point q){
p[n ++] = q;
}
void input(int _n){
n = _n;
for(int i = ;i < n;i++) p[i].input();
}
void getline(){
for(int i = ;i < n;i++){
l[i] = Line(p[i], p[(i+) % n]);
}
}
int relationpoint(Point q){
for(int i = ;i < n;i++){
if(p[i] == q) return ;
}
getline();
for(int i = ;i < n;i++){
if(l[i].pointonseg(q)) return ;
}
int cnt = ;
for(int i = ;i < n;i++){
int j = (i + ) % n;
int k = sgn((q - p[j])^(p[i] - p[j]));
int u = sgn(p[i].y - q.y);
int v = sgn(p[j].y - q.y);
if(k > && u < && v >= ) cnt++;
if(k < && v < && u >= ) cnt--;
}
return cnt != ;
}
};
int main()
{
double x1, x2, x3, y1, y2, y3;
polygon a;
while(~scanf("%lf%lf%lf%lf%lf%lf",&x1, &y1, &x2, &y2, &x3, &y3) && (x1|| x2|| x3|| y1|| y2|| y3))
{
a.n = ;
a.add(Point(x1,y1));
a.add(Point(x2,y2));
a.add(Point(x3,y3));
int cnt = ;
for(double i = ;i <= ;i++)
for(double j = ;j <= ;j++)
if(a.relationpoint(Point(i,j))) cnt ++;
printf("%4d\n",cnt);
}
return ;
}

UVA - 143 Orchard Trees (点在三角形内)的更多相关文章

  1. UVa 143 - Orchard Trees

    题目大意:果园里的树排列成矩阵,它们的x和y坐标均是1~99的整数.输入若干三角形,依次统计每一个三角形内部和边界上共有多少棵树. 三角形P0P1P2有向面积为A:2A = x0y1 + x2y0 + ...

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

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

  3. 2D空间中判断一点是否在三角形内

    要注意如果是XY坐标轴的2D空间,要取差乘分量z而不是y. 实现原理是,将三角形ABC三个边(AB,BC,CA)分别与比较点判断差乘,如果这3个差乘结果表示的方向一致,说明就在三角形内. 效果: 代码 ...

  4. hrbustoj 1142:围困(计算几何基础题,判断点是否在三角形内)

    围困 Time Limit: 1000 MS     Memory Limit: 65536 K Total Submit: 360(138 users) Total Accepted: 157(12 ...

  5. 【Leetcode】判断平面中1个点是否落在三角形内

    参考资料: 题目: https://blog.csdn.net/dongtinghong/article/details/78657403 符号重载: https://blog.csdn.net/cd ...

  6. 【TOJ 3005】Triangle(判断点是否在三角形内+卡精度)

    描述 Given the coordinates of the vertices of a triangle,And a point. You just need to judge whether t ...

  7. UVA 11186 Circum Triangle (枚举三角形优化)(转)

    题意:圆上有n个点,求出这n个点组成的所有三角形的面积之和 题解: 当我们要求出S(i,j,k)时,我们需要假设k在j的左侧,k在i与j之间,k在i的右侧. 如果k在 j的左侧  那么 S(i,j,k ...

  8. hdu 4353 统计点在三角形内的个数

    Finding Mine Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  9. poj 2954 Triangle 三角形内的整点数

    poj 2954 Triangle 题意 给出一个三角形的三个点,问三角形内部有多少个整点. 解法 pick's law 一个多边形如果每个顶点都由整点构成,该多边形的面积为\(S\),该多边形边上的 ...

随机推荐

  1. C# Winform版批量压缩图片程序

    需求 上周,领导给我分配了一个需求:服务器上的图片文件非常大,每天要用掉两个G的大小的空间,要做一个自动压缩图片的工具处理这些大图片.领导的思路是这样的: 1)打开一个图片,看它的属性里面象素是多少, ...

  2. win10在bios上还原系统

    遇到两次,win10系统,自动更新后,c盘好像被格式化了,桌面啥都没了,那个气啊.记录下怎么恢复的. 参考https://www.kafan.cn/edu/50206642.html,中的方法1. 通 ...

  3. Windows 8.1 PLSQL_32连接到RHEL6.1 Oracle10gr2_64

    目录 目录 系统环境 连接Oracle Server 系统环境 操作系统 Windows 8.1 RHEL6.1 软件 Oracle10gr2 PL/SQL instantclient-basic-w ...

  4. 数据可视化----matplotlib.pylot

    一.输入具体数 plt.plot([3,1,4,5,2]) #自动生成y轴 plt.ylabel("Grade") #y轴的标签 plt.savefig('test1',dpi=6 ...

  5. 07、python的基础-->数据类型、集合、深浅copy

    一.数据类型 1.列表 lis = [11, 22, 33, 44, 55] for i in range(len(lis)): print(i) # i = 0 i = 1 i = 2 del li ...

  6. flask获取参数

    <!DOCTYPE html> body, html { width: 100%; height: 100%; } , ::after, ::before { -webkit-box-si ...

  7. 深海Django少年

    orm查询,如果遇到我之前的环境报错 就可去manage.py中拷贝前四行代码到tests文件中,然后增加两行代码: import django django.setup() 或者任意新建一个py文件 ...

  8. Shell内置命令let

  9. grep 正则2

    基本正则表达式所定义的元字符 元字符 作用 例子 例子说明 ^ 行首定位符 ^ty 匹配"t"开头,后面紧跟一个"y"的字符串 $ 行尾定位符 txt$ 匹配以 ...

  10. mysql莫名报"unknown column ... in 'on clause'"

    今天遇见个会诡异的问题 一个web程序本地调试的好好的,结果发布到服务器上程序就报错了,报"unknown column ... in 'on clause'",网上搜了下,说是m ...