一个简单的用叉积求任意多边形面积的题,并不难,但我却错了很多次,double的数据应该是要转化为long long,我转成了int...这里为了节省内存尽量不开数组,直接计算,我MLE了一发...,最后看了下别人的才过,我的代码就不发了,免得误导,不得不说几何真是...
还有就是这个大神的代码,貌似G++,过不了,C++AC
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
using namespace std;
int moveY[] = {-, , , -, , , -, , };
int moveX[] = {-, -, -, , , , , , };
char step[];
#define EPS 1e-8
int main()
{
int t;
scanf("%d\n", &t);
int x, y, px, py;
double area;
long pos = ;
while (t--)
{
x = y = px = py = ;
pos = area = ;
scanf("%s", step);
while (step[pos] != '')
{
x = px + moveX[step[pos]-''];
y = py + moveY[step[pos]-''];
area += 0.5*(px*y-py*x);
px = x;
py = y;
pos++;
}
area = fabs(area);
if (fabs((long long)area - area)<EPS)
{
printf("%.0lf\n", area);
}
else
{
printf("%.1lf\n", area);
}
}
return ;
}