链接: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.

输入例子:
2 0
输出例子:
4

-->

示例1

输入

复制

2 0

输出

复制

4

备注:

 题解

  如果没有被破坏的点 ans=n*2-(n%2);
  如果有则减去相应的被破坏的行和列,但是奇数行的最中间的那个只影响一个,(此处可以考虑n==3的,最中间的点之影响一个车的填入)
 #include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+;
int a[MAXN],b[MAXN];
int main()
{
int ans=;
int n,m;
scanf("%d%d",&n,&m);
int x,y;
ans=n*-(n%);
for(int i=;i<m;i++)
{
scanf("%d%d",&x,&y);
a[x]=;
b[y]=;
}
int k1=,k2=;
for(int i=;i<n;i++)
{
if(a[i]== ) ans--;
if(b[i]==) ans--;
}
if(n%==&&a[(n+)/]==&&b[(n+)/]==) ans++;
printf("%d\n",ans);
return ;
}

牛课第二次多校I的更多相关文章

  1. 【C语言探索之旅】 第一部分第四课第二章:变量的世界之变量声明

    内容简介 1.课程大纲 2.第一部分第四课第二章:变量的世界之变量声明 3.第一部分第四课第三章预告:变量的世界之显示变量内容 课程大纲 我们的课程分为四大部分,每一个部分结束后都会有练习题,并会公布 ...

  2. 2018牛客暑期ACM多校训练营第二场(有坑未填)

    第二场终于等来学弟 开始(被队友带飞)的开心(被虐)多校之旅 A   run A题是一个递推(dp?)+前缀和 因为看数据量比较大 就直接上前缀和了 一个比较简单的递推 没有太多难点 签到题 需要注意 ...

  3. (原)2018牛课多校第4场--G

    传送门 /* 按值从大到小排序,记录下相应出现的次数并去重 枚举:从大到小枚举,如果能够通过删除其他数让当前这个数成为众数,则循环结束,输出此数,如果循环结束也没答案,输出-1 优先级:值优先 举例: ...

  4. 牛客第二场Dmoney

    链接:https://www.nowcoder.com/acm/contest/140/D 来源:牛客网 题目描述 White Cloud has built n stores numbered to ...

  5. 牛客第二场A-run

    链接:https://www.nowcoder.com/acm/contest/140/A 来源:牛客网 White Cloud is exercising in the playground. Wh ...

  6. cousera 吴恩达 深度学习 第一课 第二周 作业 过拟合的表现

    上图是课上的编程作业运行10000次迭代后,输出每一百次迭代 训练准确度和测试准确度的走势图,可以看到在600代左右测试准确度为最大的,74%左右, 然后掉到70%左右,再掉到68%左右,然后升到70 ...

  7. 牛客暑期ACM多校 第七场

    链接:https://www.nowcoder.com/acm/contest/145/C来源:牛客网 C .题目描述 A binary string s of length N = 2n is gi ...

  8. 2019牛客网暑假多校训练第四场 K —number

    链接:https://ac.nowcoder.com/acm/contest/884/K来源:牛客网 题目描述 300iq loves numbers who are multiple of 300. ...

  9. CODING 敏捷实战系列课第二讲:Scrum 敏捷项目管理核心要素之 3355

    Scrum 是敏捷开发流派中最著名和最落地的一支,全球 70% 以上公司的敏捷转型都是以 Scrum 起步.CODING 特邀敏捷顾问.CST & CTC 认证敏捷教练申健老师将在本课程< ...

随机推荐

  1. Mysql 如何设置字段自动获取当前时间,附带添加字段和修改字段的例子

    --添加CreateTime 设置默认时间 CURRENT_TIMESTAMP  ALTER TABLE `table_name`ADD COLUMN  `CreateTime` datetime N ...

  2. 在Controller方法执行之前进行捕获请求,进行类型的转换

    @ExceptionHandler(TypeMismatchException.class) public ModelAndView ParseException(Excetion ex,HttpSe ...

  3. 一个关于document.write()的问题

    Index.html中: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> ...

  4. Java集合框架—Map

    Map集合:该集合存储键值对.一对一对往里存.而且要保证键的唯一性. 1,添加. put(K key, V value)  putAll(Map<? extends K,? extends V& ...

  5. Compaq Visual Fortran生成静态库的方法及使用

    Compaq Visual Fortran 6.5生成lib静态库详细方法: 打开Compaq Visual Fortran,新建Fortran Static Library工程,命名为ForLib: ...

  6. fish 与oh-my-fish 的安装

    fish 相对于 自带的shell优势很大,最近在研究使用中. 安装教程如下: sudo apt-get install fish oh-my-fish是github上开源项目,使得fish的使用更加 ...

  7. Masonry 等间隔或等宽高排列多个控件

    - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typica ...

  8. 爬虫基础-http请求的基础知识

    百度百科上这么介绍爬虫: 网络爬虫(又被称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种按照一定的规则,自动地抓取万维网信息的程序或者脚本. 在开发爬虫时常用的工具:ch ...

  9. gitlab用户添加ssh免密钥认证后clone还是要求输入密码

    今天在centos 7公网服务器上安装gitlab在配置ssh免密钥时遇到一个奇怪的事,正确添加了本机的公钥到gitlab账户上,进行clone时死活都要你输入密码gitlab使用yum安装的,之前在 ...

  10. 关于dependencies和devDependencies的理解

    npm install 会下载dependencies和devDependencies中的模块,当使用npm install --production或者注明NODE_ENV变量值为productio ...