2015
09-17

# Poker Shuffle

Jason is not only an ACMer, but also a poker nerd. He is able to do a perfect shuffle. In a perfect shuffle, the deck containing K cards, where K is an even number, is split into equal halves of K/2 cards which are then pushed together in a certain way so as to make them perfectly interweave. Suppose the order of the cards is (1, 2, 3, 4, …, K-3, K-2, K-1, K). After a perfect shuffle, the order of the cards will be (1, 3, …, K-3, K-1, 2, 4, …, K-2, K) or (2, 4, …, K-2, K, 1, 3, …, K-3, K-1).
Suppose K=2^N and the order of the cards is (1, 2, 3, …, K-2, K-1, K) in the beginning, is it possible that the A-th card is X and the B-th card is Y after several perfect shuffles?

Input to this problem will begin with a line containing a single integer T indicating the number of datasets.
Each case contains five integer, N, A, X, B, Y. 1 <= N <= 1000, 1 <= A, B, X, Y <= 2^N.

Input to this problem will begin with a line containing a single integer T indicating the number of datasets.
Each case contains five integer, N, A, X, B, Y. 1 <= N <= 1000, 1 <= A, B, X, Y <= 2^N.

3
1 1 1 2 2
2 1 2 4 3
2 1 1 4 2

Case 1: Yes
Case 2: Yes
Case 3: No

cwz指出这种洗牌规则不符合常规, 还真是, 先不管了~~

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
// #pragma commet(linker, "/STACK:102400000, 102400000")
using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<PII> VPII;

template <class T> inline void checkMin(T& a, T b) { if (b < a) a = b; }
template <class T> inline void checkMax(T& a, T b) { if (b > a) a = b; }

const int N = 105;
const double INF = 1e20;

struct Rec {
int i, j, k;
Rec(int a, int b, int c) : i(a), j(b), k(c) {}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int n;
string a, b, x, y;

void getIn(string& x) {
char s[1005];
scanf("%s", s);
int l = strlen(s);
for (int i = 0; i < l / 2; i++) swap(s[i], s[l - i - 1]);

int k = 0; while (s[k] == '0') s[k++] = '9';
s[k]--;
x.resize(0);
for (int i = 0; i < n; i++) {
if ((s[0] - '0') & 1) x += '1'; else x += '0';
int jw = 0;
for (int i = l - 1; i >= 0; i--) {
int val = s[i] - '0' + jw * 10;
jw = val & 1;
s[i] = (val >> 1) + '0';
}
}
}

int main() {
int T; scanf("%d", &T);
for (int cas = 1; cas <= T; cas++) {
scanf("%d", &n);
getIn(a);
getIn(x);
getIn(b);
getIn(y);

bool flag = false;
for (int t = 0; t < n; t++) {
bool ff = true;
for (int i = 0; i < n; i++) {
int k = i + t;
if (k >= n) k -= n;
if ((a[k] == b[k]) ^ (x[i] == y[i])) { ff = false; break; }
}
if (ff) { flag = true; break; }
}
if (flag) printf("Case %d: Yes\n", cas);
else printf("Case %d: No\n", cas);
}
return 0;
}

1. 苏联为什么该死tm用我告诉你？？？斯大林杀了多少人? 建了多少集中营？杀了波兰多少军官 还死不承认 最后还是叶利钦公布了档案，我有什么资格？凡是反人类反社会的国家 都该死，这事发生在中国的还少吗？？文革死了多少人？多少人受迫害？你一点意识都没有，因为你的