链接: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. 关于ScrollView中嵌套listview焦点滑动问题 解决

    (第三种,第四种简单推荐使用) 在这里我要提出的是,listview能滚动的前提是:当listview本身的高度小于listview里的子view. 第一种方法 只需在MainActivity中 找到 ...

  2. Android中Listview实现分页加载效果OnScrollListener

    activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android& ...

  3. 一个基于和围绕Docker生态环境构建的早期项目列表

    https://blog.docker.com/2013/07/docker-projects-from-the-docker-community/

  4. Linux计划任务,自动删除n天前的旧文件【转】

    转自:http://blog.csdn.net/jehoshaphat/article/details/51244237 转载地址:http://yaksayoo.blog.51cto.com/510 ...

  5. mac下多个php版本快速切换的方法是怎么样

    一.使用brew安装php多版本方法# brew install php56# brew install php70二.安装切换工具# brew install php-version# source ...

  6. List与Set的contains方法效率问题

    今天看到网上一篇文章说:Set检索元素效率低下,删除和插入效率高:List查找元素效率高,插入删除元素效率低.于是想到List虽然用get(index)方法查询效率高,但是若用contains方法查询 ...

  7. java用freemarker导出数据到word(含多图片)

    一.制作word模版 新建word文档,按照需要设置好字体等各种格式:这里为了显得整齐使用了无边框的表格. 将word文档另存为xml文件(注意不是word xml文档,我吃了这家伙的大亏了) 然后用 ...

  8. Spring+Quartz实现定时执行任务的配置

    1.要想使用Quartz 必须要引入相关的包:以下是我在项目中gradle中的配置: compile 'org.quartz-scheduler:quartz:2.1.1' 2.Scheduler的配 ...

  9. 关于android中Bundle的使用

      1.Android using Bundle for sharing variables 注:android中使用Bundle来共享变量,下例中Activity1和Activity2通过bundl ...

  10. Human Gene Functions

    Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18053 Accepted: 1004 ...