UVA 1468

Description

 

Mr. Kim is planning to open a new restaurant. His city is laid out as a grid with size MxM. Therefore, every road is horizontal or vertical and the horizontal roads (resp., the vertical roads) are numbered from 0 to M - 1. For profitability, all restaurants are located near road junctions. The city has two big apartments which are located on the same horizontal road. The figure below shows an example of a city map with size 11 x 11. A circle represents an existing restaurant and a circle labeled with `A' or `B' represents the location of an apartment. Notice that a restaurant is already located at each apartment. Each road junction is represented by the coordinate of the ordered pair of a vertical road and a horizontal road. The distance between two locations (x1y1) and (x2y2) is computed as | x1 - x2| + |y1 - y2|. In the figure below, the coordinates of A and B are (0, 5) and (10, 5), respectively.

Mr. Kim knows that the residents of the two apartments frequently have a meeting. So, he thinks that the best location of a new restaurant is halfway between two apartments. Considering lease expenses and existing restaurants, however, he can't select the optimal location unconditionally. Hence he decides to regard a location satisfying the following condition as a good place. Let dist(pq) be the distance between p and q.

A location p is a good place if for each existing restaurant's location qdist(pA) < dist(qA) or dist(pB) < dist(qB). In other words, p is not a good place if there exists an existing restaurant's location q such that dist(pA)dist(qA) and dist(pB)dist(qB).

In the above figure, the location (7, 4) is a good place. But the location p = (4, 6) is not good because there is no apartment which is closer to p than the restaurant at q = (3, 5), i.e., dist(pA) = 5dist(qA) = 3 and dist(pB) = 7dist(qB) = 7. Also, the location (0, 0) is not good due to the restaurant at (0, 5). Notice that the existing restaurants are positioned regardless of Mr. Kim's condition.

Given n locations of existing restaurants, write a program to compute the number of good places for a new restaurant.

Input

Your program is to read the input from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. Each test case starts with a line containing two integers M and n ( 2M60, 000 and 2n50, 000), which represent the size of a city map and the number of existing restaurants, respectively. The (i + 1)-th line of a test case contains two integers xi and yi (i = 1, 2,..., n and 0xiyi < M), which represents the coordinate of the i-th existing restaurant. Assume that all restaurants have distinct coordinates and that the two apartments A and B are positioned at the locations of 1-st restaurant and 2-nd restaurant. Notice that A and B are placed on the same horizontal line.

Output

Your program is to write to standard output. Print exactly one line for each test case. Print the number of good places which can be found in a given city map.

The following shows sample input and output for two test cases.

Sample Input

2
6 3
1 3
4 3
0 2
11 11
0 5
10 5
4 9
2 8
7 8
5 6
3 5
5 3
3 2
7 2
9 1

Sample Output

2
16 题意:
在一个m*m方格的地图上有n个餐馆,其中有最左和最右两个公寓a,b,公寓里面也有一个餐馆,现在你需要确定有多少个好位置,好位置的标准是没有其他的餐馆会比这个位置离a近同时也离b近
思路:
加入已经有一个餐馆(x,y),那么同x的其他点只要离a的y相对距离更近,那么这些点就是可行的,再考虑到已经存在的所有餐馆都会对你新选的地址造成影响,所以你可以假设位置,比如存在(x-1,y)那么你可以把它假定为存在一点f(x-1)+1是对右边造成的影响
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#define maxn 70000
using namespace std;
struct node
{
int x,y;
}a,b,c;
int h;
int f[maxn];
const int INF=1e9;
int main()
{
int m,n;
int T;
cin>>T;
while(T--)
{
fill(f,f+maxn,INF);
cin>>m>>n;
cin>>a.x>>a.y>>b.x>>b.y;
h=b.y;
for(int i=;i<n-;i++)
{
cin>>c.x>>c.y;
f[c.x]=min(f[c.x],abs(c.y-h));
}
f[a.x]=f[b.x]=;int ans=;
for(int i=a.x+;i<b.x;i++)
f[i]=min(f[i],f[i-]+);
for(int j=b.x-;j>a.x;j--)
f[j]=min(f[j],f[j+]+);
for(int k=a.x+;k<b.x;k++)
if(f[k]!=)
{
if(f[k]-<=h&&f[k]-<=m-h-) ans+=f[k]*-;
else
{
if(f[k]-<=h&&f[k]->=m-h-) ans+=f[k]+m-h-;
else
if(f[k]-<=m-h-&&f[k]->=h)
ans+=f[k]+h-;
else
ans+=m-;
}
ans++;
}
cout<<ans<<endl;
}
return ;
}

