Educational Codeforces Round 178 (Rated for Div. 2)

目录

A. Three Decks

题目:

代码: 

无注释版:

有注释版:

B. Move to the End

题目:​编辑

代码:

无注释版:

有注释版:

C. Card Game

题目:​编辑

代码:

无注释版:

有注释版:


A. Three Decks

题目:

代码: 

无注释版:

#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		int a,b,c;
		cin>>a>>b>>c;
		int s=a+b+c;
		if(s%3!=0){
			cout<<"NO\n";
			continue;
		}
		int r=s/3;
		if(a<=r&&b<=r&&c>=r){
			cout<<"YES\n";
		}
		else cout<<"NO\n";
	}
} 

有注释版:

#include<bits/stdc++.h> 
// 引入所有标准库头文件,包含了常用的输入输出流、容器、算法等
using namespace std;

int main(){
    int t;
    cin >> t; 
    // 输入测试用例的数量 t
    while(t--){
        int a, b, c;
        cin >> a >> b >> c; 
        // 输入三副牌的数量 a, b, c,其中 a < b < c

        int s = a + b + c;
        // 计算三副牌的总数 s

        if(s % 3 != 0){
            cout << "NO\n";
            // 如果三副牌的总数不是 3 的倍数,则不可能将牌分成三份相等的数量,输出 NO
            continue;
        }

        int r = s / 3;
        // 计算每一副牌最终应该有的数量 r,即总牌数除以 3

        if(a <= r && b <= r && c >= r){
            cout << "YES\n";
            // 判断条件:第一副牌的数量 a 不大于 r,第二副牌的数量 b 不大于 r,第三副牌的数量 c 不小于 r
            // 如果满足条件,说明可以通过从第三副牌中抽取牌并合理分配,使得每副牌的数量相等
        }
        else cout << "NO\n";
        // 如果不满足上述条件,输出 NO
    }
}

B. Move to the End

题目:

代码:

无注释版:

#include<bits/stdc++.h>
using namespace std;
#define int long long
int a[200010],s[200010],b[200010];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		memset(b,0,sizeof(b));
		memset(s,0,sizeof(s));
		int n;
		cin>>n;
		for(int i=1;i<=n;i++){
			cin>>a[i];
		}
		int ma=0;
		for(int i=1;i<=n;i++){
			if(a[i]>ma){
				ma=a[i];
				s[i]=ma;
			}
			else s[i]=s[i-1];
		}
		for(int i=n;i>=1;i--){
			b[i]=b[i+1]+a[i];
		}
		for(int k=1;k<=n;k++){
			int ans=0;
			ans+=b[n-k+2];
			ans+=s[n-k+1];
			cout<<ans<<" "; 
		}
		cout<<"\n";
	}
}

有注释版:

#include<bits/stdc++.h>
using namespace std;
#define int long long
// 使用 long long 类型来避免溢出问题
int a[200010], s[200010], b[200010];
// 数组 a 存储输入的整数,s 和 b 用于存储中间结果

signed main(){
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0); 
    // 优化输入输出流,避免每次操作都刷新缓冲区

    int t;
    cin >> t; 
    // 读取测试用例的数量 t

    while(t--){
        memset(b, 0, sizeof(b)); 
        memset(s, 0, sizeof(s)); 
        // 将数组 b 和 s 初始化为 0,以防上次测试用例的结果影响当前测试

        int n;
        cin >> n; 
        // 读取数组的大小 n

        for(int i = 1; i <= n; i++){
            cin >> a[i]; 
        }
        // 输入数组 a 中的元素

        int ma = 0;
        // ma 用来记录到目前为止出现过的最大值

        for(int i = 1; i <= n; i++){
            if(a[i] > ma){
                ma = a[i]; 
                s[i] = ma; 
            }
            else s[i] = s[i - 1];
        }
        // 填充数组 s。s[i] 保存从第 1 个元素到第 i 个元素中出现的最大值。
        // 如果 a[i] 比之前的最大值大,就更新 ma 和 s[i] 为 a[i]。
        // 否则,s[i] 就是之前的最大值。

        for(int i = n; i >= 1; i--){
            b[i] = b[i + 1] + a[i];
        }
        // 填充数组 b。b[i] 保存从第 i 个元素到最后一个元素的元素和。
        // 这可以理解为,b[i] 代表从 i 开始到数组末尾的元素和。

        for(int k = 1; k <= n; k++){
            int ans = 0;
            ans += b[n - k + 2]; 
            // b[n - k + 2] 是从 n - k + 2 到最后的元素和
            ans += s[n - k + 1]; 
            // s[n - k + 1] 是前 n - k + 1 个元素中的最大值
            cout << ans << " "; 
            // 输出每次操作后的可能的最大值
        }
        cout << "\n"; 
        // 输出每个测试用例的结果后换行
    }
}

C. Card Game

题目:

代码:

无注释版:

