2018牛客多校训练----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
备注:
n*n矩阵中,边缘格子的车方向向内开,同时开且速度相同。有m个格子被损坏,车开到这上面也将被损坏,两车相撞也会被损坏。问在不损坏车辆的情况下,这个矩阵最多放多少辆车。
思路:
找规律,大胆猜测规律。
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+100;
bool vis1[N],vis2[N];
int main()
{
int n,m,i;
scanf("%d%d",&n,&m);
if(m==0)
{
printf("%d\n",(2*n-n%2));
return 0;
}
for(int i=1;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
vis1[x]=1;
vis2[y]=1;
}
int sum=0;
for(i=1;i<=n;i++)
{
if(!vis1[i])
sum++;
if(!vis2[i])
sum++;
}
if(n%2==1&&vis1[n/2+1]==0&&vis2[n/2+1]==0)
sum--;
printf("%d\n",sum);
return 0;
}
下一篇: mysql 新增、删除用户和权限分配
推荐阅读
-
2018牛客多校训练----car
-
2020牛客多校第二场 B.Boundary
-
F Fake Maxpooling(2020牛客暑期多校训练营(第二场))(单调队列)
-
2019牛客暑期多校训练营(第三场)F Planting Trees【单调队列】
-
2020牛客多校三 F. Fraction Construction Problem (扩展欧几里得)
-
2020牛客暑期多校训练营(第四场)H.Harder Gcd Problem
-
[2020牛客暑期多校训练营第三场] L.Problem L is the Only Lovely Problem 字符串函数
-
2020牛客多校联赛F题-Fake Maxpolling
-
2018暑期牛客网多校第二场签到题---思维(规律题)
-
牛客网暑期ACM多校训练营(第二场) I car