A - Restaurant的更多相关文章

  1. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  2. Flo's Restaurant[HDU1103]

    Flo's Restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. Codeforces Testing Round #12 B. Restaurant 贪心

    B. Restaurant Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem ...

  4. HDU-2368 Alfredo's Pizza Restaurant

    http://acm.hdu.edu.cn/status.php Alfredo's Pizza Restaurant Time Limit: 1000/1000 MS (Java/Others)   ...

  5. hdoj 4883 TIANKENG’s restaurant【贪心区间覆盖】

    TIANKENG’s restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/O ...

  6. hdu2368Alfredo's Pizza Restaurant

    Problem Description Traditionally after the Local Contest, judges and contestants go to their favour ...

  7. HDOJ 4883 TIANKENG’s restaurant

    称号: TIANKENG's restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Ja ...

  8. Restaurant

    Restaurant Time Limit:4000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit  ...

  9. 九校联考_24OI——餐馆restaurant

    凉心模拟D1T1--最简单的一道题 TAT 餐馆(restaurant) 题目背景 铜企鹅是企鹅餐馆的老板,他正在计划如何使得自己本年度收益增加. 题目描述 共有n 种食材,一份食材i 需要花ti 小 ...

  10. Codeforces828 A. Restaurant Tables

    A. Restaurant Tables time limit per test 1 second memory limit per test 256 megabytes input standard ...

随机推荐

  1. uva10870

    https://vjudge.net/problem/UVA-10870 裸的矩阵快速幂 注意系数矩阵在前面 因为系数矩阵为d*d 方程矩阵为d * 1 放反了就是d * 1 d * d 不符合矩阵乘 ...

  2. hdu1213 并查集不压缩

    题意:题意:一个人请人吃饭,相互认识的朋友在一张桌子,相互认识的朋友的意思是如果A认识B,B认识C,那么A.B.C是朋友,对于每组输入输出桌子的张数. Sample Input 2 5 3 1 2 2 ...

  3. Left Join 时筛选条件在on后与where后的区别

    a left join  b 时限制条件在on后, 相当于先筛选右连接表b的数据后,再进行数据连接.形成最终的集合. 这时不影响a表中相关字段的显示. SELECT T001W~WERKS, LGOR ...

  4. WEB前端学习

    第一日:软件的安装和下载 1.百度搜索推荐使用webStorm前端神器进行开发,傻瓜式安装不必多说! 激活 前提:修改本地的hosts配置文件(/etc/hosts) 最后一行新增这句话:0.0.0. ...

  5. 转载使用 ContentObsever 拦截短信,获取短信内容

    在一些应用上,比如手机银行,QQ,微信等,很多时候我们都需要通过发送验证码到手机上,然后把验证码填上去,然后才能成功地继续去做下面一步事情. 而如果每次我们都要离开当前界面,然后去查收短信,记住验证码 ...

  6. mybatis之多个对象自动装配问题

    因为业务的需要,所以我在一个方法中植入三个对象,但是mybatis并没有自动装配,结果并不是我想的那么美好,还是报错了.报错截图如下: <select id="GetOneBillPa ...

  7. springboot与dubbo整合入门(三种方式)

    Springboot与Dubbo整合三种方式详解 整合环境: jdk:8.0 dubbo:2.6.2 springboot:2.1.5 项目结构: 1.搭建项目环境: (1)创建父项目与三个子项目,创 ...

  8. 《CSS世界》学习笔记(一)

    <CSS世界>,张鑫旭著,人民邮电出版社,2017年12月第一版. 1.P9二维码链接文章的demo值得一看,可以实现有关“某些区域颜色始终保持一致”的效果. P9二维码所链接文章的一个d ...

  9. opencv3.31+vs2015终于配置成功了

    风萧萧兮易水寒, 熬了几个夜晚,终于把opencv配好了, 来图一 唉试了很多方法,终于成功. 教程和资料会发在个人网站里. 测试 代码 #include <iostream> #incl ...

  10. Angular——内置过滤器

    基本介绍 在AngularJS中使用过滤器格式化展示数据,在“{{}}”中使用“|”来调用过滤器,使用“:”传递参数. 基本使用 过滤器可以串起来使用,只要用   |  来衔接就行了,可以将上次返回的 ...