done 3 sorting problems
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// Number Spiral
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
using ll = long long;
|
||||
|
||||
int main() {
|
||||
int t; cin >> t;
|
||||
for (int i{}; i < t; i++) {
|
||||
ll x, y;
|
||||
cin >> y >> x;
|
||||
|
||||
if (y >= x) {
|
||||
ll yy = y * (y-1) + 1;
|
||||
if (y & 1) yy -= (y - x);
|
||||
else yy += (y - x);
|
||||
cout << yy << endl;
|
||||
} else {
|
||||
ll xx = x * (x - 1) + 1;
|
||||
if (x & 1) xx += (x - y);
|
||||
else xx -= (x - y);
|
||||
cout << xx << endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user