题意:有一个M*M的网格,坐标[0...M-1,0...M-1] 网格里面有两个y坐标同样的宾馆A和B。以及n个餐厅,宾馆AB里面各有一个餐厅,编号1,2,其它餐厅编号3-n。如今你打算新开一家餐厅。须要考察一下可能的位置。一个位置p是“好位置”的条件是:当且仅当对于已有的每一个餐厅q。要么p比q离A近。要么p比q离B近。即dist(p,A) < dist(q,A) 或者 dist(p,B) < dist(q,B)  问“好位置”的个数

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#define eps 1e-6
#define LL long long
using namespace std; const int maxn = 50000 + 50;
const int maxm = 60000 + 50;
const int INF = 0x3f3f3f3f;
int borderl[maxm], borderr[maxm], rest[maxm];
int m, n, begx, endx, level;//begx。endx记录ab的横坐标 void init() {
memset(rest, -1, sizeof(rest));
cin >> m >> n;
int tx, ty;
cin >> tx >> ty; rest[tx] = ty; begx = tx;
cin >> tx >> ty; rest[tx] = ty; endx = tx;
if(begx > endx) swap(begx, endx);
level = ty;
for(int i = 3; i <= n; i++) {
cin >> tx >> ty;
if(ty < level) ty = 2*level - ty;
if(rest[tx] != -1) rest[tx] = min(rest[tx], ty);
else rest[tx] = ty;
}
} void solve() {
int ans = 0;
borderl[begx] = borderl[endx] = level;
borderr[begx] = borderr[endx] = level;
for(int i = begx + 1; i < endx; i++) {
if(rest[i] != -1) {
borderl[i] = min(borderl[i-1]+1, rest[i]);
}
else {
borderl[i] = borderl[i-1] + 1;
}
}
for(int i = endx - 1; i > begx; i--) {
if(rest[i] != -1) {
borderr[i] = min(borderr[i+1]+1, rest[i]);
}
else {
borderr[i] = borderr[i+1] + 1;
}
}
for(int i = begx + 1; i < endx; i++)
ans += max(0, min(min(borderl[i], borderr[i]), m)-max(max(2*level-borderl[i], 2*level-borderr[i]), -1)-1);
cout << ans << endl;
// for(int i = begx + 1; i < endx; i++) cout << min(borderl[i], borderr[i]) << " " << rest[i] << endl;
} int main() {
//freopen("input.txt", "r", stdin);
int t; cin >> t;
while(t--) {
init();
solve();
}
}


最新文章

  1. 轻松搞懂WebService工作原理
  2. qt 单文档程序关闭时在delete ui处出现segmentation fault
  3. MySQL数据库一个字段对应多个值得模糊查询
  4. acm算法模板(1)
  5. 20145129 《Java程序设计》第1周学习总结
  6. Keil &#181;Vision4 中出现中文乱码的解决办法
  7. TCP与UDP区别
  8. 混合使用Azure LB和ILB访问相同web服务(2)
  9. Train Problem II(卡特兰数+大数乘除)
  10. 几分钟看完 flow.ci 全部功能
  11. c#获取数组中最大的元素
  12. alert执行顺序
  13. sql中检查时间是否重叠
  14. 【搬运】 Page Object 官方文档 (新增了Widget特性)
  15. Day9--Python--函数入门
  16. 修改host文件——mac
  17. 自动化工具之三:pywinauto
  18. python实现简单的聊天小程序
  19. hashlib(摘要算法的模块)--重要 (一)
  20. 秋色园QBlog技术原理解析:性能优化篇:缓存总有失效时,构造持续的缓存方案(十四)

热门文章

  1. TextView过长显示省略号, TextView文字中间加横线
  2. IPTV中的EPG前端优化
  3. JavaScript 显示弹出窗口(二)
  4. JavaScript 显示弹出窗口
  5. 【转】Qt之模型/视图
  6. 在linux下用tomcat部署java web项目的过程与注意事项(转)
  7. php 基于phpexcel制作的导出excel类
  8. DbContext的命名空间
  9. Today&#39;s interview of C#
  10. NSSet和NSMutableSet 确保数据的唯一性--备