膜拜蛇形矩阵

  

Description

Many Normal students will be teachers after graduating, and as a head teacher, arranging the seats for students is a problem. Xuanflyer wants to arrange seats for his students, and he comes up with a strange idea. 1 4 5 16 2 3 6 15 9 8 7 14 10 11 12 13 He arranges the seats in a snake-shaped way, and each number represents a student’s student number. After finishing it, he was confussed about the particular position of the student whose number is N , please tell him.

Input

The first line contains an integer T(1 <= T <= 100), indicating the number of test cases.For each test case there is a line,contains an integer N(1<=N<=10^9).

Output

For each test case, you should output two integers, indicating the number n 's student seat,the first integer is row ,and the second is column.

Sample Input

2 1 4

Sample Output

1 1 1 2
 #include <functional>
#include <algorithm>
#include <stdexcept>
#include <iostream>
#include <sstream>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <cctype>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <list>
#include <map>
#include <set>
using namespace std;

int main()
{
//freopen("in.txt","r",stdin);
int t ;
cin >> t;
while(t--)
{
long long n ;
long long i ;
cin >> n;
int f = 1;
long long t = sqrt(n) ;
if(t*t == n)
{
if(t&1)//t为奇数
{
printf("%lld 1\n",t);
}
else
{
printf("1 %lld\n",t);
}
}
else
{
n -= t*t;
if((t+1)&1)
{
if(t+1-n >= 0)
{

printf("%lld %lld\n",n,t+1);
}
else
{
printf("%lld %lld\n",t+1,t+1-(n-(t+1)));
}
}
else
{
if(t+1-n>=0)
{

printf("%lld %lld\n",t+1,n);
}
else
{
printf("%lld %lld\n",t+1-(n-(t+1)),t+1);
}
}
}
}
return 0;
}
原文地址:https://www.cnblogs.com/zsj576637357/p/2284622.html