poj 3907 Build Your Home 多边形面积

题意:

给一个多边形,求它的面积。

分析:

算一遍叉积即可。

代码:

//poj 3907
//sep9
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	float x0,y0,x1,y1;
	short n;
	while(scanf("%hd",&n)==1&&n){
		float sum=0;
		scanf("%f%f",&x0,&y0);
		float xx=x0,yy=y0;
		n--;
		while(n--){
			scanf("%f%f",&x1,&y1);
			sum+=x0*y1-x1*y0;
			x0=x1;
			y0=y1;
		}
		x1=xx;
		y1=yy;
		sum+=x0*y1-x1*y0;
		printf("%.0f\n",fabs(sum)/2+1e-6);
	}
	return 0;
} 
时间: 2024-07-29 17:08:44

poj 3907 Build Your Home 多边形面积的相关文章

poj 1654 Area(求多边形面积)

题意:从原点出发向八个方向走,所给数字串每个数字代表一个方向,终点与原点连线,求所得多边形面积: 思路:(性质)共起点的两向量叉积的一半为两向量围成三角形的面积.以此计算每条边首尾两个向量的叉积,求和,除二: #include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const dou

POJ 3907 Build Your Home | 计算多边形面积

给个多边形 计算面积 输出要四舍五入 直接用向量叉乘就好 四舍五入可以+0.5向下取整 #include<cstdio> #include<algorithm> #include<cstring> #define N 10005 #define eps 1e-8 using namespace std; struct point { double x,y; inline double operator *(const point &rhs) const { re

POJ 1265-Area(计算几何+皮克定理+多边形面积公式)

题目地址:POJ 1265 题意:给定一个格点多边形,求出内部点数in,边上点数on,和面积S. 思路:运用的定理很多. 1.皮克定理:S=in+on/2-1,即in=(2*S+2-on)/2. 2.多边形的面积公式:按顺序求相邻两个点与原点组成的向量的叉积之和. 3.求边上的格点数:以格子点为顶点的线段,覆盖的点的个数为GCD(dx,dy),其中,dxdy分别为线段横向占的点数和纵向占的点数.如果dx或dy为0,则覆盖的点数为dy或dx. #include <stdio.h> #includ

poj 3348 Cows 凸包 求多边形面积 计算几何 难度:0 Source:CCC207

Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7038   Accepted: 3242 Description Your friend to the south is interested in building fences and turning plowshares into swords. In order to help with his overseas adventure, they are f

POJ 3907 Build Your Home

传送门的连接地址 题目大意:给你一个数n ,然后给出n个坐标值(二维),让你求面积: 解题思路:求叉积,注意最后取绝对值,而且还要除以2啊... 上代码: #include <iostream> #include <cstdio> #include <cmath> using namespace std; const int maxn=1e4+5; struct Point { double x; double y; }data[maxn]; double chaji(

Area - POJ 1654(求多边形面积)

题目大意:从原点开始,1-4分别代表,向右下走,向右走,向右上走,向下走,5代表回到原点,6-9代表,向上走,向左下走,向左走,向左上走.求出最后的多边形面积. 分析:这个多边形面积很明显是不规则的,可以使用向量积直接求出来面积即可. 代码如下: ------------------------------------------------------------------------------------------------------------------------------

多边形面积模板

HDU 2036 改革春风吹满地 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 20033    Accepted Submission(s): 10256 Problem Description “ 改革春风吹满地, 不会AC没关系; 实在不行回老家, 还有一亩三分地. 谢谢!(乐队奏乐)”话说部分学生心态极好,每天就知道游戏,这次

poj 1279 求半平面交的 面积

poj 1279    求半平面交的 面积 题目来源: http://poj.org/problem?id=1279 分析: 求半平面交的 面积 代码如下: const double EPS = 1e-8; const int Max_N = 1505; struct Point{ double x,y; Point(){} Point(double x, double y):x(x),y(y){} Point operator - (Point p){ return Point(x- p.x

【POJ 1408】 Fishnet (叉积求面积)

[POJ 1408] Fishnet (叉积求面积) 一个1*1㎡的池塘 有2*n条线代表渔网 问这些网中围出来的最大面积 一个有效面积是相邻两行和相邻两列中间夹的四边形 Input为n 后面跟着四行 每行n个浮点数 每一行分别代表a,b,c,d 如图 并且保证a(i) > a(i-1) b(i) > b(i-1) c(i) > c(i-1) d(i) > d(i-1) n(n <= 30)*2+4(四个岸)条边 枚举点数就行 相邻的四个四个点枚举 找出围出的最大面积 找点用