kuangbinOJ 1217 Operations on Grids (暴搜)
来源:互联网 发布:羽西淘宝旗舰店 假货 编辑:程序博客网 时间:2024/05/05 21:13
题意:
给出一个矩阵,是右一个9位数的每位构成的,现在问通过一些四种操作能得到多少种不同的方案。操作分别为向做转,向右转,上下翻转,左右翻转。
题解:
暴力搜索,对每个排列的状态存入set。答案就是set.size(),比赛的时候一直wa,姿势不对。
#include<iostream>#include<math.h>#include<stdio.h>#include<algorithm>#include<string.h>#include<vector>#include<queue>#include<map>#include<set>using namespace std;#define B(x) (1<<(x))typedef long long ll;void cmax(int& a,int b){if(b>a)a=b;}void cmin(int& a,int b){if(b<a)a=b;}void lcmax(ll& a,ll b){if(b>a)a=b;}void lcmin(ll& a,ll b){if(b<a)a=b;}const int oo=0x3f3f3f3f;const ll OO=1LL<<61;const int MOD=10007;char s[12];int a[12],b[3][3],t[3][3];int cnt;set<ll>g;void Init(){ for(int i=0;i<3;i++) for(int j=0;j<3;j++) b[i][j]=s[i*3+j]-'0';}void change(int op){ for(int i=0;i<3;i++) for(int j=0;j<3;j++) t[i][j]=b[i][j]; if(op==1){ for(int i=0;i<3;i++) for(int j=0;j<3;j++) b[2-j][i]=t[i][j]; }else if(op==2){ for(int i=0;i<3;i++) for(int j=0;j<3;j++) b[j][2-i]=t[i][j]; }else if(op==3){ for(int i=0;i<3;i++) for(int j=0;j<3;j++) b[i][2-j]=t[i][j]; }else{ for(int i=0;i<3;i++) for(int j=0;j<3;j++) b[2-i][j]=t[i][j]; }}ll getS(){ ll x=0; for(int i=0;i<3;i++) for(int j=0;j<3;j++) x=x*10+b[i][j]; return x;}void gao(){ for(int i=0;i<3;i++) for(int j=0;j<3;j++) b[i][j]=s[i*3+j]-'0'; for(int i=0;i<cnt;i++) change(a[i]); g.insert(getS());}int main(){ //freopen("G:\\read.txt","r",stdin); int T,op; scanf("%d",&T); while(T--){ scanf("%s",s); Init(); cnt=0; for(int i=1;i<=4;i++){ scanf("%d",&op); while(op--)a[cnt++]=i; } g.clear(); do{ gao(); }while(next_permutation(a,a+cnt)); printf("%d\n",g.size()); } return 0;}/***/
0 0
- kuangbinOJ 1217 Operations on Grids (暴搜)
- kuangbin OJ 1217-- Operations on Grids(YY)(好题)
- ACM程序设计选修课——1065: Operations on Grids(暴力字符串)
- OpenCV - Operations on Arrays
- Operations on Arrays in opencv
- Operations on Surface_mesh in CGAL
- Operations on edges in polyhedron
- numpy_operations(Numberical operations on arrays)
- [agc003e]Sequential operations on Sequence
- Time Limited Exceeded => Bit operations (repeated operations on many)
- Operations
- YUI--grids
- Fluid Grids
- Many Grids
- YP2.6 Operations on Bits—Part II: Logical Operations(双语)
- Support of basic operations on Sets in Dynamics AX
- Disallowing cut copy paste operations on a textbox
- OpenCV - Operations on Arrays 对数组(矩阵)的一些操作
- linux 网站服务器优化 web server优化
- OC语言@property @synthesize和id
- ListView的getView方法原理解析
- 第二周上机项目4 图书馆的书
- php5.4.22 php_memcache.dll
- kuangbinOJ 1217 Operations on Grids (暴搜)
- struts工作原理
- 感觉再写下去就是流水账,挺浪费时间的,不写了!
- Android官方提供的支持不同屏幕大小的全部方法
- [LeetCode 38]Count and Say
- 微信菜单中的域名转发
- iOS block 小结
- nyoj 915 +-字符(贪心+栈)
- 0002. 工作起步