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个人依次等概率取一个箱子,如果有礼物则 ...
随机推荐
- myeclise中创建maven web程序
myeclipse自带了许多插件,因此使用频率很高,但是对maven框架下web程序似乎不是很好的支持,每次创建web程序总是会报一大堆的异常,因此特此记录一下如何在myeclipse下创建一个web ...
- linux内核中的两个标记GFP_KERNEL和GFP_ATOMIC是用来干什么的?
1. 作用 用来标记分配内核空间内存时的方式 2. 两个标记使用在什么场合? 如果内存不够时,会等待内核释放内存,直到可以分配相应大小的内存,也就意味着会发生阻塞,因此不能使用在中断处理函数中,而GF ...
- 光学定位点(mark点)
Mark点是使用机器焊接时用于定位的点. 表贴元件的pcb更需要设置Mark点,因为在大批量生产时,贴片机都是操作人员手动或者机器自动寻找Mark点进行校准.极少数不设置Mark点也可以,操作非常 ...
- Twitter开发
开发文档:https://developer.twitter.com/ the Twitter Developer Account Application 示例:https://wptweetboos ...
- Images之base image
Create a base image Most Dockerfiles start from a parent image. If you need to completely control th ...
- js replace使用及正则表达式使用
本文为博主原创,未经允许不得转载: js中replace方法与java中的replace方法相同,主要做替换. 表达式:stringObj.replace(rgExp, replaceText) 参数 ...
- springmvc异步上传图片并回调页面函数插入图片url代码示例
<tr> <td class="search_td">属性值图片值:</td> <td> <input type=" ...
- SpringBoot war包部署到Tomcat服务器
(1)pom.xml文件修改<packaging>war</packaging>,默认是jar包,<build>节点中增加<finalName>spri ...
- Unicode转字符串
/// <summary> /// Unicode转字符串 /// </summary> /// <returns>The to string.</retur ...
- 用Github做一个静态网页(GithubPages)
一.新建一个仓库(new). 二.命名Repository name为:(名字).github.io(一定要有.github.io). 三.勾选Initialize this repository w ...