uvalive 4851 Restaurant(扫描法)
题意:有一个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();
}
}
uvalive 4851 Restaurant(扫描法)的更多相关文章
- UVALive - 6872 Restaurant Ratings 数位dp
题目链接: http://acm.hust.edu.cn/vjudge/problem/113727 Restaurant Ratings Time Limit: 3000MS 题意 给你一个长度为n ...
- UVALive 3716 DNA Regions ——(扫描法)
乍一看这个问题似乎是很复杂,但其实很好解决. 先处理出每个点到原点的距离和到x正半轴的角度(从x正半轴逆时针旋转的角度).然后以后者进行排序. 枚举每一个点到圆心的距离,作为半径,并找出其他到圆心距离 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- 【BZOJ-1670】Building the Moat护城河的挖掘 Graham扫描法 + 凸包
1670: [Usaco2006 Oct]Building the Moat护城河的挖掘 Time Limit: 3 Sec Memory Limit: 64 MBSubmit: 464 Solv ...
- 计算几何 : 凸包学习笔记 --- Graham 扫描法
凸包 (只针对二维平面内的凸包) 一.定义 简单的说,在一个二维平面内有n个点的集合S,现在要你选择一个点集C,C中的点构成一个凸多边形G,使得S集合的所有点要么在G内,要么在G上,并且保证这个凸多边 ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
随机推荐
- Java类与类之间关系总结
继承,依赖,关联,聚合,组合 一般来说依赖和关联是类似的,关联是强依赖,聚合和组合是一类,组合属于强聚合. 继承:一般是子类和父类之间的关系,关键字extends 依赖:可以这样记忆,做某件事必须要依 ...
- Asp.Net Mvc MapRoute .html不起作用(转)
RegisterRoutes 注册路由示例配置: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRo ...
- 将图片转换为Base64
string Imagefilename 硬盘路径 protected string ImgToBase64String(string Imagefilename) { try { Bitmap ...
- java数据库连接类,已经把数据库操作的方法都封装好了
在这里分享一个已经封装好了的java数据库连接类,只要创建对象就可以实现数据库的增删改查操作,用过都说好.其实这个不是我自己写的,是一个理解和学习能力超高的朋友写的,他也很乐于分享交流,本人也深受他的 ...
- A Bug's Life(hdu1829种类并查集)
题意:有一群虫子,现在给你一些关系,判断这些关心有没有错 思路:向量种类并查集,下面讲一下向量的种类并查集 本题的各个集合的关心有两种0同性,1异性,怎么判断有错, 1.先判断他们是否在一个集合,即父 ...
- phpcms v9二次开发之模型类的应用(2)
二.模型操作方法select()--查询语句 //查询级别管理列表信息 public function levellists() { $lelists = $this->l ...
- 新写PHP HTTP断点续传类文件代码
一个支持断点续传的PHP文件下载类文件,调用方法简单,类代码简洁,可记忆上次的下载的节点,实现累积下载,类名称download,类代码如下: function download($path,$file ...
- 【结构型】Adapter模式
Adapter模式主要意图是将类或接口转换成客户期望的接口,从而使得原本不兼容.无法在一起工作的接口可以在一起工作.该模式有两种形式的Adapter法,一是继承方式:二是对象关联依赖方式. 继承方式A ...
- Python实现类似switch...case功能
最近在使用Python单元测试框架构思自动化测试,在不段的重构与修改中,发现了大量的if...else之类的语法,有没有什么好的方式使Python具有C/C#/JAVA等的switch功能呢? 在不断 ...
- iPhone开发:Objective C 代码规范-iOS总结版
一,关于空行 A:.h中的空行 1,文件说明与头文件包涵(#import)之间空1行 2,头文件包涵(#import)之间,如果需要分类区别,各类别之间空1行 3,头文件包涵(#import)与@cl ...