I - car(思维题)

White Cloud has a square of n×n from (1,1) to (n,n).

White Rabbit wants to put in several cars. Each car will start moving at the same time and move from one side of one row or one line to the other. All cars have the same speed. If two cars arrive at the same time and the same position in a grid or meet in a straight line, both cars will be damaged.

White Cloud will destroy the square m times. In each step White Cloud will destroy one grid of the square(It will break all m grids before cars start).Any car will break when it enters a damaged grid.

White Rabbit wants to know the maximum number of cars that can be put into to ensure that there is a way that allows all cars to perform their entire journey without damage.

(update: all cars should start at the edge of the square and go towards another side, cars which start at the corner can choose either of the two directions)

For example, in a 5×5 square
在这里插入图片描述

legal

在这里插入图片描述

illegal (These two cars will collide at (4,4))

在这里插入图片描述

illegal (One car will go into a damaged grid)

Input
The first line of input contains two integers n and m(n≤100000,m≤100000)
For the next m lines,each line contains two integers x,y(1≤x,y≤n), denoting the grid which is damaged by White Cloud.

Output
Print a number,denoting the maximum number of cars White Rabbit can put into.

Example
Input
2 0
Output
4
Note
在这里插入图片描述
由note的图片提示可知,当没危险地区时的最大车辆为2*n
每次减去危险地区两个方向不能放的车辆数就行
最后注意一下n为奇数时,矩阵中间十字线,只能放一辆车,需要再减去1

#include <bits/stdc++.h>
using namespace std;
int l[100100],r[100100],x,y,ans=0;
int main() 
{
    int n,m,x,y;
    scanf("%d%d",&n,&m);
    ans=2*n;
    while(m--)
    {
    	cin>>x>>y;
    	if(!l[x]) l[x]=1,ans--;
    	if(!r[y]) r[y]=1,ans--; 
	}
	if((n&1)&&!(l[n/2+1]||r[n/2+1])) ans--;
    printf("%d",ans);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值