一题自闭,掉大分。
A
注意只能后移不能前移即可。
B
之前学长讲过一维推广到二维的情况,赛时也回想到了,但是没想到曼哈顿距离也能推广。算是个结论吧。
一维:奇数取中位数,偶数取两个中位数之间的任何位置都可以。
AC代码:
/*
* @Author: hesorchen
* @Date: 2020-11-26 09:12:46
* @LastEditTime: 2021-02-19 15:31:36
* @Description: 栽种绝处的花
*/
#include
using namespace std;
int x[1010];
int y[1010];
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> x[i] >> y[i];
sort(x + 1, x + 1 + n);
sort(y + 1, y + 1 + n);
if (n & 1)
cout << 1 << endl;
else
cout << 1ll * (abs(x[n / 2] - x[n / 2 + 1]) + 1) * (abs(y[n / 2] - y[n / 2 + 1]) + 1) << endl;
}
return 0;
}
C2
交互题限制次数。1e5 20次,显然二分。
赛时炸了脑子不够清醒,在那码了删,删了码也不知道码了些啥,比赛一结束理了一下思路就知道正解了。
先查询一次[1,n],得到position
AC代码:
/*
* @Author: hesorchen
* @Date: 2020-11-26 09:12:46
* @LastEditTime: 2021-02-19 15:39:29
* @Description: 栽种绝处的花
*/
#include
using namespace std;
int main()
{
long long n;
cin >> n;
int pre = n, ans, flag = 1, res;
cout << "? " << 1 << ' ' << n << endl;
cout.flush();
cin >> pre;
if (n == 2)
{
int l = 1, r = 2;
cout << "? " << l << ' ' << r << endl;
cout.flush();
cin >> pre;
if (pre == l)
return cout << "! " << r << endl, 0;
else
return cout << "! " << l << endl, 0;
}
if (pre == 1) //情况1
{
int l = 2, r = n;
ans = n;
while (l <= r)
{
int mid = l + r >> 1;
cout << "? " << pre << ' ' << mid << endl;
cout.flush();
int temp;
cin >> temp;
if (temp != pre)
l = mid + 1;
else
{
r = mid - 1;
ans = mid;
}
}
}
else if (pre == n) //情况2
{
int l = 1, r = n - 1;
ans = 1;
while (l <= r)
{
int mid = l + r >> 1;
cout << "? " << mid << ' ' << pre << endl;
cout.flush();
int temp;
cin >> temp;
if (temp != pre)
r = mid - 1;
else
{
l = mid + 1;
ans = mid;
}
}
}
else //情况3
{
int l = 1, r = n;
int re1, re2;
cout << "? " << 1 << ' ' << pre << endl;
cout.flush();
cin >> re1;
if (re1 == pre) //类比情况2
{
int l = 1, r = pre - 1;
ans = 1;
while (l <= r)
{
int mid = l + r >> 1;
cout << "? " << mid << ' ' << pre << endl;
cout.flush();
int temp;
cin >> temp;
if (temp != pre)
r = mid - 1;
else
{
l = mid + 1;
ans = mid;
}
}
}
else //类比情况1
{
int l = pre + 1, r = n;
ans = r;
while (l <= r)
{
int mid = l + r >> 1;
cout << "? " << pre << ' ' << mid << endl;
cout.flush();
int temp;
cin >> temp;
if (temp != pre)
l = mid + 1;
else
{
r = mid - 1;
ans = mid;
}
}
}
}
cout << "! " << ans << endl;
return 0;
}
打比赛时头脑还是不够清醒,得改掉这个坏习惯。