Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么我area/4才对????????

Posted by jinhouyu at 2015-07-25 11:20:55 on Problem 1654
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<iostream>
#define INF 0x7fffffff
#define eps 1e-8
#define manx 1000005
typedef long long LL;
using namespace std;

char step[manx];
double xo,yo;
struct Point{
	double x,y;
};
double Multi(Point p1,Point p2)
{
	return (p2.x*p1.y)-(p1.x*p2.y);
} 
void Move(char ch)
{
	switch(ch)
			{
				case '8':{yo+=1;break;}
				case '2':{yo-=1;break;}		
				case '6':{xo+=1;break;}
				case '4':{xo-=1;break;}
				case '9':{xo+=1;yo+=1;break;}
				case '7':{xo-=1;yo+=1;break;}	
				case '3':{xo+=1;yo-=1;break;}
				case '1':{xo-=1;yo-=1;break;}
				case '5':{xo=0;yo=0;break;}
			}  
}
int main()
{
	int T,i;
	char ch1,ch2;
	scanf("%d",&T);
	getchar();
	while(T--)
	{
		double sum=0.0;
		xo=0.0,yo=0.0;
		gets(step);
		for(i=0;step[i]!='5';i++)
		{
			Point a,b;
			Move(step[i]);
			a.x=xo;
			a.y=yo;
			Move(step[i+1]);
			b.x=xo;
			b.y=yo; 
			if(step[i+1]=='5')
				break;
			sum+=Multi(a,b);
		}
		sum=fabs(sum)/4;//求解为什么。。。。。
		if(sum-floor(sum)<eps)
			printf("%.f\n",sum);
		else
			printf("%.1f\n",sum);
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator