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 ... 
随机推荐
- 【操作系统之三】Linux下进程间通信-IPC(Inter-Process Communication)
			管道(Pipe)及有名管道(named pipe):管道可用于具有亲缘关系进程间的通信,有名管道克服了管道没有名字的限制,因此,除具有管道所具有的功能外,它还允许无亲缘关系进程间的通信:信号(Sign ... 
- 通过URI协议实现浏览器调用手机app
			<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ... 
- 微信小程序在苹果手机的New Date坑
			new Date(“2017-06-16”) 在IOS会出现NAN的情况,必须改为new Date(“2017/06/16”) 才能兼容 
- Delphi微信支付【支持MD5和HMAC-SHA256签名与验签】
			作者QQ:(648437169) 点击下载➨微信支付 微信支付api文档 [Delphi 微信支付]支持付款码支付.二维码支付.订单查询.申请退款.退款查询.撤销订单.关闭订单. ... 
- 『7.3 NOIP模拟赛题解』
			T1 gift Description  夏川的生日就要到了.作为夏川形式上的男朋友,季堂打算给夏川买一些生日礼物.  商店里一共有种礼物.夏川每得到一种礼物,就会获得相应喜悦值Wi(每种礼物的喜 ... 
- FusionInsight大数据开发---Streaming应用开发
			Streaming应用开发 掌握Streaming基本业务开发流 熟悉Streaming常用API接口使用 掌握Streaming业务设计基本原则 了解Streaming应用开发环境 了解CQL开发流 ... 
- .NET Core中如何对Url进行编码和解码
			我们在.NET Core项目中,可以用WebUtility类对Url进行编码和解码,首先我们要确保项目中引入了nuget包:System.Runtime.Extensions 当然这个nuget包默认 ... 
- Mybatis源码解析(二) —— 加载 Configuration
			Mybatis源码解析(二) -- 加载 Configuration 正如上文所看到的 Configuration 对象保存了所有Mybatis的配置信息,也就是说mybatis-config. ... 
- Map接口---Day20
			Map接口概述: 现实生活中,我们常会看到这样的一种集合:IP地址与主机名,身份证号与个人,系统用户名与系统用户对象等, 这种一一对应的关系,就叫做映射.Java提供了专门的集合类用来存放这种对象关系 ... 
- Python进阶----pymysql模块的使用,单表查询
			Python进阶----pymysql模块的使用,单表查询 一丶使用pymysql   1.下载pymysql包: pip3 install pymysql   2.编写代码 ... 
