CSP-J普及组第一轮考试阅读程写结果专项训练(二)

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Da_秀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值