博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 1654 Area
阅读量:4450 次
发布时间:2019-06-07

本文共 2519 字,大约阅读时间需要 8 分钟。

Area
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 9933   Accepted: 2813

Description

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.

Sample Input

4582567256244865

Sample Output

000.52

Source

 
计算几何求面积的题。假设初始点为(0,0),然后连续两点不断求叉积,最后的和即为所求面积。使用double可能会溢出所以用long long。判断一下奇偶然后决定是否输出.5即可。
 
用g++交Wrong Answer但是c++是Accepted
 
1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 13 14 int dx[10] = { 0,-1,0,1,-1,0,1,-1,0,1};15 int dy[10] = { 0,-1,-1,-1,0,0,0,1,1,1};16 17 using namespace std;18 19 char s[1000005];20 21 double crs(pair
a,pair
b)22 {23 return a.first*b.second-a.second*b.first;24 }25 26 int main(void)27 {28 int total;29 cin >> total;30 while(total--)31 {32 long long ans = 0;33 scanf("%s",s);34 pair
a(0,0),b(0,0);35 int length = strlen(s)-1;36 for(int i(0);i != length;++i)37 {38 b.first = a.first+dx[s[i]-'0'];39 b.second = a.second+dy[s[i]-'0'];40 ans += crs(a,b);41 a = b;42 }43 if(ans < 0)44 ans = -ans;45 long long halfans = ans/2;46 if(halfans*2 == ans)47 cout << halfans << endl;48 else49 cout << halfans << ".5" << endl;50 }51 52 return 0;53 }

 

转载于:https://www.cnblogs.com/1-2-1-3/archive/2012/04/25/2469434.html

你可能感兴趣的文章
1204. Maze Traversal
查看>>
安装gitlab ce
查看>>
【Hadoop 分布式部署 八:分布式协作框架Zookeeper架构功能讲解 及本地模式安装部署和命令使用 】...
查看>>
cogs_396_魔术球问题_(最小路径覆盖+二分图匹配,网络流24题#4)
查看>>
WPF中异步更新UI元素
查看>>
Mapreduce之序列化框架(转自http://blog.csdn.net/lastsweetop/article/details/9376495)
查看>>
python for else
查看>>
kafka 消费模型图
查看>>
[two pointers]Codeforces - 1166C - A Tale of Two Lands
查看>>
电子测量作业——采用DDS(数字频率合成法)设计信号发生器 ,完成设计方案。...
查看>>
Python就业方向
查看>>
一步步学习SPD2010--第二章节--处理SP网站(3)--创建网站层次架构
查看>>
TCP
查看>>
Excel常用函数大全
查看>>
团队-团队编程项目中国象棋-模块测试过程
查看>>
R-创建数据集-ch2
查看>>
gitHub地址
查看>>
10个经典的C语言面试基础算法及代码
查看>>
[概念] js的函数节流和throttle和debounce详解
查看>>
普通的java Ftp客户端的文件上传
查看>>