| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
旋转45度,数学之,附代码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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator