链接:http://poj.org/problem?id=1654

Area
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 14952   Accepted: 4189

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

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

又看了题解才A掉,记得自己曾对别人说WA不要马上看题解,一道题做两三天很正常,自己却MLE马上看题解

自己定的规则自己都不遵守

 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <math.h> #define MAXX 1000002
#define eps 1e-6
typedef struct
{
double x;
double y;
} point; double crossProduct(point a,point b,point c)
{
return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
} bool dy(double x,double y)
{
return x>y+eps;
}
bool xy(double x,double y)
{
return x<y-eps;
}
bool dd(double x,double y)
{
return fabs(x-y)<eps;
} int main()
{
int n,m,i,j,x,y;
scanf("%d",&n);
char str[MAXX];
int move[][]= {{,},{-,-},{,-},{,-},{-,},{,},{,},{-,},{,},{,}};
for(i=; i<n; i++)
{
scanf("%s",str);
int len=strlen(str);
int x1=,y1=,x2,y2;
long long ans=;
for(j=; j<len-; j++)
{
x2=x1+move[str[j]-''][];
y2=y1+move[str[j]-''][];
ans+=((x1*y2)-(x2*y1));
x1=x2;
y1=y2;
}
ans = ans > ? ans : (-)*ans;
if(ans == )
printf("0\n");
else if(ans % == )
printf("%lld\n",ans/);
else if(ans % != )
printf("%lld.5\n",ans/);
}
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 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17937   Accepted: 4957 Description ...

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

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

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

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

  6. Area---poj1265(皮克定理+多边形求面积)

    题目链接:http://poj.org/problem?id=1265 题意是:有一个机器人在矩形网格中行走,起始点是(0,0),每次移动(dx,dy)的偏移量,已知,机器人走的图形是一个多边形,求这 ...

  7. POJ 3348 Cows 凸包 求面积

    LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileNa ...

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

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

  9. POJ - 1654 利用叉积求三角形面积 去 间接求多边形面积

    题意:在一个平面直角坐标系,一个点总是从原点出发,但是每次移动只能移动8个方向的中的一个并且每次移动距离只有1和√2这两种情况,最后一定会回到原点(以字母5结束),请你计算这个点所画出图形的面积 题解 ...

随机推荐

  1. 【python cookbook】【字符串与文本】15.给字符串中的变量名做插值处理

    问题:想创建一个字符串,其中嵌入的变量名称会以变量的字符串值形式替换掉 解决方法:str.format().str.format_map() >>> s = '{name} has ...

  2. STM32模拟I2C

    之前为了测试, 拿最小板做了一个I2C的主发跟主读, 一开始当然是尝试用硬件I2C, 结果弄了很久, 时间紧迫, 只好用了模拟, 结果发现, 哎, 真特么挺好用的, 现在1片儿顶过去5片儿. 硬件I2 ...

  3. linux下的module_param()解释【转】

    转自:http://blog.csdn.net/wavemcu/article/details/7762133 版权声明:本文为博主原创文章,未经博主允许不得转载. ***************** ...

  4. PBOC APDU命令解析【转】

    转自:http://blog.csdn.net/zuokong/article/details/49335257 版权声明:本文为博主原创文章,未经博主允许不得转载. 应用层发出的命令报文和卡片回送到 ...

  5. umask:遮罩码

    查看umask:umask 创建文件:-umask 文件默认不能具有执行权限 创建目录:-umask 设置umask:umask 0022 生效访范围:当前shell

  6. Keepalived原理及配置应用总结

    Keepalived——保持存活,在网络里的含义就是保持在线.Keepalived提供高可用和热备的功能,用来防止单点故障的发生. 1.VRRP协议基本原理介绍 Keepalived实现的基础是VRR ...

  7. php curl向远程服务器上传文件

    <?php /** * test.php: */ header('content-type:text/html;charset=utf8'); $ch = curl_init(); //加@符号 ...

  8. Oracle存储过程返回游标实例详解

    复制代码 代码如下:CREATE OR REPLACE PROCEDURE PROCSENDEMAIL(P_TXT VARCHAR2, P_SUB VARCHAR2, P_SENDOR VARCHAR ...

  9. ASP.NET数据验证控件的常用的属性

    一.非空验证     RequiredFieldValidator ControlToValidate 所验证的控件ID Text 出错时的提示的文本 ErrorMessage 提交给Validati ...

  10. CSS3前缀自动补全方案和插件

    第一种方法:prefix free,js插件,大小2kb,直接导入,无需任何浏览器兼容前缀 <script src="prefixfree.min.js"></s ...