poj 1654

<span style="color:#3366ff;"><span style="font-size:24px;"><span style="color:#000099;">求面积</span><span class="crawlInfo" id="crawling" style="display: none;"><strong>Crawling in process...</strong>		 </span>	</span></span>	 <span class="crawlInfo" id="crawlFailed" style="display: none;"><strong><span style="color:red;">Crawling failed</span></strong>		 </span>		 
<span class="crawlInfo" id="crawlSuccess"><strong>Time Limit:</strong><span id="timeLimit">1000</span>MS    			 <strong>Memory Limit:</strong><span id="memoryLimit">10000</span>KB    			 <strong>64bit IO Format:</strong><span id="_64IOFormat">%I64d & %I64u</span>		 </span>		 
Submit			 Status					 
<div style="margin: auto; width: 960px;"><div class="hiddable" id="vj_description" style="display: block;"><p class="pst">Description</p><div class="textBG"><div class="ptx" lang="en-US"> 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:         
<center><img src="http://poj.org/images/1654_1.jpg" alt="" /></center></div></div></div><div class="hiddable" id="vj_input" style="display: block;"><p class="pst">Input</p><div class="textBG"><div class="ptx" lang="en-US"> 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.       </div></div></div><div class="hiddable" id="vj_output" style="display: block;"><p class="pst">Output</p><div class="textBG"><div class="ptx" lang="en-US"> For each polygon, print its area on a single line.       </div></div></div><div class="hiddable" id="vj_sampleInput" style="display: block;"><p class="pst">Sample Input</p><div class="textBG"><pre class="sio">4
5
825
6725
6244865

Sample Output

0
0
0.5
2
 


#include<stdio.h>
#include<string.h>
int dir[10][2] = {{0,0},{-1,-1},{0,-1},{1,-1},{-1,0},{0,0},{1,0},{-1,1},{0,1},{1,1}};//以走的那一点为原点,然后像8个方向走。带入方程,求出面积。
char c[100000000];
long long get(long long x1,long long y1,long long x2,long long y2)
{
    return x1 * y2 - x2 * y1;
}
int main()
{
    long long s;
    int i, n, j;
    long long x1, y1, x2, y2;
    scanf("%d",&n);
    while(n --)
    {
        s = 0;
        scanf("%s",c);
        int len = strlen(c);
        x1 = 0;
        y1 = 0;
        for(j = 0; j < len; j ++)
        {
            if(c[j] == '5')
                break;
            x2 = dir[c[j] - '0'][0] + x1;
            y2 = dir[c[j] - '0'][1] + y1;
            s += get(x1,y1,x2,y2);
            x1 = x2;
            y1 = y2;
        }
        if(s < 0)
        s = -s;
        if(s % 2 != 0)
            printf("%I64d.5\n",s / 2);
        else
            printf("%I64d\n",s / 2);
    }
    return 0;
}
做这道题目时, 不大会做,在编译上出现了很多问题,参考了几个模板,才大体知道怎么做。
今天刚学几何,本来感觉应该挺简单的,可是做起来完全不是那回事。
挫败啊。。。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值