poj 1654 Area(多边形面积)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 17456 | Accepted: 4847 |
Description
For example, this is a legal polygon to be computed and its area is 2.5:

Input
first line of input is an integer t (1 <= t <= 20), the number of
the test polygons. Each of the following lines contains a string
composed of digits 1-9 describing how the polygon is formed by walking
from the origin. Here 8, 2, 6 and 4 represent North, South, East and
West, while 9, 7, 3 and 1 denote Northeast, Northwest, Southeast and
Southwest respectively. Number 5 only appears at the end of the sequence
indicating the stop of walking. You may assume that the input polygon
is valid which means that the endpoint is always the start point and the
sides of the polygon are not cross to each other.Each line may contain
up to 1000000 digits.
Output
Sample Input
4
5
825
6725
6244865
Sample Output
0
0
0.5
2
Source
【思路】
多边形求面积。
叉积计算。
【代码】
#include<cstdio>
#include<cstring>
using namespace std; typedef long long LL;
const int dx[]={,,,,,,-,-,-};
const int dy[]={-,,,-,,,-,,}; LL ans;
char s[]; int main() {
int T;
scanf("%d",&T);
while(T--) {
ans=;
scanf("%s",s);
int nx=,ny=,x,y;
int l=strlen(s);
for(int i=;i<l;i++) { //为啥直接写strlen(s)会TLE =-=
x=nx+dx[s[i]-''];
y=ny+dy[s[i]-''];
ans += (x*ny-nx*y);
nx=x , ny=y;
}
if(ans<) ans=-ans;
printf("%lld",ans/);
if(ans&) printf(".5");
putchar('\n');
}
return ;
}
poj 1654 Area(多边形面积)的更多相关文章
- poj 1654 Area 多边形面积
/* poj 1654 Area 多边形面积 题目意思很简单,但是1000000的point开不了 */ #include<stdio.h> #include<math.h> ...
- POJ 1654 Area 多边形面积 G++会WA
#include<stdio.h> #include<algorithm> #include <cstring> using namespace std; type ...
- POJ 1654 Area 凸包面积
水题直接码... /********************* Template ************************/ #include <set> #include < ...
- poj 1654 Area (多边形求面积)
链接:http://poj.org/problem?id=1654 Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
- poj 1654 Area(计算几何--叉积求多边形面积)
一个简单的用叉积求任意多边形面积的题,并不难,但我却错了很多次,double的数据应该是要转化为long long,我转成了int...这里为了节省内存尽量不开数组,直接计算,我MLE了一发...,最 ...
- 2018.07.04 POJ 1654 Area(简单计算几何)
Area Time Limit: 1000MS Memory Limit: 10000K Description You are going to compute the area of a spec ...
- POJ 1654 Area
题意:从原点出发,沿着8个方向走,每次走1个点格或者根号2个点格的距离,最终回到原点,求围住的多边形面积. 分析:直接记录所经过的点,然后计算多边形面积.注意,不用先保存所有的点,然后计算面积,边走变 ...
- POJ 3348 /// 凸包+多边形面积
题目大意: 给定的n个点 能圈出的最大范围中 若每50平方米放一头牛 一共能放多少头 求凸包 答案就是 凸包的面积/50 向下取整 /// 求多边形面积// 凹多边形同样适用 因为点积求出的是有向面积 ...
- poj 1654 Area(求多边形面积 && 处理误差)
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16894 Accepted: 4698 Description ...
随机推荐
- PAT_1046 划拳
啦啦啦.今天晚上火车回学校了.= =还是挺舍不得家里的. 题目描述: 划拳是古老中国酒文化的一个有趣的组成部分.酒桌上两人划拳的方法为:每人口中喊出一个数字,同时用手比划出一个数字.如果谁比划出的数字 ...
- PHPUML 生成UML
Selecting the UML/XMI version To select which version of the UML/XMI standards you want your XMI to ...
- 曾经的10道JAVA面试题
1.HashMap和Hashtable的区别. 都属于Map接口的类,实现了将惟一键映射到特定的值上.HashMap 类没有分类或者排序.它允许一个null 键和多个null 值.Hashtable ...
- 对BFC的理解
转载http://www.cnblogs.com/lhb25/p/inside-block-formatting-ontext.html 在解释 BFC 是什么之前,需要先介绍 Box.Formatt ...
- lamp环境-编译安装
http://my.oschina.net/JerryBaby/blog/292731 http://blog.chinaunix.net/uid-20639775-id-154442.html ht ...
- gentoo下的wpa_supplicant无线网配置
在linux使用wpa_supplicant获得无线网的最痛苦的是莫过于去配置wpa_supplicant.conf文件了(当然对于linux老手这不算什么), 但是可以用一种简便的方法直接输入命令行 ...
- php练习3——猜拳游戏,评委打分问题
用户与计算机猜拳 程序caiQuan.html和caiQuan.php: 结果: 评委打分问题,去掉一个最低分和最高分,求平均分,并找出最低分和最高分对应第几个评委, 再找出最佳评委(打分最接近 ...
- 此文件时入口文件index.php
此文件时入口文件index.php <?php //定义一下ThinkPHP框架存放的路径 define('THINK_PATH','./ThinkPHP/'); //定义当前的项目的名称,此处 ...
- Omnithreadlibary学习(2)-IOmniTask异步执行
1.使用 procedure Parallel.Async(task: TProc; taskConfig: IOmniTaskConfig); 匿名委托访问网站 program main; {$AP ...
- centos 6.3 64位安装php5.5及配置tengine
PHP 用到的工具包: yum install gd-devel libjpeg-devel libpng-devel freetype-devel libxml2-devel curl-devel ...