20/08/02测试

T1

考场代码:

#include <bits/stdc++.h>
using namespace std;

template<typename temp>temp read(temp &x){
	x = 0;temp f = 1;char ch;
	while(!isdigit(ch = getchar())) (ch == '-') and (f = -1);
	for(x = ch^48; isdigit(ch = getchar()); x = (x<<1)+(x<<3)+(ch^48));
	return x *= f;
}
template <typename temp, typename ...Args>void read(temp& a, Args& ...args){read(a), read(args...);}

const int maxn = 1e6+10;

int n, ans, pos[2][maxn];

signed main(){
	freopen("distance.in", "r", stdin);
	freopen("distance.out", "w", stdout);
	read(n);
	for(int i = 1, cmp; i <= n; i ++) pos[0][read(cmp)] = i;
	for(int i = 1, cmp; i <= n; i ++) pos[1][read(cmp)] = i;
	for(int i = 1; i <= n; i ++){
		for(int j = 1; j <= n; j ++){
			if(i == j) continue;
			else ans = max(abs(pos[0][i]-pos[0][j])+abs(pos[1][i]-pos[1][j]), ans);
		}
	}
	printf("%d", ans);
	return 0;
}

挺简单的思路qwq,在AK爷Tethys的指导下解决了问题orz%%%。

代码:

#include <bits/stdc++.h>
using namespace std;

template<typename temp>temp read(temp &x){
	x = 0;temp f = 1;char ch;
	while(!isdigit(ch = getchar())) (ch == '-') and (f = -1);
	for(x = ch^48; isdigit(ch = getchar()); x = (x<<1)+(x<<3)+(ch^48));
	return x *= f;
}
template <typename temp, typename ...Args>void read(temp& a, Args& ...args){read(a), read(args...);}

const int maxn = 1e6+10;

int n, ans, a[maxn], pos[maxn], minn = 1<<29, maxnn, maxx, minx = 1<<29;

signed main(){
	freopen("distance.in", "r", stdin);
	freopen("distance.out", "w", stdout);
	read(n);
	for(int i = 1; i <= n; i ++) read(a[i]);
	for(int i = 1, cmp; i <= n; i ++) pos[read(cmp)] = i;
	for(int i = 1; i <= n; i ++){
		maxnn = max(maxnn, i+pos[a[i]]);
		minn = min(minn, i+pos[a[i]]);
		maxx = max(maxx, i+n-pos[a[i]]+1);
		minx = min(minx, i+n-pos[a[i]]+1);
		ans = max(ans, maxnn - minn);
		ans = max(ans, maxx - minx);
	}
	printf("%d", ans);
	return 0;
}

T2

考场代码:

#include <bits/stdc++.h>
using namespace std;

template<typename temp>void read(temp &x){
	x = 0;temp f = 1;char ch;
	while(!isdigit(ch = getchar())) (ch == '-') and (f = -1);
	for(x = ch^48; isdigit(ch = getchar()); x = (x<<1)+(x<<3)+(ch^48));
	x *= f;
}
template <typename temp, typename ...Args>void read(temp& a, Args& ...args){read(a), read(args...);}

const int mod = 998244353, maxn = 1000010;

#define ll long long

int t;

ll ans, jc[maxn], pi[maxn];

ll fast(ll a, ll b){
	ll ans = 1;
	while(b){
		if(b&1) ans = (a%mod)*(ans%mod);
		a = (a%mod)*(a%mod);
		b >>= 1;     
	}
	return ans%mod;
}

ll slow(ll a, ll b){
	ll ans = 0;
	while(b){
		if(b&1) ans = (ans+a)%mod;
		a = (a*2)%mod;
		b >>= 1;
	}
	return ans%mod;
}

ll C(int n, int m){
	if(!n) return 1;
	if(n < m) return 1;
	return slow(jc[n],slow(fast(jc[m],mod-2), fast(jc[n-m], mod-2)));
}

signed main(){
	freopen("number.in", "r", stdin);
	freopen("number.out", "w", stdout);
	read(t);
	jc[0] = 1;
	for(int i = 1; i <= 1000000; i ++) jc[i] = ((i%mod)*(jc[i-1]%mod))%mod;
	for(int i = 1, x, y, z; i <= t; i ++){
		read(x, y, z);
		ans = 0;
		for(int j = 0; j <= x; j ++){
			ans += slow(C(x,j),C(y,z+j))%mod;
		}
		printf("%lld\n", ans);
	}
	return 0;
}

T3

考场代码:

#include <bits/stdc++.h>
using namespace std;

template<typename temp>temp read(temp &x){
	x = 0;temp f = 1;char ch;
	while(!isdigit(ch = getchar())) (ch == '-') and (f = -1);
	for(x = ch^48; isdigit(ch = getchar()); x = (x<<1)+(x<<3)+(ch^48));
	return x *= f;
}
template <typename temp, typename ...Args>void read(temp& a, Args& ...args){read(a), read(args...);}

const int maxn = 1e5+10;

int n, t, val[maxn];

signed main(){
	freopen("phone.in", "r", stdin);
	freopen("phone.out", "w", stdout);
	read(n, t);
	for(int i = 1; i <= n; i ++) read(val[i]);
	for(int a, b; t; t --){
		read(a, b);
		int ans = 0;
		for(int i = 1; i <= n; i ++)
			if((val[i] xor a) <= b) ans ++;
		printf("%d\n", ans);
	}
	return 0;
}

最近一直在考炸,是不是要反思一下啦qwq??

posted @ 2020-08-02 11:01  Vanyun  阅读(104)  评论(2编辑  收藏  举报