链接: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实现文章或博客的自动摘要(附java版开源项目)

    python实现文章或博客的自动摘要(附java版开源项目) 写博客的时候,都习惯给文章加入一个简介.现在可以自动完成了!TF-IDF与余弦相似性的应用(三):自动摘要 - 阮一峰的网络日志http: ...

  2. SqlParameter

    List<SqlParameter> parameters = new List<SqlParameter>(); SqlParameter param; foreach (. ...

  3. Google Map: JavaScript API RefererNotAllowedMapError

    visite https://console.developers.google.com/apis/credentials and select the project you use. http:/ ...

  4. 用excel2010 制作复合图表

    用excel2010制作双轴柱线复合图表就是要用excel2010做一个这样的图表:

  5. sql server 快捷键

    书签:清除所有书签. CTRL-SHIFT-F2 书签:插入或删除书签(切换). CTRL+F2 书签:移动到下一个书签. F2 功能键 书签:移动到上一个书签. SHIFT+F2 取消查询. ALT ...

  6. Java JDBC 驱动 MySQL

    MySQL: 1>下载地址:http://www.mysql.com/products/connector/ 2> //jdbc:[数据库类型]://[ip地址]:[端口号]/[数据库名] ...

  7. miniUI子窗口调父窗口方法

    window.Owner.XXX 其中XXX是父窗口里的方法名

  8. [转]android使用shape stroke描边只保留底部

    在项目中遇到这种情况:由于一些原因,自己需要用LinearLayout的垂直布局做出ListView的那种效果,但是ListView是自带了分割线的,而且顶部底部都是没有分割线的,每个item中间都是 ...

  9. 关于List.ToArray()方法的效率测试

    之前一直认为因为List内部是数组,ToArray的实现只是将数组返回出去而已. 今天测了一下发现并不是那样 var a = new List<int>(); ; i < ; i++ ...

  10. JAVA基础知识之IO——IO流(Stream)的概念

    Java IO 流 Java将不同的设备或载体(键盘.文件.网络.管道等)的输入输出数据统称为"流"(Stream),即JAVA的IO都是基于流的. JAVA传统的所有流类型类都包 ...