Educational Codeforces Round 65 (Rated for Div. 2)

本文解析了三道编程题目,包括交互式的数列求解、并查集的应用于新闻分配问题,以及双色RBS字符串的最小嵌套层数求解。通过具体的代码示例,展示了如何使用全排列、并查集和计数策略解决问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

B - Lost Numbers(交互题)

题意:你输入一个询问值i,j然后电脑返回两个值相乘的结果,最后输出符合该结果的数列(6个数)。
题解:固定询问数然后用全排列看看矛不矛盾就行,就是第一次遇到交互题一开始以为是电脑给数然后自己猜数列。。。。。。。。

#include <cstdio>
#include <algorithm>
#include <stdio.h>
using namespace std ; 
int num[7] = {4,8,15,16,23,42} ;
int main(){
	int a , b , c , d ;
	printf ("? 1 2\n") ;
	fflush(stdout);
	scanf ("%d",&a) ;
	printf ("? 2 3\n") ;
	fflush(stdout) ;
	scanf ("%d",&b) ; 
	printf ("? 4 5\n") ;
	fflush(stdout);
	scanf ("%d",&c) ; 
	printf ("? 5 6\n") ;
	fflush(stdout); 
	scanf ("%d",&d) ;
	do{
		if (num[0]*num[1] != a)	continue ; 
		if (num[1]*num[2] != b)	continue ; 
		if (num[3]*num[4] != c)	continue ; 
		if (num[4]*num[5] != d)	continue ; 
                break ; 		
	}while(next_permutation(num,num+6)) ;
	printf ("! ") ;
	for (int i = 0 ; i < 7 ; ++ i)
		printf ("%d ",num[i]) ;
	return 0 ; 
}
C - News Distribution(并查集)

题意:给出每个团体内所含人的编号,最后输出每个人所在团体有几个人
题解:并查集板子。

#include <cstdio>
const int N = 5e5 + 5 ; 
int s[N] , num[N] ; 
int find(int x){
	if (x != s[x])
		s[x] = find(s[x]) ; 
	return s[x] ; 
}
void built(int x , int y){
	x = find(s[x]) , y = find(s[y]) ; 
	if (x != y){
		if (num[x] >= num[y]){
			s[y] = x ; 
			num[x] += num[y] ; 
		}
		else{
			s[x] = y ; 
			num[y] += num[x] ; 
		}
	}
}
int main(){
	int n , m ; 
	scanf ("%d%d",&n,&m) ;
	for (int i = 1 ; i <= n ; ++ i){
		s[i] = i ; 
		num[i] = 1 ; 
	}
	while(m--){
		int t , x , y ; 
		scanf ("%d",&t) ;
		if (t > 0)	scanf ("%d",&x) ;
		-- t ; 
		for (int i = 0 ; i < t ; ++ i){
			scanf ("%d",&y) ;
			built(x,y) ; 
		}
	}
	for (int i = 1 ; i <= n ; ++ i){
		int x = find(i) ; 
		printf ("%d ",num[x]) ;
	}
	return 0 ; 
}
D - Bicolored RBS

题意:给出一串只含()的字符串,问最小的最大嵌套有几重,并且用0/1表示,另外的用1/0表示。
题解:比赛看了老半天不知道是啥意思。。。。。。。。,偷看大佬题解,就是用cnt统计括号‘(’就++ , ‘)’就–,然后用01交替插入。

#include <iostream>
#include <string>
using namespace std ; 
int main(){
	int n ; 
	string s ; 
	cin >> n >> s ; 
	int cnt = 0 ;
	for (int i = 0 ; i < n ; ++ i){
		if (s[i] == '('){
			cout << cnt%2 ; 
			++ cnt ; 
		}
		else{
			-- cnt ; 
			cout << cnt%2 ; 
		}
	}
	return 0 ; 
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值