URAL 1034. Queens in Peaceful Positions
2015-08-06 16:41
387 查看
题意开始完全理解错了,,,以为是给一个皇后的位置问几步可以让他们处于和平
其实是开始是和平,问只改动三个皇后位置仍和平的方式有多少?
可以想到所有的皇后的横坐标是1到n,纵坐标是1到n,,,,,所以三个皇后变换,其实就是换三个皇后的横坐标纵坐标看可不可以。。。。。。
还有斜线上不能有东西。。。。。
代码来自别人:http://blog.sina.com.cn/s/blog_5f50d0c20100d5hn.html
#include<stdio.h>
#include<string.h>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#include<stdio.h>
long h[200];long n;
void swap(long a,long b,long c)
{ long t1=h[a],t2=h[b],t3=h[c]; h[b]=t1; h[c]=t2; h[a]=t3;}
bool ks()
{ bool a[200]={false},b[200]={false};
for(int i=1;i<=n;i++)
{ if(a[i+h[i]+100]==true) return false; if(b[i-h[i]+100]==true) return false; a[i+h[i]+100]=true; b[i-h[i]+100]=true; } return true;}
int main(){ long x,y; scanf("%ld",&n);
for(long i=1;i<=n;i++) { scanf("%ld%ld",&x,&y); h[x]=y; }
long i,j,k,s=0; for(i=1;i<=n;i++) for(j=1;j<i;j++) for(k=1;k<j;k++)
{ swap(i,j,k); if(ks()==true) s++; swap(i,j,k); if(ks()==true) s++; swap(i,j,k); }
printf("%ld\n",s); return 0;}
其实是开始是和平,问只改动三个皇后位置仍和平的方式有多少?
可以想到所有的皇后的横坐标是1到n,纵坐标是1到n,,,,,所以三个皇后变换,其实就是换三个皇后的横坐标纵坐标看可不可以。。。。。。
还有斜线上不能有东西。。。。。
代码来自别人:http://blog.sina.com.cn/s/blog_5f50d0c20100d5hn.html
#include<stdio.h>
#include<string.h>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#include<stdio.h>
long h[200];long n;
void swap(long a,long b,long c)
{ long t1=h[a],t2=h[b],t3=h[c]; h[b]=t1; h[c]=t2; h[a]=t3;}
bool ks()
{ bool a[200]={false},b[200]={false};
for(int i=1;i<=n;i++)
{ if(a[i+h[i]+100]==true) return false; if(b[i-h[i]+100]==true) return false; a[i+h[i]+100]=true; b[i-h[i]+100]=true; } return true;}
int main(){ long x,y; scanf("%ld",&n);
for(long i=1;i<=n;i++) { scanf("%ld%ld",&x,&y); h[x]=y; }
long i,j,k,s=0; for(i=1;i<=n;i++) for(j=1;j<i;j++) for(k=1;k<j;k++)
{ swap(i,j,k); if(ks()==true) s++; swap(i,j,k); if(ks()==true) s++; swap(i,j,k); }
printf("%ld\n",s); return 0;}
相关文章推荐
- easyUI 1.4版本 easyui-numberbox输入不了小数点bug
- ueditor编辑器使用
- UIStepper (加减符号)(步进控件)
- 关于两个标签的比较@queryparam和@pathparam
- iOS开发笔记--UILabel的相关属性设置
- 写在Demo战斗系统之前,先用原型工具做套UI第五篇-即时战斗UI界面制作
- SAP Basis: 从SAP GUI杀死进程
- Android中UI线程与后台线程交互设计的5种方法
- 详解request.getRequestDispatcher(url).forword(request,response)
- Errors running builder 'Android Resource Manager' on&nb
- String、StringBuffer、与StringBuilder的区别
- iOS8 UIPopoverPresentationController的Crash解决
- Implement Stack using Queues
- 使用Thread+Handler实现非UI线程更新UI界面
- Access restriction: The type BASE64Encoder is not accessible due to restrict
- hdoj---Rescue
- hdoj---Rescue
- UIKit 滚动视图 UIScrollView
- 【Android UI】Android开发之View的几种布局方式及实践
- [LeetCode] Unique Binary Search Trees II