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 ...
随机推荐
- (转徐明吉)C#生成随机数
private static char[] constant = { ', 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p ...
- java克隆总结
对象clone,注意基本类型和指针类型.
- Topshelf
Topshelf允许开发者创建一个简单的控制台程序,将其安装为一个window服务. 这样做的原因很简单:方便调试. 使用命令行工具可以很方面的安装Topshelf创建的服务. server.exe ...
- ASP.NET中的SQL注入攻击与防护
什么是SQL注入攻击? 它是在执行SQL查询的时候,由于接收了用户的非法参数从而导致,所执行的SQL语义与业务逻辑原本所要查询的语义不相符,从而实现的攻击. 例如我们经常使用的用户登录,通常会出现这样 ...
- C#操作Office- Cannot find the interop type that matches the embedded interop type 'Microsoft.Office.Interop.Excel.Application'
网上说 2003 -> 11.0, 2007 -> 12.0. 因为平时提示"Are you missing an assembly reference?",都是没有引 ...
- start with connect by prior学习
这是oracle中的树查询,查询出来的数据会根据上下级组成树的结构.select * from mw_sys.mwt_pd_deps start with obj_id = '63EBEC8E-E76 ...
- swift 闭包 由浅入深 优化
//: Playground - noun: a place where people can play import UIKit ////////////////////////////////// ...
- token验证 sae
在微信平台中修改服务器设置时,使用微信Demo的php,刚开始一直验证token 失败 解决办法 :在echo $echoStr;之前添加header('content-type:text');一句这 ...
- mysql_config not found
在python中安装MySQL_python.不想通过下载源码编译,而是想用 easy_install MySQL_python 来安装.结果一直报错: mysql_config not found ...
- 按钮控件Button
钮窗口(控件)在MFC中使用CButton表示,CButton包含了三种样式的按钮,Push Button,Check Box,Radio Box.所以在利用CButton对象生成按钮窗口时需要指明按 ...