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 ...
随机推荐
- CSS 命名规则
CSS书写顺序: 位置属性(position, top, right, z-index,display, float等) 大小(width, height, padding, margin) 文字系列 ...
- [php基础]Mysql日期函数:日期时间格式转换函数详解
在PHP网站开发中,Mysql数据库设计中日期时间字段必不可少,由于Mysql日期函数输出的日期格式与PHP日期函数之间的日期格式兼容性不够,这就需要根据网站实际情况使用Mysql或PHP日期转换函数 ...
- IIS应用程序池数目
今天突然遇到一个问题,访问线上站点,数据处理过之后,访问页面有时是404,有时不是404,而404页面刷新几次之后就正常了. 经过大神们指点之后,发现竟然是应用程序池惹的祸. 分析下原因,在代码里面数 ...
- 用 CALayer 定制下载进度条控件
// // RPProgressView.h // CALayer定制下载进度条控件 // // Created by RinpeChen on 16/1/2. // Copyright © 2016 ...
- CHAR数组转成STRING:C++
有些时候,键入了CHAR数组却不会知道到底有多长,是不是很差评呢?但是,转成STRING就可以啦QWQ #include <iostream> #include <cstdio> ...
- uva 482 - Permutation Arrays
<int, double> --> <int, string> 从而避免了输出格式: #include <vector> #include <strin ...
- Oracle数据库之序列
Oracle数据库之序列(sequence) 序列是一个计数器,它并不会与特定的表关联.我们可以通过创建Oracle序列和触发器实现表的主键自增.序列的用途一般用来填充主键和计数. 一.创建序列 语法 ...
- 使用 HTML5 设计辅助功能
使用 HTML5 设计辅助功能 Rajesh Lal 下载代码示例 如果您真的对面向广大受众感兴趣,将需要为网站设计辅助功能. 辅助功能使网页更易于访问.更易于使用,可供每个人浏览. 通常,使用最新的 ...
- 兄弟连面试宝典php
学历这个事情是企业招聘经常设置的一道门槛,我们不能说学历高就能力高,也不能说学历低能力就差,那如何辩证回答这个问题呢?回答提示:学历不一定完全代表能力,虽然我的学历不够硬但是我会在技术上更努力更认真, ...
- scss组件定制的一些学习
应组织上的要求,简化前端开发,提高工作效率,开始着手研究scss框架及组件化. 把一些长的像的弄在一起,就有了组件化. 但组件只用一部分需要的,就有了定制. 下面是参考一个button组件写出的一些简 ...