#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<string>
#include<unordered_set>
#include<map>
#define p pair<int,int>
#define P pair<int,p>
using namespace std;
int a[30][30];
int dx[4] = { -1,0,0,1 }, dy[4] = { 0,-1,1,0 };
P S[900];
void gyaku(int x,int y){
for (int i = 0;i<4;i++) {
int n = x + dx[i], m = y + dy[i];
if (n >= 0 && n < 30 && m >= 0 && m < 30 && a[n][m]!=0 && a[n][m] == a[x][y]+1) {
gyaku(n,m);
break;
}
}
printf("%d %d\n", x+1, y+1);
a[x][y]--;
}
bool T;
void DFS(int x, int y) {
if(T){printf("%d %d\n", x+1, y+1);a[x][y]--;}
T=true;
for (int i =0;i<4;i++) {
int n = x + dx[i], m = y + dy[i];
if (n >= 0 && n < 30 && m >= 0 && m < 30 && a[n][m]!=0 && a[n][m] == a[x][y]) {
DFS(n, m);
break;
}
}
}
signed main(){
for (int b = 0; b < 30; b++) {
for (int c = 0; c < 30; c++) {
scanf("%d", &a[b][c]);
S[b*30+c]=P(a[b][c],p(b,c));
}
}
sort(S,S+900,greater<P>());
for(int i=0;i<900;i++){
int n=S[i].second.first,m=S[i].second.second;
while(a[n][m]){
gyaku(n,m);
T=false;
DFS(n,m);
}
}
}
./Main.cpp: In function ‘int main()’:
./Main.cpp:41:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[b][c]);
^