Card
算法:
暴力枚举找循环节。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<iostream> #include<vector> #include<string> #include<math.h> #include<map> #include<set> #include<algorithm> using namespace std; int T,N,L,R; int card[100]; int pcard[100]; int p[100]; int main( ) { scanf("%d",&T); int abc = 1; while( T-- ) { for( int i = 1; i <= 52; i++) { scanf("%d",&card[i]); pcard[i] = card[i]; } scanf("%d%d%d",&N,&L,&R); int minx = 0; for( int i = 1; i <= 1001110; i++) { int n = 1; for( int j = L; j <= R; j++) { p[n++] = card[j]; } int v = R - L + 1; for( int x= L-1; x >= 1; x--) { card[x + v] = card[x]; } for( int t = 1; t <= v; t++) { card[t] = p[t]; } int f = 0; for( int j = 1; j <= 52; j++) { if( pcard[j] == card[j] ) f++; } if( f == 52 ) { minx = i; break; } } N %= minx; for( int i = 1; i <= N; i++) { int n = 1; for( int j = L; j <= R; j++) { p[n++] = pcard[j]; } int v = R - L + 1; for( int x= L-1; x >= 1; x--) { pcard[x + v] = pcard[x]; } for( int t = 1; t <= v; t++) { pcard[t] = p[t]; } } printf("Case #%d: ",abc++); for( int j = 1; j <= 51; j++) { printf("%d ",pcard[j]); } printf("%d\n",pcard[52]); } return 0; }
posted on 2012-08-09 16:54 more think, more gains 阅读(176) 评论(0) 编辑 收藏 举报