Codeforces Gym 100825 B. Delete This! (枚举 + 三分)
来源:互联网 发布:淘宝卖家后台官网 编辑:程序博客网 时间:2024/06/05 06:20
Problem
对于给定的若干需删除的桌面图标坐标及不应删除的桌面图标坐标(均为左上角点坐标),求最少图标移动个数,使得可以通过一个矩形框将所有应删除图标选中,同时不能包括应保留的图标(矩形框的范围不能超过桌面坐标)。
限制条件
桌面大小
应删除图标 n 个,保留图标 m 个,
每个图标的大小为
解题思路
提前将超出桌面边界的应删除图标标记,并直接作为必须移动的。
对其余图标进行预处理出二维前缀和(分应删除和不应删除的)。
枚举矩形框上边界、左边界、右边界,三分处理下边界的位置使得移动个数最少。
代码
#include<bits/stdc++.h>using namespace std;const int N = 100 + 10;int nr, nc, n, m, x[N], y[N], nx, ny, delta;int mb[N][N], mw[N][N];int l, r, u, ans = N;set<int> sx, sy;struct Node { int x, y;} b[110], w[110];int calc(int d) { int outBlack = n - (mb[r][u] - mb[r][d-1] - mb[l-1][u] + mb[l-1][d-1]); int inWhite = mw[r][u] - mw[r][d-1] - mw[l-1][u] + mw[l-1][d-1]; ans = min(ans, outBlack+inWhite); return outBlack + inWhite;} int solve(int maxU) { int L = 1, R = maxU+1, mid, midmid, midv, midmidv; while(L < R) { mid = (L+R) / 2; midmid = (mid + R) / 2; midv = calc(mid); midmidv = calc(midmid); if(midv <= midmidv) R = midmid; else L = mid; } return L;}int main(){ scanf("%d %d %d %d", &nr, &nc, &n, &m); for(int i=1;i<=n;i++) { scanf("%d %d", &b[i].y, &b[i].x); if(b[i].x > nc - 4 || b[i].y > nr - 8) delta++, i--, n--; sx.insert(b[i].x); sy.insert(b[i].y); } for(int i=1;i<=m;i++) { scanf("%d %d", &w[i].y, &w[i].x); sx.insert(w[i].x); sy.insert(w[i].y); } for(set<int>::iterator it=sx.begin();it!=sx.end();it++) x[++nx] = *it; for(set<int>::iterator it=sy.begin();it!=sy.end();it++) y[++ny] = *it; x[nx+1] = nr; y[ny+1] = nc; for(int i=1;i<=n;i++) mb[lower_bound(x+1, x+nx+1, b[i].x) - x][lower_bound(y+1, y+ny+1, b[i].y) - y]++; for(int i=1;i<=m;i++) mw[lower_bound(x+1, x+nx+1, w[i].x) - x][lower_bound(y+1, y+ny+1, w[i].y) - y]++; for(int i=1;i<=nx;i++) { for(int j=1;j<=ny;j++) mb[i][j] += mb[i][j-1] + mb[i-1][j] - mb[i-1][j-1], mw[i][j] += mw[i][j-1] + mw[i-1][j] - mw[i-1][j-1]; } for(l=1;l<=nx;l++) for(r=l;r<=nx;r++) for(u=1;u<=ny;u++) solve(u); printf("%d\n", ans+delta);}
阅读全文
0 0
- Codeforces Gym 100825 B. Delete This! (枚举 + 三分)
- Gym 100206B Fire station building(三分)
- CodeForces Gym 100114B
- CodeForces Gym 100735B
- Codeforces GYM 100726B
- codeforces GYM 101431B (STL)
- Codeforces Round #403 (Div. 2) B 二分 or 三分
- Codeforces Gym 101061 B RGB plants(矩阵快速幂)
- Codeforces Gym 100187 B A Lot of Joy(期望)
- Codeforces Gym 101158 B. Quality of Check Digits (模拟)
- [枚举+三分] Codeforces #626E. Simple Skewness
- CodeForces Gym 100989B LCS (B)
- Codeforces Gym 100623B Problem B. Billboard
- GYM 100971 F.Two Points(三分)
- Codeforces Gym 100342J Triatrip Bitset+枚举
- CodeForces 589B Layer Cake(枚举)
- CodeForces 707B Bakery(建图 + 枚举)
- 枚举 codeforces 452B
- Degug: QmlApplicationEngine failed to load component
- java动态传参调用python脚本
- Python中struct.pack()和struct.unpack()用法详细说明
- AFNetworking 请求参数中含有二进制图片信息
- 深入解析MVP怎么玩,接口抽取深入解析
- Codeforces Gym 100825 B. Delete This! (枚举 + 三分)
- 微信小程序开发(6)---用户拒绝授权,重新调起授权
- express框架的注册登陆
- Cannot read property 'length' of undefined
- 移动开发UI工具包Xamarin.Forms v2.3.5-pre6发布
- 英伟达CUVID硬解,并通过FFmpeg读取文件
- NOIP2015 Day 1 T3 斗地主
- Activity以singleTask模式启动,intent传值的解决办法
- LeetCode