链接: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三种存储引擎总结

    MySQL三种存储引擎 MyISAM.InnoDB.MEMORY 1.MyISAM MyISAM,3.23.34a前的默认存储引擎. 优缺点 优点 在于占用空间小,处理速度快. 缺点 不支持事务的完整 ...

  2. OracleJDK与OpenJDK的区别和联系

    OpenJDK原是SunMicrosystems公司为Java平台构建的Java开发环境(JDK)的开源版本,完全自由,开放源码.OracleJDK里面包含的JVM是HotSpotVM,HotSpot ...

  3. .net core mvc项目部署nginx报错一直显示404错误

    遇到一个奇怪的问题,.net core mvc 项目部署到nginx上面,系统是linux,controller明明抛出500错误,但页面一直显示是404. 解决如下: 1.修改Startup.cs, ...

  4. NetBeans切换其他界面风格

    NetBeans是一款优秀的IDE,但是界面过亮,让我从使用以来就又爱又恨,经过一番摸索,测试出一款扩展软件 个人挺喜欢的分享出来 废话不多说下面教程: 1.安装NetBeans: 2.下载外观包ja ...

  5. Android 悬浮窗权限各机型各系统适配大全

    这篇博客主要介绍的是 Android 主流各种机型和各种版本的悬浮窗权限适配,但是由于碎片化的问题,所以在适配方面也无法做到完全的主流机型适配,这个需要大家的一起努力,这个博客的名字永远都是一个将来时 ...

  6. 《Unity預計算即時GI》笔记:二、光照图

    说明 这篇文章是对<Unity預計算即時GI>这个系列文章的笔记. 光照图 什么是光照图 光照图在第三章中有如下的定义,读起来很是费解. 一個光照圖(Chart)是表示一個光照貼圖的區域, ...

  7. Mybatis-Spring整合Spring

    因为 MyBatis 用 SqlSessionFactory 来创建 SqlSession ,SqlSessionFactoryBuilder 创建 SqlSessionFactory ,而在 Myb ...

  8. pat甲级1020中序后序求层序

    1020 Tree Traversals (25)(25 分) Suppose that all the keys in a binary tree are distinct positive int ...

  9. webpack最简单的入门教程里bundle.js之运行单步调试的原理解析

    读这篇文章的朋友,请确保对webpack有最基础的认识. 您可以阅读我前一篇文章:Webpack 10分钟入门 来在本地运行一个Webpack的hello world项目.https://www.to ...

  10. POJ 3421 X-factor Chains(构造)

    这条链依次乘一个因子.因为n<2^20,sqrt(n)分解因子,相同的因子相对顺序取一个. 组合公式计算一下就好. #include<cstdio> #include<iost ...