(补一年前的题)GLPT团队程序设计天梯赛 2023正式赛

L2-046 天梯赛的赛场安排

读懂题目最重要!!!

#include<bits/stdc++.h>
//unordered_map hash
//priority_queue<int,vector<int>,greater<int>>
//deque front back
#define endl '\n'
#define PII pair<int,int>
//#define int long long
//#define int __int128
using namespace std;
inline int read();
inline void write(int x);
string s[5005];
int a[5005];
int cnt[5005];
int res[5005];
int idx;
void solve(){
    int n = read(), c = read();
    priority_queue<PII> q;
    for(int i = 1; i <= n; ++ i){
        cin >> s[i] >> a[i];
        q.push({a[i], i});
    }
    int sum = 0;
    while(q.size()){
        int v = q.top().first, id = q.top().second;
        q.pop();
        if(v >= c){
            cnt[id] ++;
            v -= c;
            if(v){
                q.push({v, id});
            }
            ++ sum;
        }
        else{
            int f = 0;
            for(int i = 1; i <= n; ++ i){
                if(res[i] >= v){
                    f = 1;
                    res[i] -= v;
                    if(id != i){
                        cnt[id] ++;
                    }
                    break;
                }
            }
            if(!f){
                res[id] = c - v; 
                cnt[id] ++;
                ++ sum;
            }
        }
    }
    
    for(int i = 1; i <= n; ++ i){
        cout << s[i] << ' ' << cnt[i] << endl;
    }
    cout << sum;
    
    
    
}
signed main(){
	int _ = 1;
	while(_ --) solve();

	return 0;
}
inline int read(){
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return x*f;
}
inline void write(int x){
	if(x < 0) putchar('-'), x = - x;
	if(x > 9) write(x / 10);
	putchar('0' + x % 10);
}

L2-048 寻宝图

因为图的大小满足N*M \leqslant 10{^{5}},所以需要动态开辟空间

#include<bits/stdc++.h>
//unordered_map hash
//priority_queue<int,vector<int>,greater<int>>
//deque front back
#define endl '\n'
#define PII pair<int,int>
//#define int long long
//#define int __int128
using namespace std;
inline int read();
inline void write(int x);
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
vector<char> g[100005];
vector<int> st[100005];
int land, val;
int n, m;
void bfs(int x1, int y1, int flag){
    if(flag) ++ val;
    ++ land;

    queue<PII> q;
    q.push({x1, y1});
    st[x1][y1] = 1;
    while(q.size()){
        
        int x = q.front().first, y = q.front().second;
        q.pop();
        
        for(int i = 0; i < 4; ++ i){
            int xx = x + dx[i];
            int yy = y + dy[i];
            if(xx >= 1 && xx <= n && yy >= 1 && yy <= m && g[xx][yy] != '0' && !st[xx][yy]){
                if(g[xx][yy] != '1' && !flag){
                    ++ val;
                    flag = 1;
                }
                q.push({xx, yy});
                st[xx][yy] = 1;
            }
        }
    }
}
void solve(){
    n = read(), m = read();
    for(int i = 1; i <= n; ++ i){
        g[i].resize(m + 1);
        st[i].resize(m + 1);
        for(int j = 1; j <= m; ++ j){
            cin >> g[i][j];
        }
    }
    for(int i = 1; i <= n; ++ i){
        for(int j = 1; j <= m; ++ j){
            if(!st[i][j] && g[i][j] != '0'){
                if(g[i][j] == '1'){
                    bfs(i, j, 0);
                }
                else{
                    bfs(i, j, 1);
                }
                // cout << i << ' ' << j << endl;
            }
        }
    }
    write(land);
    putchar(' ');
    write(val);

}
signed main(){
	int _ = 1;
	while(_ --) solve();

	return 0;
}
inline int read(){
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return x*f;
}
inline void write(int x){
	if(x < 0) putchar('-'), x = - x;
	if(x > 9) write(x / 10);
	putchar('0' + x % 10);
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值