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

不是太水,只是比较水而已。我的代码,完全就是数学题嘛

Posted by 20083331 at 2009-04-29 08:24:40 on Problem 1969
#include<iostream>
using namespace std;

int main()
{
	long n;
	while((scanf("%d",&n))==1)
	{
		int i;
		long sum1,sum2,sum3,sum4;
		for(i=0;;i++)
		{
			sum1=(2*i-1)*i;
			sum2=(2*(i+1)-1)*(i+1);
//			cout<<"sum1  is "<<sum1<<" sum2   is    "<<sum2<<endl;
			if(n>sum1 && n<=sum2)
				break;
		}
		int temp1=n-sum1;
		
		if(temp1<=2*i+1)
			cout<<"TERM "<<n<<" IS "<<temp1<<"/";
		else
			cout<<"TERM "<<n<<" IS "<<4*i+2-temp1<<"/";
		
		for(i=0;;i++)
		{
			sum3=2*i*i+i;
			sum4=2*(i+1)*(i+1)+(i+1);
//			cout<<"sum 3   is   "<<sum3<<"   sum4    is   "<<sum4<<endl;
			if(n>sum3 && n<=sum4)
				break;
		}
		int temp2=n-sum3;
//		cout<<"temp2   is   "<<temp2<<endl;
//		cout<<"and the 2*(i+1)"<<2*(i+1)<<endl;
		
		if(temp2<=2*(i+1))
			cout<<temp2<<endl;
		else
			cout<<4*(i+1)-temp2<<endl;
	}

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