Area
来源:互联网 发布:java讲师技术含量 编辑:程序博客网 时间:2024/04/30 12:15
You are going to compute the area of a special kind of polygon. One vertex of the polygon is the origin of the orthogonal coordinate system. From this vertex, you may go step by step to the following vertexes of the polygon until back to the initial vertex. For each step you may go North, West, South or East with step length of 1 unit, or go Northwest, Northeast, Southwest or Southeast with step length of square root of 2.
For example, this is a legal polygon to be computed and its area is 2.5:
Input
The 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
For each polygon, print its area on a single line.
代码:
const x:array[1..9] of longint=(1,1,1,0,0,0,-1,-1,-1); y:array[1..9] of longint=(-1,0,1,-1,0,1,-1,0,1);var s:array[0..1000000] of longint; a,b:array[1..3] of longint; n,i,ans:longint; c:char;begin read(n); while n>0 do begin while eoln=false do begin read(c); inc(s[0]); s[s[0]]:=ord(c)-48; end; a[3]:=y[s[1]];b[3]:=x[s[1]]; a[1]:=a[3];b[1]:=b[3]; for i:=2 to s[0] do begin a[2]:=a[3];b[2]:=b[3]; a[3]:=a[3]+y[s[i]]; b[3]:=b[3]+x[s[i]]; ans:=ans+abs((a[2]*b[3])-(a[3]*b[2])); end; ans:=ans+abs((a[3]*b[1])-(b[3]*a[1])); writeln(ans div 2); if ans mod 2=1 then write('.5'); n:=n-1; end;end.
- Area
- Area
- Area
- area
- Area
- Area
- zoj1010 Area
- Controlling Area
- mrp area
- The area
- Arable Area
- ZOJ1010 Area
- Circular Area
- POJ1265 Area
- Area (P1654)
- poj1654 - Area
- HDACM217 area
- map area
- 树形DP-POJ-2342-Anniversary party
- 【携程】2016研发工程师笔试
- 微信开发获取access_token函数库
- 接口
- 2016 ICPC 大连 网络赛
- Area
- 数据结构实验之链表八:Farey序列
- leetCode练习(20)
- HDU 1025 Constructing Roads In JGShining's Kingdom ( LIS )
- 设计模式——6.单例模式(包含多线程环境下的一些写法)
- Ubuntu使用SVN 命令以及使用方法
- 第四周项目2-建设“单链表”算法库
- 生活随笔
- 前台页面通过JS调用Servlet访问到后台类