Skip to content

Instantly share code, notes, and snippets.

@riku179
Created October 31, 2020 09:02
Show Gist options
  • Save riku179/2c5df81966dd703eae3056ce88b8d539 to your computer and use it in GitHub Desktop.
Save riku179/2c5df81966dd703eae3056ce88b8d539 to your computer and use it in GitHub Desktop.
行列の斜め走査
#include <iostream>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
for (int s=0; s<N+M-1; s++) {
int i, j;
if (s < N) {
i=s, j=0;
} else {
i=N-1; j=s-i;
}
for (; i >= 0 && j < M; i--, j++) {
// here
cout << i << ' ' << j << endl;
}
}
}
@riku179
Copy link
Author

riku179 commented Oct 31, 2020

ex) N=4, M=5

0 0
1 0
0 1
2 0
1 1
0 2
3 0
2 1
1 2
0 3
3 1
2 2
1 3
0 4
3 2
2 3
1 4
3 3
2 4
3 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment