Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 18499   Accepted: 5094

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

 
 
最终会回到原点,所以只需要模拟每一步行走,用叉积计算当前点、上一个点、原点构成的三角形面积,累计求和即可。
 
注意:1、需要long long
   2、单串长度可能小于3,需要特判输出0(加上这个就对了,诡异。大概是会出现步数不够,走不回原点的情况?)
 
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int mx[]={,,,,,,,-,-,-},
my[]={,-,,,-,,,-,,};
long long s;
int x,y;
long long area(int x1,int y1,int x2,int y2){//叉积求面积
return x1*y2-x2*y1; }
int main(){
int T;
scanf("%d\n",&T);
while(T--){
char str[];
scanf("%s",str);
s=;
x=;y=;
int len=strlen(str);
//
if(len<){
printf("0\n");
continue;
}
//
for(int i=;i<len;i++){
int num=str[i]-'';
int nowx=x+mx[num];
int nowy=y+my[num];
s+=area(x,y,nowx,nowy);
x=nowx;
y=nowy;
}
if(s<)s=-s;
if(s&){
printf("%lld.5\n",s/);
}
else printf("%lld\n",s/);
}
return ;
}

POJ1065 Area的更多相关文章

  1. [转]NopCommerce How to add a menu item into the administration area from a plugin

    本文转自:http://docs.nopcommerce.com/display/nc/How+to+code+my+own+shipping+rate+computation+method Go t ...

  2. ASP.NET MVC系列:Area

    1. Area简介 ASP.NET MVC Area机制构建项目,可以将相对独立的功能模块切割划分,降低项目的耦合度. 2. Area设置Routing 新建Admin Area后,自动创建Admin ...

  3. Web API项目中使用Area对业务进行分类管理

    在之前开发的很多Web API项目中,为了方便以及快速开发,往往把整个Web API的控制器放在基目录的Controllers目录中,但随着业务越来越复杂,这样Controllers目录中的文件就增加 ...

  4. MVC View中获取action、controller、area名称

    获取控制器名称: ViewContext.RouteData.Values["controller"].ToString(); 获取Action名称: ViewContext.Ro ...

  5. [LeetCode] Rectangle Area 矩形面积

    Find the total area covered by two rectilinear rectangles in a2D plane. Each rectangle is defined by ...

  6. 如何在Linux上使用文件作为内存交换区(Swap Area)

    交换区域(Swap Area)有什么作用? 交换分区是操作系统在内存不足(或内存较低)时的一种补充.通俗的说,如果说内存是汽油,内存条就相当于油箱,交换区域则相当于备用油箱. Ubuntu Linux ...

  7. MVC 添加Area

    在MVC项目中经常会使用到Area来分开不同的模块让项目结构更加的清晰. 步骤如下: 项目 –> 添加 -> 区域 ( Area ) 输入 Admin 添加成功后 Area包含: 创建一个 ...

  8. ASP.NET MVC 设置Area中 Controller 的方法 默认启动页

    MVC中通常分区域编程,互不干扰,如果需要设置某个区域下面的某个控制器下面的某个方法为默认启动页的话,直接修改项目的路由如下: public static void RegisterRoutes(Ro ...

  9. [ASP.NET MVC 小牛之路]08 - Area 使用

    ASP.NET MVC允许使用 Area(区域)来组织Web应用程序,每个Area代表应用程序的不同功能模块.这对于大的工程非常有用,Area 使每个功能模块都有各自的文件夹,文件夹中有自己的Cont ...

随机推荐

  1. flex+AS3编程规范

    flex+AS3编程规范 Flex+AS3编码规范 http://www.cnblogs.com/jiahuafu/   1.  缩写: 尽量避免使用缩写,使用缩写时尽量和Flex保持一致.但要记住一 ...

  2. web安全测试工具的局限性

    讨论安全漏洞的原理,谈谈工具的局限. 先说下扫描工具的原理: 扫描工具可以看做由两部分组成:爬虫+校验机构.爬虫的作用是搜集整个被采集对象的链接,然后校验机构对这些链接逐一进行验证. 说扫描工具的局限 ...

  3. MongoDB学习(四)客户端工具备份数据库

    在上一篇MongoDB学习(三)中讲解了如何在服务器端进行数据的导入导出与备份恢复,本篇介绍下如何利用客户端工具来进行远程服务器的数据备份到本地. 以客户端工具MongoVUE为例来进行讲解: 1.首 ...

  4. 导航 tab

  5. scala学习之第三天:数组的特性与使用技巧

    1.数组 Scala数组与Scala序列是兼容的 - 在需要Seq[T]的地方可由Array[T]代替.最后,Scala数组支持所有的序列操作. 隐式转换 方法1:通过scala.collection ...

  6. c语言 &取地址运算符的理解

    对于c语言中的&运算符,百度百科是这样定义的:(&p)则是这样一种运算,返回当时声明p 时开辟的地址:但是根据我对代码的观察,我觉得&运算符不只是返回地址的功能: 例如: in ...

  7. Java6 String.substring()方法的内存泄露

    substring(start,end)在Java编程里面经常使用,没想到如果使用不当,会出现内存泄露. 要了解substring(),最好的方法便是查看源码(jdk6): /** * <blo ...

  8. Spring4 MVC文件下载实例

    这篇文章将向您展示如何使用Spring MVC4执行文件下载,我们将看到应用程序从文件系统内部以及外部文件下载文件. 本教程的主要亮点: 下载文件是相当简单的,涉及以下步骤. 创建一个InputStr ...

  9. 尝试EJB整合Mybatis部署时报错:获得带有类加载器MybatisUtil的ModuleClassLoader的反射信息出错,请问大神如何解决

    mybatis的配置 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configurati ...

  10. 微信小程序内测申请

    想申请微信小程序的内测?别做梦了! 小程序内测是邀请制的,目前就发放了200个内测邀请.正因为稀缺,江湖传言内测资格已经炒到300万(一套房)一个了 但是!!!!你可以先熟悉一下相关资料和文档,下载一 ...