nyoj 67-三角形面积 (海伦公式, 叉积)
67-三角形面积
内存限制:64MB
时间限制:3000ms
特判: No
通过数:8
提交数:13
难度:2
题目描述:
输入描述:
每行是一组测试数据,有6个整数x1,y1,x2,y2,x3,y3分别表示三个点的横纵坐标。(坐标值都在0到10000之间)
输入0 0 0 0 0 0表示输入结束
测试数据不超过10000组
输出描述:
输出这三个点所代表的三角形的面积,结果精确到小数点后1位(即使是整数也要输出一位小数位)
样例输入:
0 0 1 1 1 3
0 1 1 0 0 0
0 0 0 0 0 0
样例输出:
1.0
0.5 分析:
方法一、海伦公式 s = sqrt(p*(p-a)*(p-b)*(p-c)), p = (a+b+c)/2;
方法二、叉积 s = fabs(BA(x)*CA(y) - BA(y)*CA(x)) / 2.0 方法一(海伦公式)(AC):
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <stack>
#include <map>
#include <queue>
#include <set> using namespace std; int main()
{
double a, b, c, d, e, f;
while(scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e, &f), a || b || c || d || e || f)
{
double line_a = sqrt((a-c)*(a-c) + (b-d)*(b-d));
double line_b = sqrt((a-e)*(a-e) + (b-f)*(b-f));
double line_c = sqrt((c-e)*(c-e) + (d-f)*(d-f));
double line_p = (line_a + line_b + line_c) / ;
printf("%.1lf\n", sqrt(line_p * (line_p - line_a)* (line_p - line_b)* (line_p - line_c))); // 海伦
}
return ;
}
方法二(叉积)(AC):
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <stack>
#include <map>
#include <queue>
#include <set> using namespace std;
struct node
{
double x, y;
}; double cross_product(node a, node b, node c)
{
return ((b.x-a.x)*(c.y-a.y) - (b.y-a.y)*(c.x-a.x));
} int main()
{
node a, b, c;
while(scanf("%lf%lf%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y, &c.x, &c.y), a.x || a.y || b.x || b.y || c.x || c.y)
{
printf("%.1lf\n", fabs(cross_product(a, b, c)) / 2.0);
}
return ;
}
nyoj 67-三角形面积 (海伦公式, 叉积)的更多相关文章
- nyoj 67 三角形面积【三角形面积公式】
三角形面积 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 给你三个点,表示一个三角形的三个顶点,现你的任务是求出该三角形的面积 输入 每行是一组测试数据,有6个 ...
- NYOJ 67 三角形面积(线代,数学)
三角形面积 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 给你三个点,表示一个三角形的三个顶点,现你的任务是求出该三角形的面积 输入 每行是一组测试数据,有6个 ...
- NYOJ 815 三角形【海伦公式】
/* 关键点:海伦公式 解题人:lingnichong 解题时间:2014-10-04 21:48:47 解题体会:海伦公式的使用 */ 三角形 时间限制:1000 ms | 内存限制:65535 ...
- hdu 4709:Herding(叉积求三角形面积+枚举)
Herding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- OpenJudge计算概论-计算三角形面积【海伦公式】
/*============================================== 计算三角形面积 总时间限制: 1000ms 内存限制: 65536kB 描述 平面上有一个三角形,它的 ...
- luogu 1355 神秘大三角 判断点和三角形的位置关系 面积法 叉积法
题目链接 题目描述 判断一个点与已知三角形的位置关系. 输入输出格式 输入格式: 前三行:每行一个坐标,表示该三角形的三个顶点 第四行:一个点的坐标,试判断该点与前三个点围成三角形的位置关系 (详见样 ...
- UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)
Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...
- 计算概论(A)/基础编程练习2(8题)/3:计算三角形面积
#include<stdio.h> #include<math.h> int main() { // 声明三角形的三个顶点坐标和面积 float x1, y1, x2, y2, ...
- POJ 2079 最大三角形面积(凸包)
Triangle Description Given n distinct points on a plane, your task is to find the triangle that have ...
- 【C语言】已知三角形三边长,求三角形面积
一. 数学基础: 已知三角形的三边,计算三角形面积,需要用到海伦公式: 即p=(a+b+c)/2 二. 算法: 输入三个边长,套用海伦公式计算面积,并输出. 可以先判断是否可以构成三角形,即任意两边之 ...
随机推荐
- HTML5 lufylegend引擎学习(一) -- 剪刀石头布小游戏
网址:http://www.lufylegend.com/ <!DOCTYPE html> <html> <head> <title>A Little ...
- 使用js json/xml互相转换
<html> <head> <title>json与xml互转</title> <script type="text/javascrip ...
- 13.多级代理下Nginx透传真实IP
1.基于代理(七层负载均衡)情况下 透传客户端的真实IP 环境: 10.0.0.5 proxy_node1 一级代理 10.0.0.6 proxy_node2 二级代理 10.0.0.7 proxy_ ...
- 20.Linux进程管理-企业案例
1.管理进程状态 当程序运行为进程后,如果希望停止进程,怎么办呢? 那么此时我们可以使用linux的kill命令对进程发送关闭信号.当然除了kill.还有killall,pkill 1.使用kill ...
- kaldi使用cvte模型进行语音识别
操作系统 : Unbutu18.04_x64 gcc版本 :7.4.0 该模型在thch30数据集上测试的错误率只有8.25%,效果还是不错的. 模型下载地址: http://www.kaldi-as ...
- Spring Boot构建的Web项目如何在服务端校验表单输入
本文首发于个人网站:Spring Boot构建的Web项目如何在服务端校验表单输入 这个例子用于演示在Spring Boot应用中如何验证Web 应用的输入,我们将会建立一个简单的Spring MVC ...
- 第一章、Python环境搭建
一.安装Python解释器 Windows下 Python开发环境搭建 1.官网下载: https://www.python.org/downloads/ 2.选择对应的版本 3.双击运行 4.选 ...
- webStrom快捷键快速创建React组件
1. rcc + tab键 - - 用ES6模块系统创建一个React组件类 2. rccp + tab键 - - 创建一个带有PropTypes和ES6模块系统的React组件类 3. rcfc + ...
- Openmp编程练习
火车卖票 // OpenMP2.cpp : 定义控制台应用程序的入口点. // #include "stdio.h" #include "omp.h" #inc ...
- Splash的使用
Splash Lua脚本http://localhost:8050 入口及返回值 function main(splash, args) splash:go("http://www.baid ...