poj 1654 Area(求多边形面积)

题意:从原点出发向八个方向走,所给数字串每个数字代表一个方向,终点与原点连线,求所得多边形面积;

思路:(性质)共起点的两向量叉积的一半为两向量围成三角形的面积。以此计算每条边首尾两个向量的叉积,求和,除二;

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const double epsi=1e-10;
const double pi=acos(-1.0);
const int maxn=100005;
inline int sign(const double &x){
    if(x>epsi) return 1;
    if(x<-epsi) return -1;
    return 0;
}
struct point{
    long long x,y;
    point(double xx,double yy):x(xx),y(yy) {}
    point operator +(const point &op2) const{
        return point(x+op2.x,y+op2.y);
    }
    long long operator ^(const point &op2) const{
        return x*op2.y-y*op2.x;
    }
};
int main()
{
    int t,i,j,k;
    string s;
    long long ans;
    scanf("%d",&t);
    while(t--){
        cin>>s;
        ans=0;
        point p=point(0,0),p1=point(0,0);
        for(int i=0;i<s.size();i++){
            if(s[i]==‘1‘) p1=p+point(-1,-1);
            if(s[i]==‘2‘) p1=p+point(0,-1);
            if(s[i]==‘3‘) p1=p+point(1,-1);
            if(s[i]==‘4‘) p1=p+point(-1,0);
            if(s[i]==‘5‘) p1=p+point(0,0);
            if(s[i]==‘6‘) p1=p+point(1,0);
            if(s[i]==‘7‘) p1=p+point(-1,1);
            if(s[i]==‘8‘) p1=p+point(0,1);
            if(s[i]==‘9‘) p1=p+point(1,1);
            ans+=p^p1;
            p=p1;
        }
        if(ans<0) ans=-ans;
        printf("%lld",ans/2);
        if(ans%2) printf(".5");
        printf("\n");
    }
    return 0;
}
时间: 2024-12-26 02:51:43

poj 1654 Area(求多边形面积)的相关文章

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

Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16894   Accepted: 4698 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 thi

Area - POJ 1654(求多边形面积)

题目大意:从原点开始,1-4分别代表,向右下走,向右走,向右上走,向下走,5代表回到原点,6-9代表,向上走,向左下走,向左走,向左上走.求出最后的多边形面积. 分析:这个多边形面积很明显是不规则的,可以使用向量积直接求出来面积即可. 代码如下: ------------------------------------------------------------------------------------------------------------------------------

poj 1654 Area(多边形面积)

Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17456   Accepted: 4847 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 thi

poj 1654 Area (多边形求面积)

链接: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 orth

poj1408——叉积求多边形面积

poj1408——叉积求多边形面积 Fishnet Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1853   Accepted: 1185 Description A fisherman named Etadokah awoke in a very small island. He could see calm, beautiful and blue sea around the island. The previou

poj1265--Area(求多边形面积+匹克定理)

Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5150   Accepted: 2308 Description Being well known for its highly innovative products, Merck would definitely be a good target for industrial espionage. To protect its brand-new resear

hdu 2036 求多边形面积 (凸、凹多边形)

<题目链接> Problem Description " 改革春风吹满地,不会AC没关系;实在不行回老家,还有一亩三分地.谢谢!(乐队奏乐)" 话说部分学生心态极好,每天就知道游戏,这次考试如此简单的题目,也是云里雾里,而且,还竟然来这么几句打油诗.好呀,老师的责任就是帮你解决问题,既然想种田,那就分你一块.这块田位于浙江省温州市苍南县灵溪镇林家铺子村,多边形形状的一块地,原本是linle 的,现在就准备送给你了.不过,任何事情都没有那么简单,你必须首先告诉我这块地到底有多

三角剖分求多边形面积的交 HDU3060

1 //三角剖分求多边形面积的交 HDU3060 2 3 #include <iostream> 4 #include <cstdio> 5 #include <cstring> 6 #include <stack> 7 #include <queue> 8 #include <cmath> 9 #include <algorithm> 10 using namespace std; 11 12 const int max

POJ 3348 Cows(凸包+多边形面积)

先求出凸包,然后利用凸包求出面积,除以50就是答案 代码: #include<cstdio> #include<cmath> #include<algorithm> using namespace std; const int MAXN=10005; struct Point { double x, y; Point() {} Point(double x, double y) { this->x = x; this->y = y; } void read(