#include<bits/stdc++.h>
using namespace std;
map<int,int> ma,mb;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		if(s=="AB"){
			cout<<"Alice\n";
			continue;
		}
		if(s=="BA"){
			cout<<"Bob\n";
			continue;
		}
		s="?"+s;
		ma.clear();
		mb.clear();
		int mma=0;
		for(int i=1;i<=n;i++){
			if(s[i]=='A'){
				ma[i]++;
			}
			else{
				mb[i]++;
				mma=max(mma,i);
			}
		}
		if(ma.count(1)&&ma.count(n)||mb.size()==1){
			cout<<"Alice\n";
			continue;
		}
		int f=0;
		for(auto i:ma){
			if(i.first>mma&&i.first!=n){
				f=1;
				break;
			}
		}
		if(f) cout<<"Alice\n";
		else cout<<"Bob\n";
	}
}

有注释版:

#include<bits/stdc++.h>  // 引入头文件,包含常用的库
using namespace std;  // 使用标准命名空间

map<int,int> ma,mb;  // 使用map分别存储爱丽丝和鲍勃的牌,键是牌号,值是该牌出现的次数

int main(){
    ios::sync_with_stdio(0);  // 优化输入输出
    cin.tie(0);  // 解绑cin与cout,进一步优化性能
    cout.tie(0);  // 解绑cin与cout

    int t;  // 记录测试用例的个数
    cin >> t;  // 输入测试用例的个数

    while(t--){  // 处理每个测试用例
        int n;  // 记录牌的数量
        cin >> n;  // 输入牌的数量
        string s;  // 记录每张牌的分配情况
        cin >> s;  // 输入牌的分配情况,'A'表示爱丽丝拥有该牌,'B'表示鲍勃拥有该牌

        if(s == "AB"){  // 如果爱丽丝和鲍勃各有一张牌
            cout << "Alice\n";  // 爱丽丝直接获胜
            continue;  // 继续下一个测试用例
        }

        if(s == "BA"){  // 如果鲍勃和爱丽丝各有一张牌
            cout << "Bob\n";  // 鲍勃直接获胜
            continue;  // 继续下一个测试用例
        }

        s = "?" + s;  // 在字符串前加上一个"?",因为牌的编号从1开始,方便后续处理

        ma.clear();  // 清空爱丽丝的牌
        mb.clear();  // 清空鲍勃的牌
        int mma = 0;  // 记录鲍勃拥有的最大的牌号

        // 遍历所有牌,根据分配情况统计爱丽丝和鲍勃各自拥有的牌
        for(int i = 1; i <= n; i++){
            if(s[i] == 'A'){  // 如果爱丽丝拥有这张牌
                ma[i]++;  // 将这张牌加入爱丽丝的牌
            }
            else{  // 如果鲍勃拥有这张牌
                mb[i]++;  // 将这张牌加入鲍勃的牌
                mma = max(mma, i);  // 更新鲍勃的最大牌号
            }
        }

        // 判断特殊情况:如果爱丽丝有牌1且有牌n,或者鲍勃只有一张牌
        if(ma.count(1) && ma.count(n) || mb.size() == 1){
            cout << "Alice\n";  // 特殊情况下,爱丽丝获胜
            continue;  // 继续下一个测试用例
        }

        int f = 0;  // 用于标记是否找到特殊情况
        // 遍历爱丽丝的牌
        for(auto i : ma){
            if(i.first > mma && i.first != n){  // 如果爱丽丝拥有的牌的编号大于鲍勃的最大牌号且不等于n
                f = 1;  // 设定标记f为1
                break;  // 跳出循环
            }
        }

        if(f)  // 如果标记f为1
            cout << "Alice\n";  // 爱丽丝获胜
        else
            cout << "Bob\n";  // 否则,鲍勃获胜
    }
}
"educational codeforces round 103 (rated for div. 2)"是一个Codeforces平台上的教育性比赛,专为2级选手设计评级。以下是有关该比赛的回答。 "educational codeforces round 103 (rated for div. 2)"是一场Codeforces平台上的教育性比赛。Codeforces是一个为程序员提供竞赛和评级的在线平台。这场比赛是专为2级选手设计的,这意味着它适合那些在算法数据结构方面已经积累了一定经验的选手参与。 与其他Codeforces比赛一样,这场比赛将由多个问题组成,选手需要根据给定的问题描述和测试用例,编写程序来解决这些问题。比赛的时限通常有两到三个小时,选手需要在规定的时间内提交他们的解答。他们的程序将在Codeforces的在线评测系统上运行,并根据程序的正确性和效率进行评分。 该比赛被称为"educational",意味着比赛的目的是教育性的,而不是针对专业的竞争性。这种教育性比赛为选手提供了一个学习和提高他们编程技能的机会。即使选手没有在比赛中获得很高的排名,他们也可以从其他选手的解决方案中学习,并通过参与讨论获得更多的知识。 参加"educational codeforces round 103 (rated for div. 2)"对于2级选手来说是很有意义的。他们可以通过解决难度适中的问题来测试和巩固他们的算法和编程技巧。另外,这种比赛对于提高解决问题能力,锻炼思维和提高团队合作能力也是非常有帮助的。 总的来说,"educational codeforces round 103 (rated for div. 2)"是一场为2级选手设计的教育性比赛,旨在提高他们的编程技能和算法能力。参与这样的比赛可以为选手提供学习和进步的机会,同时也促进了编程社区的交流与合作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值