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 frkstyc at 2005-12-25 17:32:20 on Problem 1844
In Reply To:Re:简单解法:) Posted by:IC0500510080 at 2005-12-25 17:25:15
> #include<stdio.h>
> void main()
> {
> 	int n,k,m;
> 	scanf("%d",&n);
> 	for(int i=0;;i++)
> 	{
> 		if((i*(i+1)/2)>=n)
> 		{k=i*(i+1)/2;break;}
> 	}
> 	if(k==n)m=i;
> 	else if((k-n)%2==1&&i%2==1)m=i+2;
> 	else if((k-n)%2==1&&i%2==0)m=i+1;
> 	else if((k-n)%2==0)m=i;
> 	printf("%d\n",m);
> }

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