题意:
从一个点出发,8个方向,给出每一步的方向,求出走过的路径形成的多边形的面积。
思路:
先普及一下向量叉乘、、
POJ 1654 乱搞题?
(摘自度娘)
也就是x1y2-x2y1。
那这不就好说了嘛。
一个经过原点的闭合多边形的面积可以分割成多个三角形。
每个三角形的面积就是相邻向量叉乘的一半。
大功告成~
注意精度问题。。。

// by SiriusRen
#include <cstdio>
#include <cstring>
using namespace std;
char a[1000005],xx[]={0,-1,0,1,-1,0,1,-1,0,1};
char yy[]={0,-1,-1,-1,0,0,0,1,1,1};
long long x,y,tempx,tempy,n,ans,cases;
int main(){
    scanf("%lld",&cases);
    while(cases--){
        scanf("%s",a);
        n=strlen(a);ans=x=y=0;
        for(int i=0;i<n;i++){
            tempx=x;tempy=y;
            x+=xx[a[i]-'0'];
            y+=yy[a[i]-'0'];
            ans+=tempx*y-x*tempy;
            if(a[i]=='5')break;
        }
        ans=ans>0?ans:-ans;
        printf("%lld",ans/2);
        if(ans&1)puts(".5");
        else puts("");
    }
}

相关文章:

  • 2022-01-12
  • 2022-12-23
  • 2021-06-29
  • 2022-12-23
  • 2021-11-06
  • 2021-11-16
  • 2021-08-03
  • 2021-09-09
猜你喜欢
  • 2022-12-23
  • 2021-09-27
  • 2021-12-09
  • 2021-06-05
  • 2022-03-09
  • 2022-02-15
  • 2022-12-23
相关资源
相似解决方案