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 ...
随机推荐
- PhoneGap与WAP站静态化
最近在参与的WAP站项目,决定将所有页面都静态化处理,登录验证.价格数据等都通ajax动态的方式实现.开始这么规划的目前是为了页面提高网站加载速度及SEO,最近看到了一篇报道phonegap buil ...
- 【转】EXT JS MVC开发模式
原文链接:EXT JS MVC开发模式 在app(亦即根目录)文件夹下面创建controller.model.store和view文件夹,从名称上就知道他们该放置什么代码了吧.然后创建Applicat ...
- 在vmware 6.5+ubuntu12.04上安装VMware tools出现问题的分析
笔者已经写了一篇关于安装"VMware Tools",以实现文件共享的文章,那篇文章对于你实现共享操作是足够了, 所以,倘若你赶时间不如直接去在虚拟机的linux中利用VMware ...
- 时序图(Sequence Diagram)
控制焦点Focus on Control 的取值: Alternative fragment(denoted “alt”) 与 if…then…else对应 Option fragment (deno ...
- python manage.py shell之后的一些错误:
1. 在执行python manage.py shell之后的一些错误: wyl@wyl:~/myobject$ python manage.py shell /usr/lib/python2.7/d ...
- the apply of backbone
http://www.developer.com/print/lang/jscript/creating-a-javascript-driven-online-notebook-with-backbo ...
- mysql优化案例
MySQL优化案例 Mysql5.1大表分区效率测试 Mysql5.1大表分区效率测试MySQL | add at 2009-03-27 12:29:31 by PConline | view:60, ...
- 【网络流24题】 No.22~24
接下来几题就写写题解吧.不是很想打了. 22. 输入文件示例input.txt4 21 2 7 36 5 8 37 8 10 59 6 13 9 输出文件示例output.txt17 最长不相交路径. ...
- 【网络流24题】No.8 机器人路径规划问题
[题意] 机器人 Rob 可在一个树状路径上自由移动. 给定树状路径 T 上的起点 s 和终点 t, 机器人 Rob 要从 s 运动到 t. 树状路径 T 上有若干可移动的障碍物. 由于路径狭窄, 任 ...
- 【HDU 4372】 Count the Buildings (第一类斯特林数)
Count the Buildings Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...