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 200730720308 at 2008-08-31 16:42:01 on Problem 3685
初学C,写得不好!!!


#include"stdio.h"
int i,j;
long a[100],b[100];
void f(long a,long b)
{
	int temp,k;
	long aa,bb;
	aa=a;bb=b;
	temp=aa*(aa+1)/2;
	if(bb<=temp)
	{
		for(k=1;;k++)
		{
			if(bb-k<=0)
				break;
			bb-=k;
		}
		i=bb;
		j=a-k+bb;
	}
	else//与上面得if是对称的
	{
		bb=aa*aa+1-bb;
		for(k=1;;k++)                      //与
		{                                  //上
			if(bb-k<=0)                //面
				break;             //的
			bb-=k;                     //方
		}                                  //法
		i=bb;                              //相
		j=a-k+bb;                          //同
		i=a+1-i;                           
		j=a+1-j;                            
	}
	return;
}
void main()
{
	int k,n;
	scanf("%d",&n);
	for(k=1;k<=n;k++)
	{
		scanf("%d %d",&a[k],&b[k]);
	}
	for(k=1;k<=n;k++)
	{
		f(a[k],b[k]);//找出指定位置得二维下标(i,j)
		printf("%ld\n",i*i+100000*i+j*j-100000*j+i*j);
	}
}

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