Think:
1知识点:判断一个点是否在三角形内/圆形内/正方形内
2题意:输入多个三角形和圆形和正方形,询问最终有多少个点在输入的三角形内或者圆形内或者正方形内

vjudge题目链接

以下为Accepted代码

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>using namespace std;struct point{/*记录点的信息*/double x;double y;
};struct v{/*记录边的信息*/point star;/*边的起点*/point en;/*边的终点*/
};struct triangle{/*记录三角形信息*/point A;/*三角形的顶点A*/point B;/*三角形的顶点B*/point C;/*三角形的顶点C*/
};
triangle tre[104];
int tr;struct square{int x;/*正方形左下角的横坐标*/int y;/*正方形左下角的纵坐标*/int l;/*正方形的边长*/
};
square squ[104];
int sq;struct circle{int x;/*圆心的横坐标*/int y;/*圆心的纵坐标*/int r;/*圆的半径*/
};
circle cir[104];
int ci;double crossProduct(v * v1, v * v2);/*向量叉积*/
bool inTrianle(triangle t, point P);/*判断点是否在三角形内*/
bool inSquare(square t, int x, int y);/*判断点是否在正方形内*/
bool inCircle(circle t, int x, int y);/*判断点是否在圆内*/int main(){int T, n, i, j, k, num;char st[14];scanf("%d", &T);while(T--){tr = sq = ci = 0;scanf("%d", &n);while(n--){scanf("%s", st);if(st[0] == 'C'){scanf("%d %d %d", &cir[ci].x, &cir[ci].y, &cir[ci].r);ci++;}else if(st[0] == 'S'){scanf("%d %d %d", &squ[sq].x, &squ[sq].y, &squ[sq].l);sq++;}else {scanf("%lf %lf %lf %lf %lf %lf", &tre[tr].A.x, &tre[tr].A.y, &tre[tr].B.x, &tre[tr].B.y, &tre[tr].C.x, &tre[tr].C.y);tr++;}}num = 0;for(i = -200; i <= 200; i++){for(j = -200; j <= 200; j++){bool flag = false;for(k = 0; k < ci; k++){if(inCircle(cir[k], i, j)){flag = true;break;}}if(!flag){for(k = 0; k < sq; k++){if(inSquare(squ[k], i, j)){flag = true;break;}}}if(!flag){point t;for(k = 0; k < tr; k++){t.x = (double)i, t.y = (double)j;if(inTrianle(tre[k], t)){flag = true;break;}}}if(flag)num++;}}printf("%d\n", num);}return 0;
}
double crossProduct(v * v1, v * v2){v vt1, vt2;double result = 0;vt1.star.x = 0;vt1.star.y = 0;vt1.en.x = v1->en.x - v1->star.x;vt1.en.y = v1->en.y - v1->star.y;vt2.star.x = 0;vt2.star.y = 0;vt2.en.x = v2->en.x - v2->star.x;vt2.en.y = v2->en.y - v2->star.y;result = vt1.en.x * vt2.en.y - vt2.en.x * vt1.en.y;return result;
}
bool inTrianle(triangle t, point p){v AB, AC, BC, PA, PB, PC;AB.star = t.A;AB.en = t.B;AC.star = t.A;AC.en = t.C;BC.star = t.B;BC.en = t.C;PA.star = p;PA.en = t.A;PB.star = p;PB.en = t.B;PC.star = p;PC.en = t.C;double Sabc = fabs(crossProduct(&AB, &AC));double Spab = fabs(crossProduct(&PA, &PB));double Spac = fabs(crossProduct(&PA, &PC));double Spbc = fabs(crossProduct(&PB, &PC));if(Sabc == Spab + Spac + Spbc)return true;elsereturn false;
}
bool inSquare(square t, int x, int y){if(x >= t.x && x <= t.x+t.l && y >= t.y && y <= t.y+t.l)return true;elsereturn false;
}
bool inCircle(circle t, int x, int y){int ans = (x-t.x)*(x-t.x) + (y-t.y)*(y-t.y);if(ans <= t.r*t.r)return true;elsereturn false;
}

