题意:从原点出发,沿着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. Hadoop-2.4.1学习之Writable及事实上现

    Hadoop基于DataInput和DataOutput实现了简单.高效的序列化协议,而Writable接口定义了Hadoop序列化的方法,MapReduce框架中的不论什么键值类型都实现了该接口,比 ...

  2. Winform: use the WebBrowser to display XML with xslt, xml, xslt 转 html 字符串

    原文:Winform: use the WebBrowser to display XML with xslt, xml, xslt 转 html 字符串 声明xml字符串: string xml = ...

  3. nodeJS起步 1

    nodeJS起步 -- (1) 先来简单介绍nodeJS 我们知道JavaScript是运行在浏览器中的,浏览器为它提供了一个上下文(context),从而让JavaScript得以解析执行. nod ...

  4. [Unity3D]Unity3D游戏开发Android内嵌视图Unity查看

    ---------------------------------------------------------------------------------------------------- ...

  5. Delphi三层网络架构代码实现

    Delphi三层网络架构代码实现 1 .三层网络的概念 三层架构(3-tier architecture) 通常意义上的三层架构就是将整个业务应用划分为: 表现层(UI).业务逻辑层(BLL).数据访 ...

  6. PHP激活用户注册验证邮箱

    本文将结合实例介绍如何使用PHP+Mysql完成注册帐号.发送激活邮件.验证激活帐号.处理URL链接过期的功能. 注册邮箱激活流程 <ul class='ul_demo''> <li ...

  7. android rawquery和query对照

    Cursor cursor = db.rawQuery("select name from *** where id=? ", new String[]{"1" ...

  8. jquery背景动画插件使用

    在网页制作动画特效的时候,有时候想通过背景插入图片,然后通过控制背景显示的位置来实现一些动画效果,这样就不用使用绝对定位控制left和top来实现动画效果!但是jquery本身的动画函数是不支持背景动 ...

  9. 【从0开始Tornado网站】主页登录和显示的最新文章

    日志首页只能放置在它,这里的美,该<form>使用bootstrap的form-inline修改后的类,例如以下列方式: 前台代码例如以下: {%extends 'main.html'%} ...

  10. Extjs中GridPanel的各个属性与方法

    1.Ext.grid.GridPanel 主要配置项: store:表格的数据集 columns:表格列模式的配置数组,可自动创建ColumnModel列模式 autoExpandColumn:自动充 ...