CSP-J普及组第一轮考试阅读程写结果专项训练(二)
程序1
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll T, n; ll k;
ll a[100007], b[100007];
inline void work() {
ll sum = 0;
for(int i = 1; i <= n; i++) sum ^= a[i];
for(int i = 1; i <= n; i++) b[i] = sum ^ a[i];
}
inline ll read() {
ll x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9') {
if(ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
int main() {
T = read();
while(T--) {
n = read(), k = read();
for(int i = 1; i <= n; i++)
a[i] = read();
if(n % 2 == 0 && k % 2 == 0) {
for(int i = 1; i <= n; i++)
printf("%lld ", a[i]);
printf("\n");
continue;
}
work();
for(int i = 1; i <= n; i++)
printf("%lld ", b[i]);
printf("\n");
}
return 0;
}
输入:
1
4 1
1 2 3 4
输出:
————————————————
输入:
1
4 2
0 0 0 1
输出:
————————————————
程序2
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int fx[] = {0, -2, -1, 1, 2, 2, 1, -1, -2};
const int fy[] = {0, 1, 2, 2, 1, -1, -2, -2, -1};
int bx, by, mx, my;
ll f[2][40];
bool s[40][40];
int main(){
scanf("%d%d%d%d", &bx, &by, &mx, &my);
bx += 2; by += 2; mx += 2; my += 2;
f[1][2] = 1;
s[mx][my] = 1;
for(int i = 1; i <= 8; i++) s[mx + fx[i]][my + fy[i]] = 1;
for(int i = 2; i <= bx; i++){
for(int j = 2; j <= by; j++){
if(s[i][j]){
f[i & 1][j] = 0;
continue;
}
f[i & 1][j] = f[(i - 1) & 1][j] + f[i & 1][j - 1];
}
}
printf("%lld\n", f[bx & 1][by]);
return 0;
}
输入:
6 6 3 3
输出:
————————————————
答案:
1.P9227 异或积
5 6 7 0
0 0 0 1
2.P1002 [NOIP2002 普及组] 过河卒
6