codechef FEB19 Manhattan Rectangle

Manhattan Rectangle

链接

题意:

  交互题,询问小于7次,确定一个矩形的位置,每次询问一个点到矩形的曼哈顿距离。

分析:

  询问三个顶点,然后解一下方程,求出一个边界,就好办了。

  用scanf和printf会TLE?

代码:

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;

const LL D = 1e9;

LL Ask(LL x,LL y) {
    LL z; 
    cout << "Q " << x << " " << y << "\n";
    cin >> z;
    fflush(stdout);
    return z;
}
void solve() {
    LL a = Ask(0ll, 0ll), b = Ask(D, 0ll), c = Ask(0ll, D);
    LL d = Ask((a - b + D) / 2, 0); // !!! 
    LL y0 = d, x0 = a - d, x1 = D - (b - d), y1 = D - (c - x0);
    cout << "A " << x0 << " " << y0 << " " << x1 << " " << y1 << "\n";
    int flag; 
    cin >> flag;
    fflush(stdout);
    if (flag < 0) exit(0);
}
int main() {
    int T ;
    cin >> T;
    for (; T --; solve()) ;
    return 0;
}

 

上一篇:vue项目中的防抖、节流


下一篇:nginx.conf配置文件中timeout超时时间设置