栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3133 Grid Panel

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3133 Grid Panel

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <vector>using namespace std;typedef long long LL;const LL INF = 1000000007LL*1000000007LL;struct Pt{ int x, y; Pt(int _x, int _y): x(_x), y(_y){} Pt(){}};vector<Pt> vec;int n, w, h;const int maxn = 50005;LL m1[maxn], mv1[maxn], m2[maxn], mv2[maxn];LL cal(){ memset(m1, -1, sizeof(m1)); memset(m2, -1, sizeof(m2)); for(int i = 0; i < (int)vec.size(); i ++){ m1[vec[i].x] = max(m1[vec[i].x], (LL)vec[i].y); m2[vec[i].x] = max(m2[vec[i].x], (LL)h-1-vec[i].y); } memcpy(mv1, m1, sizeof(m1)); memcpy(mv2, m2, sizeof(m2)); for(int i = 1; i < w; i ++){ m1[i] = max(m1[i], m1[i-1]); m2[i] = max(m2[i], m2[i-1]); } for(int i = w-2; i >= 0; i --){ mv1[i] = max(mv1[i], mv1[i+1]); mv2[i] = max(mv2[i], mv2[i+1]); } for(int i = 0; i < w; i ++){ if(m2[i] == -1) m2[i] = h-1; if(mv2[i] == -1) mv2[i] = h-1; m1[i] ++; m2[i] ++; mv1[i] ++; mv2[i] ++; } for(int i = 1; i < w; i ++){ m1[i] += m1[i-1]; m2[i] += m2[i-1]; } for(int i = w-2; i >= 0; i --){ mv1[i] += mv1[i+1]; mv2[i] += mv2[i+1]; } LL ret = INF; for(int i = 0; i < w; i ++){ LL tmp = h*2; if(i != 0) tmp += m1[i-1] + m2[i-1]; if(i != w-1) tmp += mv1[i+1] + mv2[i+1]; ret = min(ret, tmp); } return ret - (LL)w*h;}int main() { int test; scanf("%d", &test); while(test --){ scanf("%d%d%d", &w, &h, &n); vec.clear(); for(int i = 0; i < n; i ++){ int x, y; scanf("%d%d", &x, &y); if(x != 0 && y != 0) vec.push_back(Pt(x-1, y-1)); if(x != w && y != h) vec.push_back(Pt(x, y)); if(x != w && y != 0) vec.push_back(Pt(x, y-1)); if(x != 0 && y != h) vec.push_back(Pt(x-1, y)); } LL ans = cal(); swap(w, h); for(int i = 0; i < (int)vec.size(); i ++) swap(vec[i].x, vec[i].y); ans = min(ans, cal()); cout << ans << endl; } return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/375035.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号