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的更多相关文章

  1. Puzzle 面向服务/切面(AOP/IOC)开发框架 For .Net

    Puzzle 面向服务/切面AOP开发框架 For .Net AOP主要实现的目的是针对业务处理过程中的切面进行提取,它所面对的是处理过程中的某个步骤或阶段,以获得逻辑过程中各部分之间低耦合性的隔离效 ...

  2. HDU5456 Matches Puzzle Game(DP)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5456 Description As an exciting puzzle game for ...

  3. 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 ...

  4. poj3678 Katu Puzzle 2-SAT

    Katu Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6714   Accepted: 2472 Descr ...

  5. POJ1651Multiplication Puzzle[区间DP]

    Multiplication Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8737   Accepted:  ...

  6. codeforce B Island Puzzle

    B. Island Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  7. poj 1651 Multiplication Puzzle (区间dp)

    题目链接:http://poj.org/problem?id=1651 Description The multiplication puzzle is played with a row of ca ...

  8. Ignatius's puzzle

    Ignatius's puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  9. A hard puzzle

    A hard puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  10. hdu 1097 A hard puzzle

    Problem Description lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how ...

随机推荐

  1. odoo 币别符号显示机制 Monetary

    //-------------------------------------------------------------------basic_fields.js init: function ...

  2. 使用 Mockito 辅助单元测试

    了解过单元测试相关概念的人应该会清楚一个概念:一个好的单元测试应该是与环境无关的,每一个测试都是相互独立的.亦即你可以在任何地方,以任意顺序运行这些测试,最后得到的结果是一样的.但是我被测试的类/方法 ...

  3. [转帖]11G Undo使用率很高问题

    11G Undo使用率很高问题 http://blog.itpub.net/12679300/viewspace-1164916/ 原创 Oracle 作者:wzq609 时间:2014-05-20 ...

  4. C语言结构体的“继承”

    这里说的继承有点像C++里的父类和子类,实际上是结构体类型的强制转换,最近看Linux内核源码时经常接触到这种方法,在这里就当作是一个简单的学习吧. 下面给出一个Demo,很简单,分别定义了一个fat ...

  5. 2014百度之星 Information

    Information Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. Golang读取并修改非主流配置文件

    今天工作中碰到的问题,要求修改此配置文件,没看出来是什么格式,用了下面的思路: mysql { # If any of the files below are set, TLS encryption ...

  7. MATBLAB学习笔记----基础绘图

    整理自台大生机系郭彦甫.MATLAB系列教程,吐血推荐看这个视频,非计算机专业也能看懂,全程干货 MATLAB图形来自于“数据”,MATLAB不能理解函数. MATLAB绘图原理: 1.在特定范围生成 ...

  8. 【mybatis】mybatis查询 结果 用map接收,无实体接收 + 关联子表 一并返回主子表的结果

    如果后台程序没有实体对应mysql的数据表. 而mybatis想要查询mysql这个数据表的数据,返回给应用程序. 应用程序该如何接收? =============================== ...

  9. JWT与RBAC权限模型

    JWT JWT是什么? Json web token (JWT)是为了网络应用环境间传递声明而执行的一种基于JSON的开发标准(RFC7519),该token被设计为紧凑且安全的,特别适用于分布式站点 ...

  10. Spring4参考手册中文版

    Spring4参考手册中文版 前言 https://github.com/b2gats/stone-docs/blob/master/spring-4-beans.md Part III. 核心技术 ...