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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
#include <iostream> #include <cstring> #include <algorithm> #include <queue> #include <map> #include <unordered_map> #include <string> #include <cmath> #include <set> #include <stack> #include <vector> #include <deque> #include <bitset> #include <cstdio> #include <iomanip>
#define ull unsigned long long #define ed '\n' #define fi first #define se second #define fore(i, l, r) for(int i = (int)(l); i <=(int)r; i++) #define debug(x) cout << "#x = " << x << ed; #define PI acos(-1) #define E exp(1) #define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); #define me0(st) memset(st, 0, sizeof st) #define me3f(st) memset(st, 0x3f, sizeof st) #define pdf(x) printf("%lf", double(x)) #define pif(x) printf("%d ", int(x)) #define scf(x) printf("%d", int(x)) #define re return 0
#define out(x, k) cout << fixed << setprecision(k) << x << ed
using namespace std;
typedef pair<int, int> PII; typedef long long LL; typedef double db;
LL n, m, x, q, g, s, st, len, width;
LL f(LL fk) { return (2 * (n + m) - 4 * fk) * fk; } void solve() { cin>>n>>m>>x; LL l = 1, r = min((n+1)/2,(m+1)/2); while(l < r) { LL mid = l + r >> 1; if(f(mid) >= x) r = mid; else l = mid + 1; }
s = f(r); q = r; st = s - (2*(n+m)+4-8*q) + 1; len = m - (q-1)*2; width = n - (q-1)*2;
if(st <= x && x <= st + len - 1) { cout << q << ' ' << q + x - st << '\n'; } else if(st+len-1<=x && x<=st+len+width-2) { cout<<q+x-(st+len-1)<<' '<<m-q+1<<ed; } else if(st+len+width-2<=x && x<=st+2*len+width-3) { cout<<n-q+1<<' '<<m-q+1-(x-(st+len+width-2))<<ed; } else if(st+2*len+width-3<=x && x<=st+2*len+2*width-5) { cout<<n-q+1-(x-(st+2*len+width-3))<<' '<<q<<ed; } }
int main() { IOS; int T = 1; cin >> T; while (T--) solve(); return 0; }
|