csp评测里不能存以前的代码,先存一份70分的在这儿,有心情再填坑。
#include <bits/stdc++.h>
using namespace std;
char ans[20] = "0123456789ABCDEF";
int toInt(char a) {
if (a >= '0' && a <= '9')
return a - '0';
else
return a - 'A' + 10;
}
char Xor(char a, char b) {
int x, y;
x = toInt(a), y = toInt(b);
x = x xor y;
return ans[x];
}
char di[1010][101000];
bool vis [1010];
int main() {
int n, s, l, numk = 0; // numk是每个盘上块的数量
scanf("%d %d %d", &n, &s, &l);
memset(vis, false, sizeof(vis));
for (int i = 1; i <= l; i++) {
int num;
scanf("%d", &num);
vis[num] = true;
scanf("%s", di[num]);
if (numk == 0) numk = strlen(di[num]) / 8;
}
int m; scanf("%d", &m);
while(m--) {
int b; scanf("%d", &b);
if (b >= (n - 1) * numk) { //从0开始计数,所以相等也是超出范围的
printf("-\n");
continue;
}
int pos1 = b / s, pos2 = b % s; //pos1是看块在第几个条带,pos2是看块属于该条带的第几个块
int x, y, num, cur, p; //最终定位在第x块盘的第y个条带里
y = pos1 / (n - 1);
num = pos1 % (n - 1); //num是第y层条带的第num个盘
cur = y % n; p = n - 1 - cur;
x = p + num + 1; x = x % n;
// cout << "x:" << x << " y:" << y << endl;
if (!vis[x]) {
if (l == n - 1) {
for (int i = (y * s + pos2) * 8; i < (y * s + pos2 + 1) * 8; i++) {
if (di[x][i] == '\0') {
int j = 0;
if (j == x) j++;
char a = di[j][i];
while(++j < n) {
if (j == x) continue;
char a1 = di[j][i];
a = Xor(a, a1);
}
di[x][i] = a;
}
printf("%c", di[x][i]);
}
printf("\n");
}
else
printf("-\n");
continue;
}
// 最后输出第x块盘,第y * s + pos2个块里的数据
for (int i = (y * s + pos2) * 8; i < (y * s + pos2 + 1) * 8; i++) {
printf("%c", di[x][i]);
}
printf("\n");
}
return 0;
}
/*
2 1 2
0 000102030405060710111213141516172021222324252627
1 000102030405060710111213141516172021222324252627
2
0
1
3 2 2
0 000102030405060710111213141516172021222324252627
1 A0A1A2A3A4A5A6A7B0B1B2B3B4B5B6B7C0C1C2C3C4C5C6C7
2
2
5
3 1 2
0 00000000
1 00000000
1
2
3 1 1
1 00000000
1
0
-
3 2 2
1 A0A1A2A3A4A5A6A7B0B1B2B3B4B5B6B7C0C1C2C3C4C5C6C7
0 000102030405060710111213141516172021222324252627
2
2
5
*/