P4112DrawingPointsDivOne
二分
具有单调性,考虑二分答案
对于 考虑怎么 ,可以暴力的展开 次,再缩小 次,如果得到的结果和初始状态相同,那么就合法,否则不合法
// Author: xiaruize const int N = 1e3 + 10; int n; pii a[N]; bool s[N][N], cur[N][N], mp[N][N]; bool check(int x) { // debug(x); rep(i, 0, 799) { rep(j, 0, 799) { s[i][j] = false; } } rep(i, 1, n) { s[a[i].first + 400][a[i].second + 400] = true; } rep(asdasd, 1, x) { rep(i, 1, 799) { rep(j, 1, 799) { cur[i][j] = (s[i - 1][j - 1] | s[i - 1][j + 1] | s[i + 1][j - 1] | s[i + 1][j + 1]); } } rep(i, 1, 799) { rep(j, 1, 799) { s[i][j] = cur[i][j]; } } } rep(asdads, 1, x) { rep(i, 1, 799) { rep(j, 1, 799) { cur[i][j] = (s[i - 1][j - 1] & s[i - 1][j + 1] & s[i + 1][j - 1] & s[i + 1][j + 1]); } } rep(i, 1, 799) { rep(j, 1, 799) { s[i][j] = cur[i][j]; } } } rep(i, 1, 799) { rep(j, 1, 799) { if (s[i][j] && !mp[i][j]) return false; if (!s[i][j] && mp[i][j]) return false; } } return true; } void solve() { cin >> n; rep(i, 1, n) { cin >> a[i].first; a[i].first *= 2; } cin >> n; rep(i, 1, n) { cin >> a[i].second; a[i].second *= 2; mp[a[i].first + 400][a[i].second + 400] = true; } int l = 0, r = 141; while (l < r) { int mid = l + r + 1 >> 1; if (check(mid)) l = mid; else r = mid - 1; } if (l >= 140) { cout << "-1" << endl; return; } cout << l << endl; } #ifndef ONLINE_JUDGE bool end_of_memory_use; #endif signed main() { // freopen(".in","r",stdin); // freopen(".out","w",stdout); ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int testcase = 1; // cin >> testcase; while (testcase--) solve(); #ifndef ONLINE_JUDGE cerr << "Memory use:" << (&end_of_memory_use - &start_of_memory_use) / 1024.0 / 1024.0 << "MiB" << endl; cerr << "Time use:" << (double)clock() / CLOCKS_PER_SEC * 1000.0 << "ms" << endl; #endif return 0; }
本文作者:xiaruize's Blog
本文链接:https://www.cnblogs.com/xiaruize/p/18121246
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步