area
来源:互联网 发布:海外淘宝网站 编辑:程序博客网 时间:2024/04/30 09:19
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
struct POINT
{
int x,y;
}point[110];
int n;
double getArea()
{
double sum = 0;
for (int i = 0; i < n; ++ i)
{
sum += (point[i].x * point[(i + 1) % n].y - point[i].y * point[(i + 1) % n].x );
}
return fabs(sum/2.0);
}
int Gcd(int a, int b)
{
if (0 == b)
{
return a;
}
else
return Gcd(b, a % b);
}
int getSegmentPoint(POINT p1, POINT p2)
{
int a = abs(p2.y - p1.y);
int b = abs(p2.x - p1.x);
if (a == 0 && b == 0)
{
return 0;
}
if (a == 0)
{
return b - 1;
}
if (b == 0)
{
return a - 1;
}
return Gcd(b, a) - 1;
}
int getPoint()
{
int ans = n;
for (int i = 0; i < n; ++ i)
{
ans += getSegmentPoint(point[i], point[(i + 1) % n]);
}
return ans;
}
int main()
{
int cas, j = 1;
int temp1=0,temp2=0,temp3=0,temp4=0,begin1=0,begin2 = 0;
while (scanf("%d",&n)!=EOF)
{
point[0].x = point[0].y = 0;
for (int i = 1; i <= n; ++ i)
{
scanf("%d %d", &point[i].x, &point[i].y);
}
for (int i = 1; i <= n; ++ i){
point[i].x=point[i].x-point[n].x;
point[i].y=point[i].y-point[n].y;
}
double Area = getArea();
int res;
int fans;
int PointNum = getPoint();
res = (int)Area - PointNum / 2 + 1;
fans = Area*2;
if(fans%2 ==1)
printf("%d.5\n",fans/2);
if(fans%2==0)
printf("%d\n",fans/2);
}
return 0;
}
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
struct POINT
{
int x,y;
}point[110];
int n;
double getArea()
{
double sum = 0;
for (int i = 0; i < n; ++ i)
{
sum += (point[i].x * point[(i + 1) % n].y - point[i].y * point[(i + 1) % n].x );
}
return fabs(sum/2.0);
}
int Gcd(int a, int b)
{
if (0 == b)
{
return a;
}
else
return Gcd(b, a % b);
}
int getSegmentPoint(POINT p1, POINT p2)
{
int a = abs(p2.y - p1.y);
int b = abs(p2.x - p1.x);
if (a == 0 && b == 0)
{
return 0;
}
if (a == 0)
{
return b - 1;
}
if (b == 0)
{
return a - 1;
}
return Gcd(b, a) - 1;
}
int getPoint()
{
int ans = n;
for (int i = 0; i < n; ++ i)
{
ans += getSegmentPoint(point[i], point[(i + 1) % n]);
}
return ans;
}
int main()
{
int cas, j = 1;
int temp1=0,temp2=0,temp3=0,temp4=0,begin1=0,begin2 = 0;
while (scanf("%d",&n)!=EOF)
{
point[0].x = point[0].y = 0;
for (int i = 1; i <= n; ++ i)
{
scanf("%d %d", &point[i].x, &point[i].y);
}
for (int i = 1; i <= n; ++ i){
point[i].x=point[i].x-point[n].x;
point[i].y=point[i].y-point[n].y;
}
double Area = getArea();
int res;
int fans;
int PointNum = getPoint();
res = (int)Area - PointNum / 2 + 1;
fans = Area*2;
if(fans%2 ==1)
printf("%d.5\n",fans/2);
if(fans%2==0)
printf("%d\n",fans/2);
}
return 0;
}
0 0
- Area
- Area
- Area
- area
- Area
- Area
- zoj1010 Area
- Controlling Area
- mrp area
- The area
- Arable Area
- ZOJ1010 Area
- Circular Area
- POJ1265 Area
- Area (P1654)
- poj1654 - Area
- HDACM217 area
- map area
- 比较两数组的大小
- IplImage应用解析
- OpenGL模板测试之镜像模型解析
- 归并排序
- 不一样的设计!20个国外优秀的电子商务网站
- area
- UNIX环境编程速记-第三章
- jsp+javabean 实现简单的计算器
- Makefile 的 遗漏分隔符错误信息
- jquery easyui datagrid 分页 详解
- 普通常用的linux指令
- CBCentralManager Class 的相关分析
- android实现图片圆角代码
- SQL练习题整理