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

这段代码是2684题的,为什么c++总是runtime error?郁闷死了。有哪位大侠肯指点一二?

Posted by Rieman at 2009-10-12 18:28:54 on Problem 2684
#include <iostream>
#include <cmath>
using namespace std;
struct p
{
  int x,y;
}v[12];
bool turn(p a,p b,p c)
{
  bool d[4];
  d[0]=(a.y==b.y)&&(a.x>b.x)&&(b.x==c.x)&&(c.y>b.y);
  d[1]=(a.x==b.x)&&(b.y>a.y)&&(b.y==c.y)&&(c.x>b.x);
  d[2]=(a.y==b.y)&&(b.x>a.x)&&(b.x==c.x)&&(b.y>c.y);
  d[3]=(a.x==b.x)&&(a.y>b.y)&&(b.y==c.y)&&(b.x>c.x);
  if(d[0]||d[1]||d[2]||d[3])
    return 1;
  else
    return 0;
}
int length(p a,p b)
{
  if(a.x==b.x)
    return abs(a.y-b.y);
  else
    return abs(a.x-b.x);
}
int main()
{
  int g,d[12],w,u[108],direction[12],m,k,mp,f,i,n,line[12],li[12];
  while(cin>>n&&n)
  {
    scanf("%d",&m);
    w=0;
    for(k=1;k<m+1;k++)
	 cin>>v[k].x>>v[k].y;
    for(k=1;k<m;k++)
	 line[k]=length(v[k],v[k+1]);
    for(k=1;k<m-1;k++)
	 direction[k]=turn(v[k],v[k+1],v[k+2]);
    for(i=0;i<n;i++)
    {
	 scanf("%d",&mp);
	 if(mp!=m)
	   continue;
	 for(k=1;k<mp+1;k++)
	   cin>>v[k].x>>v[k].y;
	 for(k=1;k<mp;k++)
	   li[k]=length(v[k],v[k+1]);
	 for(k=1;k<mp-1;k++)
	   d[k]=turn(v[k],v[k+1],v[k+2]);
	 f=1;
	 for(k=1;k<mp;k++)
	   if(li[k]!=line[k])
		f=0;
	 for(k=1;k<mp-1;k++)
	   if(direction[k]!=d[k])
		f=0;
	 g=1;
	 for(k=1;k<mp;k++)
	   if(li[k]!=line[mp-k])
		g=0;
	 for(k=1;k<mp-1;k++)
	   if(!d[k]!=direction[mp-1-k])
		g=0;
	 if(f||g)
	   u[w++]=i+1;
    }
    for(i=0;i<w;i++)
	 cout<<u[i]<<endl;
    printf("+++++\n");
  }
  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