牛客多校第二场 I car (找规律)

链接:https://www.nowcoder.com/acm/contest/140/I
来源:牛客网
 

题目描述

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)

输入描述:

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.

输出描述:

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

示例1

输入

复制

2 0

输出

复制

4

看错题目,一开始以为中间也能放车,想到头都炸了还是不会233333

果然太久没做题还是菜啊......

如果没有障碍,每行最多一个,每列最多一个,然后如果n为奇数的时候,(n+1)/2的行跟列是不能放一起的。

对于每个禁止区域(x,y),把对应的车去掉就可以了

#include <bits/stdc++.h>
#define fir first
#define se second
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
const int maxn=1e5+10;
const int maxm=1e6+10;
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const double eps=1e-7;
int n,m;
int vis[maxn],vis1[maxn];
int main(){
    cin>>n>>m;
    int ans=0;
    for (int i=1;i<=m;i++){
        int x,y;
        cin>>x>>y;
        if (vis[x]==0){
            ans--;
            vis[x]=1;
        }
        if (vis1[y]==0){
            ans--;
            vis1[y]=1;
        }
    }
    if (n%2==1){
        if (vis[(n+1)/2]==0&&vis1[(n+1)/2]==0){
            ans--;
        }
    }
    cout<<ans+2*n<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/wyj_alone_smile/article/details/81149682
今日推荐