| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
跑了32MS,有兴趣的看看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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator