sgu 139 Help Needed!
题意:16数码是否有解?
先计算展开成一维后逆序对。如果0在最后一行,那么逆序偶时有解。4*4时(n为偶)0的位置上升一行,逆序对+3或-1(奇偶性变化)。(n为奇时+2或+0,不变)
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#define mkp make_pair
using namespace std;
const double EPS=1e-;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon;
int arr[SZ]; int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
lon casenum;
//cin>>casenum;
//for(lon time=1;time<=casenum;++time)
{
int n=;
int res=;
for(int i=;i<n;++i)
{
cin>>arr[i];
if(arr[i]==)res+=i/+;
}
for(int i=;i<n;++i)
{
for(int j=i+;j<n;++j)
{
if(arr[i]!=&&arr[j]!=&&arr[i]>arr[j])++res;
}
}
cout<<(res&?"NO":"YES")<<endl;
}
return ;
}
sgu 139 Help Needed!的更多相关文章
- SGU 139. Help Needed! 逆序数,奇偶性,分析 难度:0
139. Help Needed! time limit per test: 0.25 sec. memory limit per test: 4096 KB Little Johnny likes ...
- SGU 139.Help Needed!
题意: 判断15数码问题是否有解. 如果0的偏移量和逆序对个数同奇偶则无解. 因为目标状态的偏移量为0,逆序对为15,而0移动的时候偏移量±1,逆序对的改变量为也为奇数. 这就使得偏移量和逆序对数始终 ...
- SGU 分类
http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...
- SGU 200. Cracking RSA (高斯消元求自由变元个数)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=200 200. Cracking RSA time limit per test: ...
- rpm包安装过程中依赖问题“libc.so.6 is needed by XXX”解决方法
rpm包安装过程中依赖问题"libc.so.6 is needed by XXX"解决方法 折腾了几天,终于搞定了CentOS上的Canon LBP2900打印机驱动.中间遇到了一 ...
- SGU 495. Kids and Prizes
水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...
- redhat 中安装rpm包时遇到异常 “error: Failed dependencies:xinetd is needed by .”
redhat 中安装rpm包时遇到错误 “error: Failed dependencies:xinetd is needed by ....” redhat中安装rpm包时遇到“error: Fa ...
- ACM: SGU 101 Domino- 欧拉回路-并查集
sgu 101 - Domino Time Limit:250MS Memory Limit:4096KB 64bit IO Format:%I64d & %I64u Desc ...
- 【SGU】495. Kids and Prizes
http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...
随机推荐
- Python常用库之functools
functools 是python2.5被引人的,一些工具函数放在此包里. python2.7中 python3.6中 import functools print(dir(functools)) [ ...
- R语言 格式化数字
x = 1111111234.6547389758965789345 y = formatC(x, digits = 8, format = "f") # [1] "11 ...
- 题解——牛客网OI赛制测试赛2
T1 规律题 考虑先全部选中再去重即可 #include <cstdio> #include <algorithm> #include <cstring> #inc ...
- HDU 4918 Query on the subtree(动态点分治+树状数组)
题意 给定一棵 \(n\) 个节点的树,每个节点有点权.完成 \(q\) 个操作--操作分两种:修改点 \(x\) 的点权.查询与 \(x\) 距离小于等于 \(d\) 的权值总和. \(1 \leq ...
- 【转载】谈谈自己对REST、SOA、SOAP、RPC、ICE、ESB、BPM知识汇总及理解
转载自:https://blog.csdn.net/tantexian/article/details/48196453 SOA: 维基百科解释:SOA:面向服务的软件架构(Service Orien ...
- 使用p4c将P4 14代码转换为16代码
参考: [Question] How to make conversion between P4 14 and P4 16? 使用p4c将P4 14代码转换为16代码: $ p4test --p4v ...
- webpack插件配置(一) webpack-dev-server 路径配置
本文的路径配置主要涉及到webpack.config.js文件中devServer与output两个选项的配置 webpack-dev-server定义 webpack-dev-server主要是启动 ...
- Mybatis工程搭建
工程搭建 • 1依赖包 • 2配置文件 • 2.1spring-mybatis.xml • 2.2mybatis-config.xml自带配置文件 • 2.3 mapper(dao)对象 • 2.4 ...
- 微信小程序之倒计时插件 wxTimer
微信小程序之倒计时插件 wxTimer 介绍: 用于在微信小程序中进行倒计时的组件. 功能: 1.最基础的当然就是倒计时功能了. 2.可以设置倒计时结束后执行的事件. 3.可以设置倒计时执行过程中 ...
- 在ETH交易区块链里查看北大的那封信
本文仅限于科普编码知识使用,随便举的例子不代表本人立场. 欢迎在其他网站传播,但转载不得标注来源及作者. 1.随便打开一个ETH区块链浏览网站,比如:https://www.etherchain.or ...