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

旋转45度,数学之,附代码

Posted by lsz at 2011-05-06 19:44:49 on Problem 1969
1/1
2/1 1/2
3/1 2/2 1/3
4/1 3/2 2/3 1/4
5/1 4/2 3/3 2/4 1/5

#include <iostream>
#include <complex>
using namespace std;

int main()
{
	int n;
	while (cin>>n && n > 0)
	{
		if (n <= 1)
		{
			cout<<"TERM 1 IS 1/1"<<endl;
			continue;
		}

		int row = (int)(sqrt(2.0 * n) + 0.5);
		int column = n - (row * (row - 1)) / 2;
		if (row % 2 == 0)
		{
			column = row + 1 - column;
		}
		cout<<"TERM "<<n<<" IS "<<row + 1 - column<<"/"<<column<<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