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

79MS...一次读入比单个来得快

Posted by Acaini at 2009-10-06 13:08:13 on Problem 1654
In Reply To:跑了32MS,有兴趣的看看 Posted by:gtzygtzy at 2009-09-18 20:30:52
> #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