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

跑了32MS,有兴趣的看看

Posted by gtzygtzy at 2009-09-18 20:30:52 on Problem 1654
In Reply To:这题怎么节省时间,我按照经典的叉积方法实现,却用了500多ms,请问15ms的是怎么搞的? Posted by:liyineng at 2006-07-30 12:14:45
> 这题怎么节省时间,我按照经典的叉积方法实现,却用了500多ms,请问15ms的是怎么搞的?
#include<iostream>
using namespace std;
char in[1000010];
struct point
{
	int x,y;
}pre,now;
int cx[]={0,-1,-1,-1,0,0,0,1,1,1};
int cy[]={0,-1,0,1,-1,0,1,-1,0,1};
int main()
{
	int test,i;
	__int64 re;
	scanf("%d",&test);
	while(test--)
	{
		scanf("%s",in);
		i=0;
		pre.x=0;pre.y=0;
		now.x=0;now.y=0;
		re=0;
		while(in[i]!='5')
		{
			if(i>0 && in[i]!=in[i-1])
			{
				re+=pre.x*now.y-pre.y*now.x;
				pre=now;
				now.x=now.x+cx[in[i]-'0'];
				now.y=now.y+cy[in[i]-'0'];
			}
			else
			{
				now.x=now.x+cx[in[i]-'0'];
				now.y=now.y+cy[in[i]-'0'];
			}
			i++;
		}
		pre.x=0;pre.y=0;
		re+=pre.x*now.y-pre.y*now.x;
		if(re<0) re=-re;
		if(re%2) printf("%I64d.5\n",re/2);
		else printf("%I64d\n",re/2);
	}
	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