poj 1654 Area(计算几何--叉积求多边形面积)
2024-10-18 23:22:21
一个简单的用叉积求任意多边形面积的题,并不难,但我却错了很多次,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 ;
}
最新文章
- Visual Basic 2012 借助DataGridView控件将SQL server2012 数据导入到Excel 2010
- 使用keytool生产jks证书
- Linux学习笔记(8)Linux常用命令之网络命令
- Lucene4.3开发之分词器总结
- Java 集合深入理解(3):Collection
- 关于UNION ALL与 UNION 用法和区别
- Hibernate逍遥游记-第12章 映射值类型集合-002映射Bag(<;idbag>;<;collection-id>;)
- L-value 和 R-value.
- GC算法之串行并行并发
- JProfiler简明使用教程
- C语言一个双向链表的实现
- java之web开发过滤器
- 查看电脑系统参数(Windows)
- 分享:使用 TypeScript 编写的游戏代码
- CSS的继承和使用方式
- saltstack API(一) 安装并测试
- poj 1151 (未完成) 扫描线 线段树 离散化
- gentoo 图像方面的软件
- 数据库-mysql命令
- Git-简单的利用SourceTree提交代码