Codeforces 336C

这题是大一暑假时候做的,当时没有出,直到今天突然觉得应该把没过的题目再做一边,不然真的是越积越多。

现在能够独立做出来真的是难以表达的兴奋,刚开始的时候就觉得 O(30 * 30 * n)的复杂度有点不安全,不过还是敲了,事实说明实际的负责度没这么高。和去年一样,没有思路,后来仔细一想,真的是数学题。现在感觉爱上了Math...


附上代码:

#include <cstdio>
#include <cstring>

// 保存原始数组
int b[100005];
// a[i][j]表示b[i]的二进制表示法中的各个位上的数值, 而able数组保存的是每一轮中可以选的标记
bool a[100005][32], able[100005];
int n;

int main(void) {
	while (~scanf("%d", &n) && n) {
		memset(a, false, sizeof(a));
		for (int i = 0; i < n; i++) {
			int x;
			scanf("%d", &x);
			b[i] = x;
			for (int j = 30; j >= 0; j--) {
				if ((1 << j) & x)
					a[i][30-j] = true;
			}
		}

		int cnt;
		for (int i = 0; i <= 30; i++) {
			cnt = 0;
			memset(able, false, sizeof(able));
			for (int j = 0; j < n; j++) {
				if ( a[j][i] ) {
					able[j] = true;
					cnt++;
				}
			}
			if (cnt == 0) continue;

			int j;
			for (j = i + 1; j <= 30; j++) {
				int f = 0;
				for (int k = 0; k < n; k++) {
					if ( able[k] ) {
						if ( !a[k][j] ) {
							f = 1;
							break;
						}
					}
				}
				if (f == 0)
					break;
			}
			if (j > 30)
				break;
		}
		printf("%d\n", cnt);
		int flag = 0;
		for (int i = 0; i < n; i++) {
			if ( able[i] ) {
				if (flag) 
					printf(" ");
				flag = 1;
				printf("%d", b[i]);
			}
		}
		puts("");
	}

	return 0;
}


### Codeforces Problem 1332C Explanation The provided references pertain specifically to problem 742B on Codeforces rather than problem 1332C. For an accurate understanding and solution approach for problem 1332C, it's essential to refer directly to its description and constraints. However, based on general knowledge regarding competitive programming problems found on platforms like Codeforces: Problem 1332C typically involves algorithmic challenges that require efficient data structures or algorithms such as dynamic programming, graph theory, greedy algorithms, etc., depending upon the specific nature of the task described within this particular question[^6]. To provide a detailed explanation or demonstration concerning **Codeforces problem 1332C**, one would need direct access to the exact statement associated with this challenge since different tasks demand tailored strategies addressing their unique requirements. For obtaining precise details about problem 1332C including any sample inputs/outputs along with explanations or solutions, visiting the official Codeforces website and navigating to contest number 1332 followed by examining section C is recommended. ```python # Example pseudo-code structure often seen in solving competitive coding questions. def solve_problem_1332C(input_data): # Placeholder function body; actual logic depends heavily on the specifics of problem 1332C. processed_result = process_input(input_data) final_answer = compute_solution(processed_result) return final_answer input_example = "Example Input" print(solve_problem_1332C(input_example)) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值