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 ...
随机推荐
- poj 3660 Cow Contest (传递闭包)
/* floyd 传递闭包 开始Floyd 之后统计每个点能到的或能到这个点的 也就是他能和几个人确定胜负关系 第一批要有n-1个 然后每次减掉上一批的人数 麻烦的很 复杂度上天了.... 正难则反 ...
- ASP.NET页面周期
上图为ASP.NET页面生命周期图. 以下详细讲解一下ASP.NET的页面生命周期. 请求页 请求页发生在页生命周期之前.用户请求时,ASP.NET将确定是否需要分析和编译页面,或者是否可以在不运 ...
- ASP.NET 页面间数据传递的方法
在做WEB开发时,很多地方会涉及到页面间的数据传递.这几天在完善教务基础系统,遇到了这个问题,上网查了一些资料,现总结如下: 说到页面间数据传递,很多人都会想到通过像Session这样的全局变量,但是 ...
- JavaScript 之 使用 XMLHttpRequest 上传文件
<div id="div1"> <input type="file" id="uploadfile" style=&quo ...
- ajax+FormData+javascript 实现无刷新上传附件
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- 一些SQL语句的问题
1.getdate()函数问题 go create table table_1( id int primary key identity, name ) not null, daytime datet ...
- Vigenère Cipher 维吉尼亚加解密算法
维吉尼亚的加解密有两种方法. 第一种是查表:第一行为明文,第一列为密钥,剩余的为对应的密文 第二种方法是转化计算法:逐个将字符转化为从零开始的数字,对数字进行加密/解密后,再转化为字符. 本文要用c+ ...
- Java语言实现简单FTP软件------>FTP软件本地窗口的实现(五)
1.首先看一下本地窗口的布局效果 2.看一下本地窗口实现的代码框架 2.本地窗口的具体实现代码LocalPanel.java package com.oyp.ftp.panel.local; impo ...
- Oracle数据库之数据类型
Oracle数据库之数据类型 Oracle基本数据类型(亦叫内置数据类型,internal datatypes或built-in datatypes)可以按类型分为:字符串类型.数字类型.日期类型.L ...
- MFC自创建类了解
CxxxxView 视窗类 所有的按键 等消息都先在这里响应 CxxxxDoc 文档类 CMainFrame 框架类 CxxxxApp 应用程序类 CxxxxView类中的 OnDraw函数 在窗口改 ...