This commit is contained in:
Zengtudor 2025-02-15 15:44:14 +08:00
parent 891db6b7ca
commit fb65b9e085
2 changed files with 52 additions and 0 deletions

3
src/2/15/T178360.cpp Normal file
View File

@ -0,0 +1,3 @@
int main(){
}

49
src/2/15/T316692.cpp Normal file
View File

@ -0,0 +1,49 @@
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
vector<vector<int>> arr(n+1, vector<int>(m+1, -1));
int x = 0, y = 0;
int dx = 1, dy = 1;
int t = 0;
while (true){
t++;
x += dx;
y += dy;
if( (x == 0 || x == n) && (y == 0 || y == m)){
if(arr[x][y] == -1){
arr[x][y] = t;
}
break;
}
if(arr[x][y] == -1){
arr[x][y] = t;
}
if(x == 0 || x == n){
dx *= -1;
}
if(y == 0 || y == m){
dy *= -1;
}
}
while(q--){
int qx, qy;
cin >> qx >> qy;
if(qx <0 || qx >n || qy <0 || qy >m){
cout << "-1\n";
continue;
}
cout << arr[qx][qy] << "\n";
}
}