记录编号 |
122221 |
评测结果 |
AAAAAAAAAA |
题目名称 |
螺旋方阵 |
最终得分 |
100 |
用户昵称 |
HouJikan |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.003 s |
提交时间 |
2014-09-22 20:31:46 |
内存使用 |
0.31 MiB |
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <iterator>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint;
const int INF=0x7ffffff;
//==============struct declaration==============
//==============var declaration=================
const int MAXN=40000;
#define round Round
int n,m,round,num,t,r,c;
//==============function declaration============
int sqr(int x){return x*x;}
//==============main code=======================
int main()
{
string FileName="spiral";//程序名
string FloderName="COGS";//文件夹名
freopen((FileName+".in").c_str(),"r",stdin);
freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG
system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
clock_t Start_Time=clock();
#endif
scanf("%d",&t);
while (t--)
{
scanf("%d%d",&n,&m);
round=1;
while (sqr(round*2-1)<m)
round++;
r=n/2+3-round;c=n/2+round;num=sqr(2*(round-1)-1)+1;
if (num+2*Round-3<m)
r+=2*round-3,num+=2*round-3;
else
{
printf("%d %d\n",r+m-num,c);
continue;
}
if (num+2*Round-2<m)
c-=2*round-2,num+=2*round-2;
else
{
printf("%d %d\n",r,c-m+num);
continue;
}
if (num+2*Round-2<m)
r-=2*round-2,num+=2*round-2;
else
{
pritnf("%d %d\n",r-m+num,c);
continue;
}
printf("%d %d\n",r,c+m-num);
}
#ifdef DEBUG
clock_t End_Time=clock();
printf("\n\nTime Used: %.4lf Ms\n",double(End_Time-Start_Time)/CLOCKS_PER_SEC);
#endif
return 0;
}
//================fuction code====================