Atcoder Beginner Contest 364 A - C 题

本文代码亲测AC

如有不足,请指正

A题


代码

#include <bits/stdc++.h>
using namespace std;
int cnt;
int main(){
	int n;
	string ans = "Yes";
	cin >> n;
	for (int i = 1;i <= n;i ++){
		if (cnt == 2) ans = "No";
		string s;
		cin >> s;
		if (s == "sweet") cnt ++;
		else cnt = 0;
	}
	cout << ans;
}


解析

1 <= N <= 100,范围不大,直接记录当前连续吃甜菜数即可。


B题


代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char c[55][55];
int h,w,si,sj;
string x; 
int main(){
	cin >> h >> w >> si >> sj;
	for (int i = 1;i <= h;i ++)
		for (int j = 1;j <= w;j ++)
			cin >> c[i][j];
	cin >> x;
	int now_i = si,now_j = sj;
	for (int i = 0;i < x.size();i ++){
		int go_i = now_i,go_j = now_j;
		if (x[i] == 'U')
			go_i -= 1;
		else if (x[i] == 'D')
			go_i += 1;
		else if (x[i] == 'L')
			go_j -= 1;
		else
			go_j += 1;
		if (go_i >= 1 and go_i <= h and go_j >= 1 and go_j <= w and c[go_i][go_j] == '.')
			now_i = go_i,now_j = go_j;
	}
	cout << now_i << " " << now_j << endl;
}


解析

根据输入移动位置即可


C题


代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,x,y;
int A[222222],B[222222];
int main(){
	cin >> n >> x >> y;
	for (int i = 1;i <= n;i ++) cin >> A[i];
	for (int i = 1;i <= n;i ++) cin >> B[i];
	sort(A+1,A+n+1);
	reverse(A+1,A+n+1);
	sort(B+1,B+n+1);
	reverse(B+1,B+n+1);
	ll atry = 1,btry = 1;
	ll sum = 0;
	while (sum <= x){
		sum += A[atry],atry ++;
		if (atry == n + 1){
			atry = n+1;
			break;
		}
	} 
	sum = 0;
	while (sum <= y){
		sum += B[btry],btry ++;
		if (btry == n + 1){
			btry = n+1;
			break;
		}
	}
	cout << min(atry-1,btry-1);
	return 0;
}


解析

甜度数组从大往小排,一直加到总甜度>x;

咸度数组从大往小排,一直加到总咸度<y;

输出两种取法中小的一个即可


文章最后

你的点赞是我最大的动力

创作不易

点个小赞

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值