19723分布式队列

19723分布式队列

⭐️难度:中等

🌟考点:模拟、2024省赛

📖

📚

java 复制代码
import javax.sound.sampled.Line;
import java.math.BigInteger;

import java.util.Arrays;
import java.util.Scanner;


public class  Main {
    static int N = 100010;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] count = new int[n + 1]; // 记录分布式队列的元素个数
        while(sc.hasNext()){
            String str = sc.next();
            if(str.equals("add")){
                int x = sc.nextInt();
                count[0] ++; // add操作都是主队列加
            } else if (str.equals("sync")) {
                int x = sc.nextInt();
                count[x] = Math.min(count[x] + 1,count[0]); // 副队列元素个数不可能超过主队列
            }else if(str.equals("query")){
                int min = count[0]; // 先假定同步个数是最多的,再在遍历的过程中找最小的
                for (int i = 1; i < n; i++) {
                    min = Math.min(min,count[i]);
                }
                System.out.println(min);
            }
        }
    }
}
相关推荐
写代码的【黑咖啡】24 分钟前
如何在大数据数仓中搭建数据集市
大数据·分布式·spark
SoleMotive.2 小时前
kafka选型
分布式·kafka
小二·4 小时前
MyBatis基础入门《十五》分布式事务实战:Seata + MyBatis 实现跨服务数据一致性
分布式·wpf·mybatis
feathered-feathered6 小时前
Redis基础知识+RDB+AOF(面试)
java·数据库·redis·分布式·后端·中间件·面试
lang201509286 小时前
深入解析Kafka Broker核心读写机制
分布式·kafka
lang201509286 小时前
Kafka高水位与日志末端偏移量解析
分布式·kafka
Tadas-Gao7 小时前
GraphQL:下一代API架构的设计哲学与实践创新
java·分布式·后端·微服务·架构·graphql
lang201509287 小时前
Kafka副本管理核心:ReplicaManager揭秘
分布式·kafka·linq
GGBondlctrl10 小时前
【Redis】从单机架构到分布式,回溯架构的成长设计美学
分布式·缓存·架构·微服务架构·单机架构
编织幻境的妖10 小时前
Zookeeper在大数据集群中的作用详解
大数据·分布式·zookeeper