poj 1654 Area(多边形面积)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 17456 | Accepted: 4847 |
Description
For example, this is a legal polygon to be computed and its area is 2.5:

Input
first line of input is an integer t (1 <= t <= 20), the number of
the test polygons. Each of the following lines contains a string
composed of digits 1-9 describing how the polygon is formed by walking
from the origin. Here 8, 2, 6 and 4 represent North, South, East and
West, while 9, 7, 3 and 1 denote Northeast, Northwest, Southeast and
Southwest respectively. Number 5 only appears at the end of the sequence
indicating the stop of walking. You may assume that the input polygon
is valid which means that the endpoint is always the start point and the
sides of the polygon are not cross to each other.Each line may contain
up to 1000000 digits.
Output
Sample Input
4
5
825
6725
6244865
Sample Output
0
0
0.5
2
Source
【思路】
多边形求面积。
叉积计算。
【代码】
#include<cstdio>
#include<cstring>
using namespace std; typedef long long LL;
const int dx[]={,,,,,,-,-,-};
const int dy[]={-,,,-,,,-,,}; LL ans;
char s[]; int main() {
int T;
scanf("%d",&T);
while(T--) {
ans=;
scanf("%s",s);
int nx=,ny=,x,y;
int l=strlen(s);
for(int i=;i<l;i++) { //为啥直接写strlen(s)会TLE =-=
x=nx+dx[s[i]-''];
y=ny+dy[s[i]-''];
ans += (x*ny-nx*y);
nx=x , ny=y;
}
if(ans<) ans=-ans;
printf("%lld",ans/);
if(ans&) printf(".5");
putchar('\n');
}
return ;
}
poj 1654 Area(多边形面积)的更多相关文章
- poj 1654 Area 多边形面积
/* poj 1654 Area 多边形面积 题目意思很简单,但是1000000的point开不了 */ #include<stdio.h> #include<math.h> ...
- POJ 1654 Area 多边形面积 G++会WA
#include<stdio.h> #include<algorithm> #include <cstring> using namespace std; type ...
- POJ 1654 Area 凸包面积
水题直接码... /********************* Template ************************/ #include <set> #include < ...
- poj 1654 Area (多边形求面积)
链接:http://poj.org/problem?id=1654 Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
- poj 1654 Area(计算几何--叉积求多边形面积)
一个简单的用叉积求任意多边形面积的题,并不难,但我却错了很多次,double的数据应该是要转化为long long,我转成了int...这里为了节省内存尽量不开数组,直接计算,我MLE了一发...,最 ...
- 2018.07.04 POJ 1654 Area(简单计算几何)
Area Time Limit: 1000MS Memory Limit: 10000K Description You are going to compute the area of a spec ...
- POJ 1654 Area
题意:从原点出发,沿着8个方向走,每次走1个点格或者根号2个点格的距离,最终回到原点,求围住的多边形面积. 分析:直接记录所经过的点,然后计算多边形面积.注意,不用先保存所有的点,然后计算面积,边走变 ...
- POJ 3348 /// 凸包+多边形面积
题目大意: 给定的n个点 能圈出的最大范围中 若每50平方米放一头牛 一共能放多少头 求凸包 答案就是 凸包的面积/50 向下取整 /// 求多边形面积// 凹多边形同样适用 因为点积求出的是有向面积 ...
- poj 1654 Area(求多边形面积 && 处理误差)
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16894 Accepted: 4698 Description ...
随机推荐
- ubuntu samba共享安装 配置
参考: http://www.360doc.com/content/11/0615/12/3989678_127081905.shtml 参考: http://xfshean.blog.163.com ...
- cmake,gtest单元测试程序
参考:http://blog.csdn.net/stdcoutzyx/article/details/8284183 PROJECT (HELLO) SET(SRC_LIST main.c) MESS ...
- linux centos cli all proxy
linux centos 下代理http.https.ftp.all_proxy 全局使用代理: export http_proxy=http://host:port/ export https_pr ...
- DelphiXE4- System.IOUtils.TDirectory笔记查询后缀名为dll的文件
TStringDynArray 在System.Types中定义
- jquery mobile页面跳转后,必须重新刷新页面js方可有效
最近在做个项目,用到jquery mobile,很陌生对他,问题一个个的来,那就要一个个解决,找了一天这个问题,放可明白:首先明白jqm里面页面跳转默认都是通过ajax请求的,必须重新刷新页面js方可 ...
- 点评VHDL语言
(1)VHDL的描述风格及语法十分类似于一般的计算机高级语言,但是它是一种硬件描述语言.学好VHDL的关键是充分理解VHDL语句和硬件电路的关系.编写VHDL,就是在描述一个电路,我们写完一段程序后, ...
- bzoj 3153: Sone1 Toptree
3153: Sone1 Time Limit: 40 Sec Memory Limit: 256 MBSubmit: 511 Solved: 202[Submit][Status][Discuss ...
- Torch vs Theano
Torch vs Theano Recently we took a look at Torch 7 and found its data ingestion facilities less than ...
- Colored Sticks
poj2513:http://poj.org/problem?id=2513 题意:就是求一个欧拉回路. 题解:本题是判断欧拉通路是否存在,但是如果是用map的话就会超时,这里采用了trie树,有发现 ...
- Jar包可执行??
第一次听说,jvm加载包,必须rwx么?