XCPC集训49

A - Make postcards

signed main() {
	int T = read();
	while(T--) {
		int a = read(), b = read(), n = read();
		int cnt = 0;
		while(a % 2 == 0) {
			cnt++;
			a /= 2;
		} 
		while(b % 2 == 0) {
			cnt++;
			b /= 2; 
		}
		int ans = pow(2, cnt);
		if(ans >= n) puts("YES");
		else puts("NO");
	} 
	return 0;
}

B - Fair Division

signed main() {
	int T = read();
	while(T--) {
		int n = read();
		int sum = 0;
		int cnt_1 = 0, cnt_2 = 0; 
		for(int i = 0; i < n; i++) {
			int x = read();
			sum += x;
			if(x == 1) cnt_1 ++;
			else cnt_2 ++;
		}
		if(sum % 2) {
			puts("NO");
			continue;
		}
		bool success = true;
		if(cnt_1 % 2) success = false;
		else if(cnt_1 == 0 && cnt_2 % 2) success = false;
		if(success) puts("YES");
		else puts("NO");
	}
	return 0;
}

C - Long Jumps

思路:

从前往后不好搞,从后往前。

代码:

signed main() {
	int T = read();
	while(T--) {
		int n = read();
		for(int i = 1; i <= n; i++) w[i] = read(), pos[i] = i + w[i];
		int ans = 0;
		for(int i = n; i >= 1; i--) {
			if(i + w[i] <= n) w[i] += w[i + w[i]];
			ans = max(ans, w[i]);
			//cout << w[i] << endl;
		}
		cout << ans << endl;
	}
	return 0;
}

D - Wizard of Orz

int main() {
	int T = read();
	while(T--) {
		int n = read();
		if(n == 1) cout << 9 << endl;
		else if(n == 2) cout << 98 << endl;
		else if(n == 3) cout << 989 << endl;
		else {
			cout << 989;
			n -= 3;
			int a = n / 10, b = n % 10;
			for(int i = 1; i <= a; i++)
				for(int j = 0; j <= 9; j++)
					cout << j;
			for(int i = 0; i <= 9 && b > 0; i++, b--) 
				cout << i;
			cout << endl;
		}
	}
	return 0;
}

E - Even-Odd Game

思路:

两个人都尽量拿大的,所以把数组从大到小排序,能取就取,换句话说,不让对方取到就等于自己取到该数。

代码:

signed main() {
	int T = read();
	while(T--) {
		int n = read();
		for(int i = 0; i < n; i++) 
			w[i] = read();
		int A = 0, B = 0;
		sort(w, w + n, cmp);
		for(int i = 0; i < n; i++) {
			if(i % 2 == 0 && w[i] % 2 == 0) A += w[i];
			else if(i % 2 == 1 && w[i] % 2 == 1) B += w[i]; 
		}
		if(A > B) puts("Alice");
		else if(A < B) puts("Bob");
		else puts("Tie"); 
	}
	return 0;
}

F - Hills And Valleys

思路:

改变的只会影响左右两边。

代码:

/*
	qwq!
*/

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <unordered_map>
using namespace std;
#define pb push_back
#define pu push
#define fi first
#define se second
#define LL long long
#pragma GCC optimize(2)
#define IOS ios::sync_with_stdio(false); std::cin.tie(0),cout.tie(0);
//#define int long long
//#define int __int64
typedef pair<int,int> PII;
const int INF = 0x3f3f3f3f, mod = 1e9 + 7, INF_MAX = 0x7fffffff;
const int N = 3e5 + 10;
//int h[N], e[N], ne[N], idx;
int w[N];
bool st[N];
int n;

inline int read () {
	int k=0,f=1;
	char c=getchar ();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar ();}
	while (c>='0'&&c<='9') {k=k*10+c-'0';c=getchar ();}
	return k*f;
}

inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10-'0');
    return;
}

inline bool check(int i) {
	if(i == 1 || i == n) return false;
	if(w[i] > w[i-1] && w[i] > w[i + 1]) {
		return true;
	}else if(w[i] < w[i-1] && w[i] < w[i+1]) {
		return true;
	}
	return false;
}

int main() {
	int T = read();
	while(T--) {
		n = read(); 
		memset(st, 0, sizeof st);
		for(int i = 1; i <= n; i++) w[i] = read();
		int cnt = 0;
		int max_cnt = 0; 
		for(int i = 2; i < n; i ++) {
			if(check(i)) {
				cnt++;
				st[i] = 1;
			} 
		}
		for(int i = 2; i < n; i++) {
			int t =  w[i];
			int x = st[i] + st[i-1] + st[i+1];
			w[i] = w[i-1]; max_cnt = max(max_cnt, x - (check(i-1) + check(i) + check(i+1)));
			w[i] = w[i+1]; max_cnt = max(max_cnt, x - (check(i-1) + check(i) + check(i+1)));
			w[i] = t; 
		}
		printf("%d\n", cnt - max_cnt);
	}
	return 0;
}

H - Number of Triplets

思路:暴力枚举

代码:

/*
	qwq!
*/

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <unordered_map>
using namespace std;
#define pb push_back
#define pu push
#define fi first
#define se second
#define LL long long
#pragma GCC optimize(2)
#define IOS ios::sync_with_stdio(false); std::cin.tie(0),cout.tie(0);
//#define int long long
//#define int __int64
typedef pair<int,int> PII;
const int INF = 0x3f3f3f3f, mod = 1e9 + 7, INF_MAX = 0x7fffffff;
const int N = 2e5 + 10;
//int h[N], e[N], ne[N], idx;
PII w[N];
map<PII, int>mp;


inline int read () {
	int k=0,f=1;
	char c=getchar ();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar ();}
	while (c>='0'&&c<='9') {k=k*10+c-'0';c=getchar ();}
	return k*f;
}

inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10-'0');
    return;
}


int main() {
	int n = read();
	for(int i = 0; i < n; i++) {
		w[i].first = read(), w[i].second = read();
		PII t = {w[i].first * 2, w[i].second * 2};
		mp[t] = 1;
	}
	int ans = 0;
	for(int i = 0; i < n; i++)
		for(int j = i + 1; j < n; j++) {
			int x = w[i].first + w[j].first;
			int y = w[i].second + w[j].second;
			PII t = {x,y};
			if(mp.count(t)) {
				ans++;
			}
		}
	cout << ans << endl;
	return 0;
}
posted @   飘向远方丶  阅读(18)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
点击右上角即可分享
微信分享提示