-
Notifications
You must be signed in to change notification settings - Fork 0
/
1913 달팽이.cpp
60 lines (51 loc) · 1.14 KB
/
1913 달팽이.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// 달팽이.cpp
// Baekjoon
//
// Created by KyungYoung Heo on 2017. 9. 29..
// Copyright © 2017년 KyungYoung Heo. All rights reserved.
//
#include <iostream>
#include <cstdio>
#include <queue>
#include <utility>
using namespace std;
vector <pair <int,int> > pos;
int main(void){
int ar[1000][1000],N,K;
int dir=1,num,cnt,i=-1,j=0;
cin>>N>>K; //입력
num=N*N;
pos.resize(N*N+1); //크기 재할당
cnt=N;
while (1) {
for(int m=0;m<cnt;m++){
i=i+dir;
ar[i][j]= num;
pos[num]=make_pair(i,j);
num--;
}
cnt--;
if(cnt<0) break;
for(int m=0;m<cnt;m++){
j=j+dir;
ar[i][j]=num;
pos[num]=make_pair(i,j);
num--;
}
dir*=-1;
}
for(int m=0;m<N;m++){
for(int n=0;n<N;n++){
printf("%d ",ar[m][n]);
}
printf("\n");
}
/*
for(int k=0;k<N*N;k++){
cout<<pos[k].first<<" "<<pos[k].second<<endl;
}
*/
cout<<pos[K].first+1<<" "<<pos[K].second+1;
return 0;
}