Codeforces Round #194 (Div. 1) B. Chips 水题
B. Chips
Time Limit: 20 Sec Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/333/problem/B
Description
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.
Input
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.
Output
Print a single integer — the maximum points Gerald can earn in this game.
Sample Input
4 3
3 1
3 2
3 3
Sample Output
HINT
题意
在N*N的棋盘边上放置棋子,每分钟把棋子向对面移动一格,要求不能进入某些特定位置,两枚棋子在某一分钟不能位于同一格且不能交换位置.求最多放多少个棋子.
题解:
一个不能进入 的位置能废掉一行和一列.设x[i]表示第i行能不能放,y[i]表示列.对于某个i来说,如果x[i]或y[i]中有真那么这里至少能放一个.如果x与 y的值同时为真,则有希望放两个(行列各一个).此时需满足这两枚棋子不能同时出现在交叉点.显然只有当n为奇数且该交点位于棋盘正中央时这是不可避免 的.
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** int a[];
int b[];
int main()
{
//test;
int n,m;
n=read(),m=read();
for(int i=;i<m;i++)
{
int x=read(),y=read();
a[x]=;
b[y]=;
}
int ans=;
for(int i=;i<=n-;i++)
{
if(a[i]+b[i]==)
ans++;
if(a[i]+b[i]==)
{
ans+=;
if(n%==&&i==(n+)/)
ans--;
}
}
cout<<ans<<endl;
}
Codeforces Round #194 (Div. 1) B. Chips 水题的更多相关文章
- Codeforces Round #185 (Div. 2) B. Archer 水题
B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...
- Codeforces Round #360 (Div. 2) A. Opponents 水题
A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...
- Codeforces Round #190 (Div. 2) 水果俩水题
后天考试,今天做题,我真佩服自己... 这次又只A俩水题... orz各路神犇... 话说这次模拟题挺多... 半个多小时把前面俩水题做完,然后卡C,和往常一样,题目看懂做不出来... A: 算是模拟 ...
- Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)解题报告
对于这道水题本人觉得应该应用贪心算法来解这道题: 下面就贴出本人的代码吧: #include<cstdio> #include<iostream> using namespac ...
- Codeforces Round #194 (Div. 2) D. Chips
D. Chips time limit per test:1 second memory limit per test:256 megabytes input:standard input outpu ...
- Codeforces Round #340 (Div. 2) B. Chocolate 水题
B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...
- Codeforces Round #340 (Div. 2) A. Elephant 水题
A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...
- Codeforces Round #340 (Div. 2) D. Polyline 水题
D. Polyline 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co There are three p ...
- Codeforces Round #338 (Div. 2) A. Bulbs 水题
A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...
随机推荐
- arch优化开机
查看开机时间 systemd-analyze 具体开机时间 systemd-analyze blame 你可以systemctl --all | grep not-found 查看有哪些服务挂掉了.然 ...
- python自动开发之(算法)第二十七天
1.什么是算法? 算法(Algorithm):一个计算过程,解决问题的方法 2.复习:递归 递归的两个特点:(1) 调用自身 (2)结束条件 def func1(x): print(x) func1( ...
- 【Python学习】使用BeautifulSoup解析HTML
对于一个最简单的爬虫结构的代码是这样的. 也就是抓取出整个页面,然后创建一个BeautifulSoup对象. from urllib.request import urlopen from bs4 i ...
- go时间和日期
1. time包 2. time.Time类型,用来表示时间 3. 获取当前时间, now := time.Now() 4. time.Now().Day(),time.Now().Minute(), ...
- Windows 7 64 位操作系统安装 Ubuntu 17.10
一.准备工作 1. DiskGenius:分区工具,为 Linux 建立单独的分区.(Linux 公社下载源) 2. UUI:Universal USB Installer,通用 U 盘安装器,用来制 ...
- 42.Trapping Rain Water---dp,stack,两指针
题目链接:https://leetcode.com/problems/trapping-rain-water/description/ 题目大意:与84题做比较,在直方图中计算其蓄水能力.例子如下: ...
- $FFT$(快速傅里叶变换)
- 概念引入 - 点值表示 对于一个$n - 1$次多项式$A(x)$,可以通过确定$n$个点与值(即$x$和$y$)来表示这唯一的$A(x)$ - 复数 对于一元二次方程 $$x^2 + 1 = 0 ...
- 安装 Xamarin for Visual Studio
总得来说,Xamarin 有“联网自动安装”和“手动安装”两种方式. 说明:本文涉及得资源链接都是官网的,同时,在 我的网盘 也有相关备份. 现在,我就以 Windows 为例来大概说明……(-=-我 ...
- leetcode 之Remove Duplicates from Sorted Array(1)
删除数组中的重复元素并返回新数组的个数 思路:保留不同的元素即可. int removeDeplicates(int A[], int n) { ; ; i < n; i++) { if (A[ ...
- csu 1551(线段树+DP)
1551: Longest Increasing Subsequence Again Time Limit: 2 Sec Memory Limit: 256 MBSubmit: 267 Solve ...