codeforces_333B_水过
1 second
256 megabytes
standard input
standard output
Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for n - 1 minutes, Gerald every minute moves each chip into an adjacent cell. He moves each chip from its original edge to the opposite edge. Gerald loses in this game in each of the three cases:
- At least one of the chips at least once fell to the banned cell.
- At least once two chips were on the same cell.
- At least once two chips swapped in a minute (for example, if you stand two chips on two opposite border cells of a row with even length, this situation happens in the middle of the row).
In that case he loses and earns 0 points. When nothing like that happened, he wins and earns the number of points equal to the number of chips he managed to put on the board. Help Gerald earn the most points.
The first line contains two space-separated integers n and m (2 ≤ n ≤ 1000, 0 ≤ m ≤ 105) — the size of the field and the number of banned cells. Next m lines each contain two space-separated integers. Specifically, the i-th of these lines contains numbers xi and yi(1 ≤ xi, yi ≤ n) — the coordinates of the i-th banned cell. All given cells are distinct.
Consider the field rows numbered from top to bottom from 1 to n, and the columns — from left to right from 1 to n.
Print a single integer — the maximum points Gerald can earn in this game.
3 1
2 2
0
3 0
1
4 3
3 1
3 2
3 3
1 题意:在一个n*n的矩阵的边上的单元格(角上的单元格不能放)中放入chip,每秒种chip向着它的对边移动一个单元格,进行n-1秒
以下三种情况为输得0分:
1.两个chip出现在同一个单元格中。
2.两个chip在一秒中互换位置。
3.至少一个chip落在禁止的单元格中。
矩阵中可以放的chip数的最大值为其得分。 思路:初看无思路。(目前看来比较暴力)从第2行开始遍历行,若无障碍,可放一个,与该行沿对角线对称的列上,若无障碍则也可放一个,这个规则一定成立。若n等于奇数,则需考虑特殊情况,若n/2+1行和n/2+1列均无障碍的情况下,这一行和这一列一共只能放一个。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 1005 int map[N][N]; int main()
{
int n,m,x,y,mr=,mc=;
scanf("%d%d",&n,&m);
for(int i=; i<m; i++)
{
scanf("%d%d",&x,&y);
map[x][y]=-;
}
int res=;
for(int i=; i<n; i++)
{
int ok=;
for(int j=;j<=n;j++)
{
if(map[i][j]==-)
{
ok=;
if(n%==&&(i==n/+))
mr=;
break;
}
}
if(ok)
res++;
ok=;
for(int j=;j<=n;j++)
{
if(map[j][i]==-)
{
ok=;
if(n%==&&i==(n/+))
mc=;
break;
}
}if(ok)
res++;
}
if(n%==&&mc==&&mr==)
res--;
printf("%d\n",res);
return ;
}
codeforces_333B_水过的更多相关文章
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- Openjudge 1.13-21:最大质因子序列(每日两水)
总时间限制: 1000ms 内存限制: 65536kB 描述 任意输入两个正整数m, n (1 < m < n <= 5000),依次输出m到n之间每个数的最大质因子(包括m和n ...
- [LeetCode] Container With Most Water 装最多水的容器
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- 如何装最多的水? — leetcode 11. Container With Most Water
炎炎夏日,还是呆在空调房里切切题吧. Container With Most Water,题意其实有点噱头,简化下就是,给一个数组,恩,就叫 height 吧,从中任选两项 i 和 j(i <= ...
- Codeforces 刷水记录
Codeforces-566F 题目大意:给出一个有序数列a,这个数列中每两个数,如果满足一个数能整除另一个数,则这两个数中间是有一条边的,现在有这样的图,求最大联通子图. 题解:并不需要把图搞出来, ...
- Bzoj3041 水叮当的舞步
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 132 Solved: 75 Description 水叮当得到了一块五颜六色的格子形地毯作为生日礼物 ...
- ACM :漫漫上学路 -DP -水题
CSU 1772 漫漫上学路 Time Limit: 1000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Submit ...
- bzoj2002弹(dan)飞绵羊 分块水过
据说是道lct求深度的题 但是在小猫大的指点下用分块就n^1.5水过了 = =数据忘记加强系列 代码极其不美观,原因是一开始是听小猫大讲的题意,还以为是弹到最前面... #include <cs ...
- bzoj1103树状数组水题
(卧槽,居然规定了修改的两点直接相连,亏我想半天) 非常水的题,用dfs序(而且不用重复,应该是直接规模为n的dfs序)+树状数组可以轻松水 收获:树状数组一遍A(没啥好骄傲的,那么简单的东西) #i ...
随机推荐
- 连接App.config
ConfigurationManager.AppSettings["AdminName"]; 连接App.config的字符
- Codeforces Beta Round #2 B. The least round way
这个2B题还好~~ 题目大意: 给出一个矩阵.从左上走到右下,仅仅能往右或下走.路径中每一个格子有一个数.这些数相乘得出一个数. 求这个数末尾零最少的一条路径. 解题思路: 找出一条路径.乘积得数中素 ...
- vs2012下安装Cocos2d-x模板问题
今天想開始学Cocos2d-x.于是依据书本的提示到网上去下载了所需的安装包.我下载的cocos2d-x版本号是2.2.3.在下载完毕之后依照书中的步骤对其环境进行配置.在搞到模板安装这一步,发现找不 ...
- 另存为Alt-F-A ©┗ 最近使用的文档/选项
另存为Alt-F-A © ┗ 最近使用的文档/选项
- (四)Java 基础语法
Java 基础语法 一个Java程序可以认为是一系列对象的集合,而这些对象通过调用彼此的方法来协同工作.下面简要介绍下类.对象.方法和实例变量的概念. 对象:对象是类的一个实例,有状态和行为.例如,一 ...
- 【bzoj4590】[Shoi2015]自动刷题机
因为解一定是单调的,n越小切的题越多,这是可以肯定的,那么直接二分答案 #include<algorithm> #include<iostream> #include<c ...
- 8-23 canvas专题
8-23 canvas专题-了解外部框架的使用 学习要点 掌握画布内容的导出的toDataURL()方法 了解外部框架的使用 第八章内容介绍 在第八章中我们将对以前的知识进行简单的回顾,着重对canv ...
- 2-4 原生小程序 - 自带组件及API
获取用户的信息有两种,一种是不需要登录的,我们只需要获取用户的头像,还有微信的名.还有一种是登录的,就是登录后台校验的,就是获取用户的openid. webview,可以内嵌一个网页,类似于原生的开发 ...
- mysql通用分页存储过程遇到的问题(转载)
mysql通用分页存储过程遇到的问题(转载) http://www.cnblogs.com/daoxuebao/archive/2015/02/09/4281980.html
- js工作备注
{ field : 'state', title : '事件状态', align: 'center', width : 120, formatter : function(value, row, in ...