【点的定位】Save the Students! UVALive - 5984相关推荐

  1. Java小案例(二) 用数组实现增删查改排序

    文章目录 案例一 案例二 案例三 案例四 案例五 案例一 Student.Java package curd;public class Student {private String stuid;pr ...

  2. Flask数据库模型之数据库模型关系反向映射(四)

    Flask数据库关系反向映射 db.relationship 当前字段用于一对多或者多对多反向映射: 第一个参数是 映射向的模型名称 Secondary 参数 指向多对多的关系表 backref 参数 ...

  3. Python实现的通讯录

    "为何表情,要让这世界安排?" 诶,我们也对python的一些基础语法有了一定能的了解了.并且在这基础上,学习了python中的文件操作,那么有了这些东西以后啊,我们能做什么呢?或 ...

  4. 【.net core】Excel导入导出之Npoi.Mapper

    引入Npoi.Mapper的nuget包 <PackageReference Include="Npoi.Mapper" Version="3.5.1" ...

  5. hdoj4648(Magic Pen 6)(前缀和)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4648 Magic Pen 6 Time Limit: 2000/1000 MS (Java/Other ...

  6. 15 -python之文件操作

    文章目录 python文件操作 普通文件的操作 1.open()返回一个文件对象 2.文件读操作--read() 3.文件写操作--write() **对文件进行操作之后都要将文件关闭** 4.更改文 ...

  7. ManytoMany字段增删改查Django

    Django下ManytoMany 增删改查 建立学生类老师类多对多关系,用ManytoManyField,迁移同步后自动生成中间表tb_Teacher_Student # 学生类 class Stu ...

  8. Database:数据库的关系模型

    数据库学习笔记:关系模型 Copyright: Jingmin Wei, Pattern Recognition and Intelligent System, School of Artificia ...

  9. Django中数据知识点归纳

    Django对象的增删改查 我们为了对django对象的增删改查进行总结,先在model.py文件中创建类便于举例 定义学生: class Students(models.Model):sname=m ...

最新文章

  1. SpringBoot整合Swagger测试api构建
  2. vue 过滤器的使用(解决forEach遇到的问题)
  3. MVC基于角色权限控制--用户管理
  4. coding note-源码搜索
  5. DCIM在数据中心现代化计划中的作用
  6. PHP的pcntl多进程
  7. php 获取每年的节假日,shell获取每年农历节日的日期
  8. Hadoop集群(一) Zookeeper搭建
  9. 获取系统分辨率_一文弄懂高分辨率高速快门CMOS成像传感器技术应用现状
  10. java web集成ldap_关于Java LDAP登录集成
  11. 《深入解析Windows操作系统》--第二章 系统结构
  12. 传感器贴片行业调研报告 - 市场现状分析与发展前景预测(2021-2027年)
  13. 比特率和波特率的区别
  14. win7我的计算机无法搜索,win7搜索功能无法正常使用的有效解决方法
  15. oracle 体系架构图
  16. 元宇宙终极目标是打造六界
  17. AddressBook iOS读取通讯录信息
  18. codeforces 1665A (GCD vs LCM)思维
  19. 23个 Web 开发中的侧边栏菜单练习实例
  20. 怎么用金蝶kis记账王修改会计期间

热门文章

  1. 清华大学教授张长水:基于小样本学习的计算机视觉应用
  2. openlayers 展示gif的2种方案
  3. asdasdasdaa
  4. antd design 引用样式不生效问题
  5. mysql数据库in函数查询是否走索引
  6. 恶意软件NOKKI和朝鲜“Group123”APT组织关联的最新证据
  7. 小虎电商浏览器:至尊宝拼多多一件代发应该如何操作
  8. 开源项目treasure_house
  9. 汽车的一些简写名词(后续会继续更新)
  10. 2022北京高考数学压轴题21题的一种解答