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

求救:怎么会WA呢

Posted by seol at 2004-10-03 22:19:23 on Problem 1809
#include <stdio.h>
#include <stdlib.h>

struct  Node;					  /* 单链表结点类型 */
typedef  struct Node  *PNode;	  /* 结点指针类型 */
typedef  struct Node  *LinkList;  /* 单链表类型 */

struct  Node { 					  /* 单链表结点结构 */
    long int info;
    PNode     link;
};

LinkList  createNullList_link( void ) {   
    LinkList llist;
    llist = (LinkList)malloc( sizeof( struct Node ) );	/* 申请表头结点空间 */
    if( llist != NULL ) llist->link = NULL;
    return llist;
}

long int count1(long int c)
{
	if (c==0 || c==1 || c==2) return 0;
	return (c*(c-1)*(c-2)/6);
}

long int count2(long int c1, long int c2)
{
	if (c1==0) return 0;
	return (c2*c1*(c1-1)/2);
}

LinkList create(LinkList llist)
{
	PNode p=llist,q;
	long int num,i;
	long int number,j,x,y,mm,b1,b2,b3,b4;
	scanf("%ld",&num);
	for (i=0;i<num;i++) {
		scanf("%ld",&number);
		b1=b2=b3=b4=0;
		for (j=0;j<number;j++) {
			scanf("%ld %ld",&x,&y); if (x<0) x=-x; if (y<0) y=-y;
			if (x%2==0 && y%2==0) b1+=1;
			if (x%2==0 && y%2==1) b2+=1;
			if (x%2==1 && y%2==0) b3+=1;
			if (x%2==1 && y%2==1) b4+=1;
		}  
		mm=count1(b1)+count1(b2)+count1(b3)+count1(b4);
		mm+=count2(b1,b2)+count2(b1,b3)+count2(b1,b4)+count2(b2,b1)+count2(b2,b3)+count2(b2,b4)+count2(b3,b1)+count2(b3,b2)+count2(b3,b4)+count2(b4,b1)+count2(b4,b2)+count2(b4,b3);
		q=(PNode)malloc(sizeof(struct Node));
		if (q==NULL)  {printf("Out of space!");return NULL;}
		q->info=mm; q->link=NULL;p->link=q;p=p->link;
	}
	return llist;
}

void print(LinkList llist)  /* 打印 */
{
	long int s=1;
	PNode p=llist->link;
	while (p!=NULL) {
		printf("Scenario #%ld:\n",s);
		printf("%ld\n\n",p->info);
		s++;
		p=p->link;
	}
}

int main()
{
	LinkList llist;
	llist=createNullList_link();
	llist=create(llist);
	print(llist);
	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