M × N Puzzle
http://poj.org/problem?id=2893
来自逆序对的强大力量
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#define lowbit(x)(x&-x)
using namespace std;
int c[],a[][],maxn,n,m,d[];
void update(int k,int x){for(int i=k;i<=maxn;i+=lowbit(i))c[i]+=x;}
int getsum(int x)
{
int ans=;
for(int i=x;i;i-=lowbit(i))ans+=c[i];
return ans;
}
int main()
{
while()
{ int cnt=,num=;
scanf("%d%d",&m,&n);
if(m==&&n==) break;
maxn=m*n;
for(register int i=;i<=maxn;++i)
{
c[i]=d[i]=;
}
int kl;
for(int i=;i<=m;++i)
for(int j=;j<=n;++j)
{
scanf("%d",&a[i][j]);
if(a[i][j]==){kl=i;continue; }
d[++cnt]=a[i][j];
update(d[cnt],);
num+=cnt-getsum(d[cnt]);
}
if(n%==)
{
if(num%==)printf("YES\n");
else printf("NO\n");
}
else
{
if((m-kl+num)%==)printf("YES\n");
else printf("NO\n");
}
}
}
M × N Puzzle的更多相关文章
- Puzzle 面向服务/切面(AOP/IOC)开发框架 For .Net
Puzzle 面向服务/切面AOP开发框架 For .Net AOP主要实现的目的是针对业务处理过程中的切面进行提取,它所面对的是处理过程中的某个步骤或阶段,以获得逻辑过程中各部分之间低耦合性的隔离效 ...
- HDU5456 Matches Puzzle Game(DP)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5456 Description As an exciting puzzle game for ...
- one recursive approach for 3, hdu 1016 (with an improved version) , permutations, N-Queens puzzle 分类: hdoj 2015-07-19 16:49 86人阅读 评论(0) 收藏
one recursive approach to solve hdu 1016, list all permutations, solve N-Queens puzzle. reference: t ...
- poj3678 Katu Puzzle 2-SAT
Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6714 Accepted: 2472 Descr ...
- POJ1651Multiplication Puzzle[区间DP]
Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8737 Accepted: ...
- codeforce B Island Puzzle
B. Island Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- poj 1651 Multiplication Puzzle (区间dp)
题目链接:http://poj.org/problem?id=1651 Description The multiplication puzzle is played with a row of ca ...
- Ignatius's puzzle
Ignatius's puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- A hard puzzle
A hard puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdu 1097 A hard puzzle
Problem Description lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how ...
随机推荐
- 第8课 常量表达式(constexpr)
一. const 和constexpr的区别 (一)修饰变量时,const为“运行期常量”,即运行期数据是只读的.而constexpr为“编译期”常量,这是const无法保证的.两者都是对象和函数接口 ...
- c# winform禁止窗口多开
static class Program { /// <summary> /// 应用程序的主入口点. /// </summary> [STAThread] static vo ...
- [C++进阶] 数据结构与算法
1 出栈&入栈问题 一个栈的入栈序列为ABCDE,则不可能的出栈序列为?(不定项选择题) A:ECDBA B:DCEAB C:DECBA D:ABCDE E:EDCBA 正确答案 ...
- A Philosophy of Software Design
关于复杂性,尚无统一的定义,从不同的角度可以给出不同的答案.可以用数量来度量,比如芯片集成的电子器件越多越复杂(不一定对):按层次性[2]度量,复杂度在于层次的递归性和不可分解性.在信息论中,使用熵来 ...
- HashMap源码2
public class test { @SuppressWarnings({ "rawtypes", "unchecked" }) public static ...
- maven-3.6.1
1.下载 cd /opt/ wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.1/binaries/apache-m ...
- centos 7 下 rabbitmq 3.8.0 & erlang 22.1 源码编译安装
centos 7 下 rabbitmq 3.8.0 & erlang 22.1 源码编译安装 安装前请检查好erlang和rabbitmq版本是否相匹配参考:RabbitMQ Erlang V ...
- [转帖]Druid介绍及入门
Druid介绍及入门 2018-09-19 19:38:36 拿着核武器的程序员 阅读数 22552更多 分类专栏: Druid 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议 ...
- JSR223 PostProcessor VS BeanShell PostProcessor in JMeter
I would recommend using JSR223 PostProcessor About performance: In JMeter's official user manual, Ab ...
- Windows定时清理文件处理脚本
一.运行CMD,输入forfile/?,即可获取forfile的使用方法 /P 路径 /M 文件类型 /D 时间 + | - +:之后 - :之前 example:-2 ...