2024天梯赛赛后总结

L1-101 别再来这么多猫娘了!

这道题,没有考虑到

语文水平有待提升。

代码:

#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
#define endl '\n'
#define pq priority_queue
using namespace std;
typedef pair<int,int> pii;

void solve(){
	int n;
	cin >> n;
	vector<string>a(n);
	for(int i = 0;i < n;i ++){
		cin >> a[i];
	}
	int k;
	cin >> k;
	string s;
	char useless = cin.get();
	getline(cin, s);
	int cnt = 0;
	for(int i = 0;i < n;i ++){
		int len = a[i].size();
		for(int j = 0;j + len <= s.size();j ++){
			string t = s.substr(j, len);
			if(t == a[i]){
				s.replace(j, len, string(1, 1));
				cnt ++;
			}
		}
	}
	if(cnt < k){
		for(int i = 0;i < s.size();i ++){
			if(s[i] == 1){
				cout << "<censored>";
			}else{
				cout << s[i];
			}
		}
	}else{
        cout << cnt << endl;
		cout << "He Xie Ni Quan Jia!";
	}
}

signed main()
{
    int t = 1;
    while(t--)
    {
        solve();
    }
    return 0;
}
  

L2-049 鱼与熊掌

这道题忘记set还有count函数,直接用二分来做有一个样例超时

代码:

#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
#define endl '\n'
#define pq priority_queue
using namespace std;
typedef pair<int,int> pii;

void solve(){
	int n, m;
	cin >> n >> m;
	set<int>a[m + 1];
	for(int i = 0;i < n;i ++){
		int k;
		cin >> k;
		while(k --){
			int x;
			cin >> x;
			a[x].insert(i);
		}
	}
	int q;
	cin >> q;
	while(q --){
		int x, y;
		cin >> x >> y;
		int cnt = 0;
		for(auto fx : a[x]){
			if(a[y].count(fx))
				cnt ++;
		}
		cout << cnt << endl;
	}
}

signed main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t = 1;
    while(t--)
    {
        solve();
    }
    return 0;
}
  

L2-050 懂蛇语

这个题忽略了每个字符串第一个字符可能是空格。

代码:

#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
#define endl '\n'
#define pq priority_queue
using namespace std;
typedef pair<int,int> pii;
map<string, vector<string>>mp;

void solve(){
	int n;
	cin >> n;
	getchar();
	for(int k = 0;k < n;k ++){
		string s;
		getline(cin, s);
		string t = "";
        if(s[0] != ' ')
            t += s[0];
		for(int i = 0;i < s.size();i ++){
			if(s[i - 1] == ' ' && s[i] != ' '){
				t += s[i];
			}
		}
		mp[t].push_back(s);
        // cout << t <<  ' ' << s << endl;
	}
    for(auto &[x, y] : mp){
        sort(y.begin(), y.end());
    }
	int k;
	cin >> k;
	getchar();
	while(k --){
		string s;
		getline(cin, s);
		string t = "";
		if(s[0] != ' ')
            t += s[0];
		for(int i = 0;i < s.size();i ++){
			if(s[i - 1] == ' ' && s[i] != ' '){
				t += s[i];
			}
		}
        // cout << t << endl;
		if(mp.count(t)){
			for(int i = 0;i < mp[t].size();i ++){
				if(i == 0)
					cout << mp[t][i];
				else
					cout << '|' << mp[t][i];
			}cout << endl;
		}else{
			cout << s << endl;
		}
	}
}

signed main()
{
    // ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t = 1;
    while(t--)
    {
        solve();
    }
    return 0;
}
  

L3-037 夺宝大赛

这个题当时读错题了,以为在空地相遇也会死亡,结果只有在大本营相遇才会死亡。

代码:从大本营跑bfs

#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
#define endl '\n'
#define pq priority_queue
using namespace std;
typedef pair<int,int> pii;
map<string, vector<string>>mp;
int n, m;
int a[110][110];
int dist[110][110];

int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};

bool cmp(pii a,pii b){
	if(a.first != b.first)
		return a.first > b.first;
	return a.second > b.second;
}

void solve(){
	cin >> n >> m;
	int rx, ry;
	for(int i = 0;i < n;i ++){
		for(int j = 0;j < m;j ++){
			cin >> a[i][j];
			if(a[i][j] == 2){
				rx = i;
				ry = j;
			}
		}
	}
	int k;
	cin >> k;
	memset(dist, -1, sizeof dist);
	dist[rx][ry] = 0;
	queue<pair<int,int>>q;
	q.push({rx, ry});
    // cout << rx << ' ' << ry << endl;
	while(q.size()){
		auto [x0,y0] = q.front();
		q.pop();
		for(int i = 0;i < 4;i ++){
			int x = x0 + dx[i], y = y0 + dy[i];
			if(x < 0 || y < 0 || x >= n || y >= m)
				continue;
 			if(dist[x][y] != -1 || a[x][y] == 0)
 				continue;
 			dist[x][y] = dist[x0][y0] + 1;
            // cout << x << ' ' << y << ' ' << dist[x][y] << endl;
 			q.push({x, y});
		}
	}
	vector<pair<int,int>>e(k);
    // cout << k << endl;
	for(int i = 0;i < k;i ++){
		int x, y;
        cin >> x >> y;
		x --, y --;
		e[i] = {dist[y][x], i};
        // cout << x << ' ' << y << ' ' << dist[x][y] << ' ' << i << endl;
	}
	sort(e.begin(), e.end(), cmp);
	while(e.size()){
		auto [d, i] = e.back();
		e.pop_back();
		if(d != -1){
			bool ok = true;
			while(e.size() && e.back().first == d){
				ok = false;
				e.pop_back();
			}
			if(ok){
				cout << i + 1 << ' ' << d << endl;
				return;
			}
		}
	}
	cout << "No winner.\n";
}

signed main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t = 1;
    while(t--)
    {
        solve();
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

临江浪怀柔ℳ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值