Educational Codeforces Round 129 (Rated for Div. 2) 补题题解


有段时间没练了,十几分钟过一道题本来还兴奋呢,第二道直接卡死,还是继续努力吧

A - Game with Cards

简单题
思路:对两人的牌进行排序,谁有最大牌且先出则能赢

#include<bits/stdc++.h>

using namespace std;

const int N = 1010;

int n, m;
int T;
int a[N];
int b[N];

int main()
{
	cin>>T;
	while(T -- ){
		cin>>n;
		for(int i = 0; i < n; i ++ ){
			cin>>a[i];
		}
		
		cin>>m;
		for(int i = 0; i < m; i ++ ){
			cin>>b[i];
		}
		
		sort(a, a + n);
		sort(b, b + m);
		
		if(a[n - 1] > b[m - 1]){
			cout<<"Alice"<<endl;
			cout<<"Alice"<<endl;
		}
		else if(a[n - 1] == b[m - 1]){
			cout<<"Alice"<<endl;
			cout<<"Bob"<<endl;
		}
		else if(a[n - 1] < b[m - 1]){
			cout<<"Bob"<<endl;
			cout<<"Bob"<<endl;
		}
	}
	return 0;
}

B - Card Trick

思维题,刚开始没想出来,看题解也不太明白,感谢大佬点拨
思路:考虑当b1+b1=n时,相当于不改变数组,所以把b数组所有数加起来对n取模,剩下哪个数就是会对数组造成影响的,假如剩下的是3,对将数组前三个数翻转后,最上面的数刚好是a[3](下标为3),所以答案就出来了,记住考虑范围,对b数组累加这一步会爆int,所以直接用过long long

#include<bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;

int a[N], b[N];
int t, n, m;

int main()
{
	cin>>t;
	while(t -- ){
		long long sum = 0;
		cin>>n;
		for(int i = 0; i < n; i ++ ){
			cin>>a[i];
		}
		cin>>m;
		for(int i = 0; i < m; i ++ ){
			cin>>b[i];
			sum += b[i];
		}
		cout<<a[sum % n]<<endl;
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值