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

注意:精度问题,使用long long /__int64,直接使用double不准确。方向的处理使用数组。
// Time 94ms; Memory 1036K
#include<iostream>
#include<cstring>
#define maxn 1000010 using namespace std; char s[maxn];
long long dx[]={-1,0,1,-1,0,1,-1,0,1},dy[]={-1,-1,-1,0,0,0,1,1,1}; struct point
{
long long x,y;
point(long long xx=0,long long yy=0):x(xx),y(yy){}
}a,b; long long cross()
{
return a.x*b.y-a.y*b.x;
}
int main()
{
int i,t,l;
long long are;
cin>>t;
while(t--)
{
cin>>s;
l=strlen(s);
if(l<2)
{
cout<<"0"<<endl;continue;
}
a=point(dx[s[0]-49],dy[s[0]-49]);
b=point(a.x+dx[s[1]-49],a.y+dy[s[1]-49]);
are=cross();
for(i=2;s[i];i++)
{
a=b;
b=point(a.x+dx[s[i]-49],a.y+dy[s[i]-49]);
are+=cross();
}
if(are<0) are=-are;
cout<<are/2;
if(are%2) cout<<".5";
cout<<endl;
}
return 0;
}

POJ 1654 Area的更多相关文章

  1. poj 1654 Area 多边形面积

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

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

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

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

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

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

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

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

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

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

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

  7. POJ 1654 Area 计算几何

    #include<stdio.h> #include<string.h> #include<iostream> #include<math.h> usi ...

  8. POJ 1654 area 解题

    Description You are going to compute the area of a special kind of polygon. One vertex of the polygo ...

  9. POJ 1654 Area(水题)

    题目链接 卡了一下精度和内存. #include <cstdio> #include <cstring> #include <string> #include &l ...

随机推荐

  1. DataTable与实体类的转换

    多年前写的DataTable与实体类的转换,已放github 阅读目录 介绍 起因 代码 UnitTest GitHub 介绍 很多年前一直使用Ado.net,后来慢慢转型到其他的orm,在转型过程中 ...

  2. 一张地图,告诉你NodeJS命令行调试器语句

    NodeJS提供脚本调试. 进入node debug xx.js您可以进入调试模式. 版权声明:本文博客原创文章,博客,未经同意,不得转载.

  3. navicat连接oracle数据库报ORA-28547: connection to server failed, probable Oracle Net admin error错误的解决方法

    原文:navicat连接oracle数据库报ORA-28547: connection to server failed, probable Oracle Net admin error错误的解决方法 ...

  4. 分布式消息系统kafka

    kafka:一个分布式消息系统 1.背景 最近因为工作需要,调研了追求高吞吐的轻量级消息系统Kafka,打算替换掉线上运行的ActiveMQ,主要是因为明年的预算日流量有十亿,而ActiveMQ的分布 ...

  5. sql 中如何取出指定行: Row_Number

    原文:sql 中如何取出指定行: Row_Number ROW_NUMBER (Transact-SQL) USE AdventureWorks2008R2;GOWITH OrderedOrders ...

  6. Linux下查看使用频率最高的十个命令

    这个shell是在linux吧一个小伙伴发的,链接已找不到,挺有意思的,隔段时间运行一次,可以看看自己最近都干了什么. [shell] history | awk '{CMD[$2]++;count+ ...

  7. Asterisk 未来之路3.0_0005

    原文:Asterisk 未来之路3.0_0005 第二章: Asterisk的架构   Asterisk 和其他众多传统的PBX是有区别的,拨号方案针对各种通道处理本质上采用同一种方式. 在传统的PB ...

  8. mysql的架构

    和其他数据库相比,mysql有点与众不同,它的架构可以在多种不同场景中应用并发挥好的作用,而理解其设计是发挥好作用的先决条件 每当我们在想起mysql的逻辑架构师,我们可以构造一副mysql各组件之间 ...

  9. C# 利用SMTP异步发送邮件

    C#实现收发邮件功能需要用到两个命名空间  System.Net; 和 System.Net.Mail; SmtpClient client = new SmtpClient("smtp.g ...

  10. 使用jquery.form异步提交注意jquery.validate需要手动添加验证

    使用jquery.form.js异步提时,即使jquery.validate验证失败也会提交的所以加个$("form").valid()来判断是否通过验证: $("#fo ...