POJ 1265 Area
有一种定理,叫毕克定理。。。。
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 4352 | Accepted: 1977 |
Description
Figure 1: Example area.
You are hired to write a program that calculates the area occupied by the new facility from the movements of a robot along its walls. You can assume that this area is a polygon with corners on a rectangular grid. However, your boss insists that you use a formula he is so proud to have found somewhere. The formula relates the number I of grid points inside the polygon, the number E of grid points on the edges, and the total area A of the polygon. Unfortunately, you have lost the sheet on which he had written down that simple formula for you, so your first task is to find the formula yourself.
Input
For each scenario, you are given the number m, 3 <= m < 100, of movements of the robot in the first line. The following m lines contain pairs 揹x dy�of integers, separated by a single blank, satisfying .-100 <= dx, dy <= 100 and (dx, dy) != (0, 0). Such a pair means that the robot moves on to a grid point dx units to the right and dy units upwards on the grid (with respect to the current position). You can assume that the curve along which the robot moves is closed and that it does not intersect or even touch itself except for the start and end points. The robot moves anti-clockwise around the building, so the area to be calculated lies to the left of the curve. It is known in advance that the whole polygon would fit into a square on the grid with a side length of 100 units.
Output
Sample Input
Sample Output
Scenario #1:
0 4 1.0
Scenario #2:
12 16 19.0
Source
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <cmath>
- using namespace std;
- const int maxn=;
- int gcd(int a,int b)
- {
- return b==?a:gcd(b,a%b);
- }
- struct point
- {
- double x,y;
- point() {}
- point(double a,double b):x(a),y(b){}
- };
- double det(point a,point b)
- {
- return a.x*b.y-a.y*b.x;
- }
- struct polyon
- {
- int n;
- point a[maxn];
- polyon() {}
- double GetArea()
- {
- double sum=;
- a[n]=a[];
- for(int i=;i<n;i++)
- {
- sum+=det(a[i+],a[i]);
- }
- return fabs(sum/.);
- }
- int Border_Int_Point_Num()
- {
- int num=;
- a[n]=a[];
- for(int i=;i<n;i++)
- {
- num+=gcd(abs(int(a[i+].x-a[i].x)),abs(int(a[i+].y-a[i].y)));
- }
- return num;
- }
- int Inside_Int_Point_Num(int x,double area)
- {
- return int(area)+-x/;
- }
- }PY;
- int main()
- {
- int t,cas=;
- scanf("%d",&t);
- while(t--)
- {
- scanf("%d",&PY.n);
- int X=,Y=;
- for(int i=;i<PY.n;i++)
- {
- int a,b;
- scanf("%d%d",&a,&b);
- X+=a; Y+=b;
- PY.a[i].x=X; PY.a[i].y=Y;
- }
- double area=PY.GetArea();
- int On=PY.Border_Int_Point_Num();
- int In=PY.Inside_Int_Point_Num(On,area);
- printf("Scenario #%d:\n",cas++);
- printf("%d %d %.1lf\n\n",In,On,area);
- }
- return ;
- }
POJ 1265 Area的更多相关文章
- poj 1265 Area 面积+多边形内点数
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5861 Accepted: 2612 Description ...
- poj 1265 Area (Pick定理+求面积)
链接:http://poj.org/problem?id=1265 Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
- POJ 1265 Area (Pick定理 & 多边形面积)
题目链接:POJ 1265 Problem Description Being well known for its highly innovative products, Merck would d ...
- poj 1265 Area( pick 定理 )
题目:http://poj.org/problem?id=1265 题意:已知机器人行走步数及每一步的坐标 变化量 ,求机器人所走路径围成的多边形的面积.多边形边上和内部的点的数量. 思路:1.以 ...
- poj 1265 Area【计算几何:叉积计算多边形面积+pick定理计算多边形内点数+计算多边形边上点数】
题目:http://poj.org/problem?id=1265 Sample Input 2 4 1 0 0 1 -1 0 0 -1 7 5 0 1 3 -2 2 -1 0 0 -3 -3 1 0 ...
- POJ 1265 Area POJ 2954 Triangle Pick定理
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5227 Accepted: 2342 Description ...
- poj 1265 Area(Pick定理)
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5666 Accepted: 2533 Description ...
- poj 1265 Area(pick定理)
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4373 Accepted: 1983 Description Bein ...
- 2018.07.04 POJ 1265 Area(计算几何)
Area Time Limit: 1000MS Memory Limit: 10000K Description Being well known for its highly innovative ...
随机推荐
- Oracle 查询今天、昨日、本周、本月和本季度的所有记录
Oracle 查询今日.昨日.本周.本月和本季度的所有记录 字段类型为date 今日 select * from 表名 where to_char(字段名,'dd')=to_char(sysdate, ...
- [iOS 视频流开发-获得视频帧处理]
调用视频流所使用框架:<Foundation/Foundation.h> 必须定义的参数: 1.AVCaptureDevice(捕获设备:前置.后置摄像头等) 2.AVCaptureInp ...
- JSP实现数据传递与保存
业务逻辑: 1.登陆login.jsp 2.判断登陆是否成功check.jsp 3.登陆成功页面newsDetail.jsp 4.登陆失败转发到login.jsp 代码如下: <%@ page ...
- 【Alpha版本】 第四天 11.10
一.站立式会议照片: 二.项目燃尽图: 三.项目进展: 成 员 昨天完成任务 今天完成任务 明天要做任务 问题困难 心得体会 胡泽善 填写招聘时用户填写各个日期到可以使用工具方便选择日期的修改 完成了 ...
- Linux tcpdump 命令详解
简介用简单的话来定义tcpdump,就是:dump the traffic on a network,根据使用者的定义对网络上的数据包进行截获的包分析工具. tcpdump可以将网络中传送的数据包的& ...
- python运维开发坎坷之路-01
前言 2014年9月,新疆乌鲁木齐,在51CTO学院看着alex老师的python教学视频,不得不说这是我第一次接触python这门高级语言,从最开始的一无所知到现在能够用python写脚本,再到未来 ...
- Vector & ArrayList 的主要区别
1) 同步性:Vector是线程安全的,也就是说是同步的 ,而ArrayList 是线程序不安全的,不是同步的 数2. 2)数据增长:当需要增长时,Vector默认增长为原来一倍 ,而ArrayLis ...
- dotnetbar入门
1.下载dotnetbar组件 2.工具箱引用 3.项目引用 4.开始工作 //此处Form完整的名称是System.Windows.Forms.Form,表示FrmMain窗体类是继承于System ...
- JAVA jdbc获取数据库连接
JDBC获取数据库连接的帮助类 import java.io.InputStream; import java.sql.Connection; import java.sql.DriverManage ...
- BZOJ4415: [Shoi2013]发牌
显然可以线段树或树状数组上二分. 然而直接写splay在bzoj上并不会T. 然而发这题的目的只是因为我又忘了return了啊啊啊啊(TдT) 内心十分崩溃.关键是在本地还能过. #include&l ...