POJ Problem 3910 Build Your Home
来源:互联网 发布:88折话费 源码 编辑:程序博客网 时间:2024/06/05 08:39
给定多边形的各个顶点,求该多边形的面积。
选多边形的任意一个顶点作为原点,它与任意相邻的两个顶点可构成一个三角形,而三角形面积可由三个顶点构成的两个平面向量的外积求得。任意多边形的面积公式为:
import java.io.*;import java.lang.Math;import java.util.Scanner;class Point{public double x, y;Point(double a, double b){ x = a; y = b;}}public class beta { public static void main(String args[]) { Scanner in = new Scanner(System.in); while(in.hasNext()){ int n = in.nextInt(); if(n == 0) break; Point []p = new Point[n]; for(int i = 0; i < n; ++i){ double a = in.nextDouble(); double b = in.nextDouble(); p[i] = new Point(a, b); } double area = 0.0; for(int i = 0; i < n-1; ++i){ area += (p[i].x - p[0].x)*(p[i+1].y - p[0].y)-(p[i].y - p[0].y)*(p[i+1].x-p[0].x); } area = Math.abs(area)*0.5; int ans = (int)area; if(area - ans < 0.5) System.out.println(ans); else System.out.println(ans + 1); } }}
1 0
- POJ Problem 3910 Build Your Home
- POJ 3907 Build Your Home
- poj 3907 Build Your Home 多边形面积
- poj 3907 Build Your Home 多边形面积
- WOJ1402-Build Your Home
- poj 3907 Build Your Home (多边形面积)
- poj 3907 Build Your Home(任意多边形面积)
- POJ 3907 Build Your Home 已被翻译
- TOJ3124 Build Your Home--任意多边形面积
- POJ 3932 Groundhog Build Home(最小圆覆盖)
- Find Your Way Home
- A problem occurred starting process 'command '/home/jason/Android/Sdk/build-tools/23.0.3/aapt
- hdu_3932_Groundhog Build Home
- Build Your Own Website
- Build your customization dojo
- Build Your Own Images
- Configure Your Build
- hdu 3932 Groundhog Build Home
- Zabbix 3配置脚本报警(二)
- Pandas Series
- zynq_devicetree
- JSP知识点
- Spring SET注入
- POJ Problem 3910 Build Your Home
- 数字图像处理与机器视觉——Visual C++与Matlab实现书中代码勘误
- WEB前端 | JS基础——(8)DOM
- 好久不开tomcat启动报错
- Java线程
- java反射机制
- Java革新大提速 Chrome 54终结YouTube的Flash内嵌技术
- php表单各项功能汇总....不断更新.....
- Problem 29 Distinct powers (set)