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 ...
随机推荐
- OCP-1Z0-051-题目解析-第21题
21. Examine the description of the EMP_DETAILS table given below: name NULL ...
- Python开发【第5节】【函数基础】
1.函数 函数的本质就是功能的封装. 函数的作用 提升代码的重复利用率,避免重复开发相同代码 提高程序开发效率 便于程序维护 2.函数定义 def 函数名(参数): """ ...
- redis 的部分配置
linux 安装: yum install redis 修改redis配置: 配置文件位于/etc/redis.conf. 作为守护进程运行(默认no) # 默认情况下 redis 不是作为守护进程运 ...
- 编译android的一些坑
1 降级gcc g++到4.4 2 参考:http://source.android.com/source/initializing.html来配置环境 3 使用jdk1.6 包括 java java ...
- codeforces 965E Trie+multiset
E. Short Code time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- bzoj2763 [JLOI2011]飞行路线——分层图
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2763 构建分层图. 代码如下: 写法1(空间略大)(时间很慢): #include<i ...
- 28. extjs中Ext.BLANK_IMAGE_URL的作用
转自:https://blog.csdn.net/yiyuhanmeng/article/details/6960132 在使用ExtJS时,我们往往需要在使用之前加入这么一句:Ext.BLANK_I ...
- C#面向过程之局部变量、成员变量、变量作用域、可变参数
局部变量与成员变量: 局部变量:定义在方法里面的变量就叫做局部变量:没有默认的初始值,使用变量之前必须给它赋值成员变量:定义在类下面的变量叫做成员变量:如果是数值类型默认初始值为0 如果是引用类型默 ...
- css实现左边div固定宽度,右边div自适应撑满剩下的宽度
(1)使用float <div class="use-float"> <div></div> <div></div> & ...
- bzoj 1047: [HAOI2007]理想的正方形【单调队列】
没有复杂结构甚至不长但是写起来就很想死的代码类型 原理非常简单,就是用先用单调队列处理出mn1[i][j]表示i行的j到j+k-1列的最小值,mx1[i][j]表示i行的j到j+k-1列的最大值 然后 ...