Area
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 17456   Accepted: 4847

Description

You are going to compute the area of a special kind of polygon. One vertex of the polygon is the origin of the orthogonal coordinate system. From this vertex, you may go step by step to the following vertexes of the polygon until back to the initial vertex. For each step you may go North, West, South or East with step length of 1 unit, or go Northwest, Northeast, Southwest or Southeast with step length of square root of 2.

For example, this is a legal polygon to be computed and its area is 2.5:

Input

The
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

For each polygon, print its area on a single line.

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(多边形面积)的更多相关文章

  1. poj 1654 Area 多边形面积

    /* poj 1654 Area 多边形面积 题目意思很简单,但是1000000的point开不了 */ #include<stdio.h> #include<math.h> ...

  2. POJ 1654 Area 多边形面积 G++会WA

    #include<stdio.h> #include<algorithm> #include <cstring> using namespace std; type ...

  3. POJ 1654 Area 凸包面积

    水题直接码... /********************* Template ************************/ #include <set> #include < ...

  4. poj 1654 Area (多边形求面积)

    链接:http://poj.org/problem?id=1654 Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:  ...

  5. poj 1654 Area(计算几何--叉积求多边形面积)

    一个简单的用叉积求任意多边形面积的题,并不难,但我却错了很多次,double的数据应该是要转化为long long,我转成了int...这里为了节省内存尽量不开数组,直接计算,我MLE了一发...,最 ...

  6. 2018.07.04 POJ 1654 Area(简单计算几何)

    Area Time Limit: 1000MS Memory Limit: 10000K Description You are going to compute the area of a spec ...

  7. POJ 1654 Area

    题意:从原点出发,沿着8个方向走,每次走1个点格或者根号2个点格的距离,最终回到原点,求围住的多边形面积. 分析:直接记录所经过的点,然后计算多边形面积.注意,不用先保存所有的点,然后计算面积,边走变 ...

  8. POJ 3348 /// 凸包+多边形面积

    题目大意: 给定的n个点 能圈出的最大范围中 若每50平方米放一头牛 一共能放多少头 求凸包 答案就是 凸包的面积/50 向下取整 /// 求多边形面积// 凹多边形同样适用 因为点积求出的是有向面积 ...

  9. poj 1654 Area(求多边形面积 && 处理误差)

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16894   Accepted: 4698 Description ...

随机推荐

  1. error signing assembly unknown error

    用VS2010 编译 C#工程,出现 Cryptographic failure while signing assembly 'Assembly.dll' -- 'Unknown error (80 ...

  2. c++ primer复习(五):类

    一:基本内容 1 类 数据成员:用于存储与类对象相关联的状态 成员函数:对数据成员进行操作 类将接口与实现分离,接口指定了类支持的操作,操作的具体实现细节是类的设计者才需要了解 2 类成员 类成员可以 ...

  3. discuz xplus 模板 没解析的问题

    <?xxx?> 模板中用得是短标签,没加php, 在php.ini中,把 open_short_tag = On ; 打开即可!浪费一上午的时间

  4. 如何在Html的div+css中去除<li>标签前面小黑点,和ul、LI部分属性方法

    div是很多人做网站都会用到的,但在显示效果时前面总是会有一个小黑点,这个效果很多人不想要,但又不知到如何去除,然而我们可以用以下方法来清除. 1.在CSS中写入代码.找到相关性的CSS,在..li和 ...

  5. CentOS使用sudo提示用户不在sudoers文件中的解决方法

    1切换到root用户[linux@localhost ~]$ su root密码:[root@localhost ~]# 2查看/etc/sudoers文件权限,如果只读权限,修改为可写权限 [roo ...

  6. VMware Workstation 10.0 下载 – 正版序列号+简体中文官方原版

    1.https://download3.vmware.com/software/wkst/file/VMware-workstation-full-10.0.0-1295980.exe 2.https ...

  7. Vim粘贴代码时缩进混乱

    Vim粘贴代码时缩进混乱 via 背景 在终端Vim中粘贴代码时,发现插入的代码会有多余的缩进,而且会逐行累加.原因是终端把粘贴的文本存入键盘缓存(Keyboard Buffer)中,Vim则把这些内 ...

  8. C# 翻页设计:首页,上一页,下一页,末页 ,跳转

    int pageSize = 0; //每页显示行数 int nMax = 0; //总记录数 int pageCount = 0; //页数=总记录数/每页显示行数 int pageCurrent ...

  9. Redis总录

    设计 选择合适的数据对象来存储对象:String,List,Hash(Entity角色对象),Set,Zset(需要排序): 选择存储是全局的,还是局部的: 机制 批处理(pipeline) 事务(w ...

  10. NOIP 2011 提高组 计算系数

    有二项式定理 `\left( a+b\right) ^{n}=\sum _{r=0}^{n}\left( \begin{matrix} n\\ r\end{matrix} \right) a^{n-r ...