uva1203 - Argus (排序、优先级队列)

简介: uva1203 - Argus (排序、优先级队列)
importjava.io.BufferedReader;
importjava.io.InputStreamReader;
importjava.io.FileReader;
importjava.io.IOException;
importjava.util.StringTokenizer;
importjava.util.Arrays;
importjava.util.PriorityQueue;
classMain{
publicstaticfinalbooleanDEBUG=false;  
publicstaticintN=1010;
publicstaticRegister[] instruction=newRegister[N];
publicstaticintn;
staticclassRegisterimplementsComparable<Register>    {
intnum;
intperiod;
intcnt;
publicintcompareTo(Registerother)
        {
if (period!=other.period) returnperiod-other.period;
returnnum-other.num;
        }
    }
staticclassNodeimplementsComparable<Node>    {
intnum;
intv;
publicintcompareTo(Nodeother)
        {
if (v!=other.v) returnv-other.v;
returnnum-other.num;
        }
    }
publicstaticvoidmain(String[] args) throwsIOException    {
BufferedReadercin;
Strings;
intk;
if (DEBUG) {
cin=newBufferedReader(newFileReader("d:\\OJ\\uva_in.txt"));
        } else {
cin=newBufferedReader(newInputStreamReader(System.in));
        }
n=0;
while ((s=cin.readLine()) !=null) {
if ("#".equals(s)) break;
StringTokenizerst=newStringTokenizer(s);
intcnt=0;
instruction[n] =newRegister();
instruction[n].cnt=0;
while (st.hasMoreTokens()) {
Stringtmp=st.nextToken();
if (cnt==1) {
instruction[n].num=Integer.parseInt(tmp);
                } elseif (cnt==2) {
instruction[n].period=Integer.parseInt(tmp);
                }
cnt++;
            }
n++;
        }
s=cin.readLine();
k=Integer.parseInt(s);
Arrays.sort(instruction, 0, n);
intoutputcnt=k;
inti=0;
while (i<k) {
intstart=instruction[0].period*instruction[0].cnt;
intend=start+instruction[0].period;
PriorityQueue<Node>pq=newPriorityQueue<Node>();
for (intj=0; j<n; j++) {
intcur=instruction[j].period* (instruction[j].cnt+1);
if (cur>=start&&cur<=end) {
i++;
Nodetmp=newNode();
tmp.num=instruction[j].num;
tmp.v=cur;
instruction[j].cnt++;
pq.add(tmp);
                }
            }
while (!pq.isEmpty() &&outputcnt>0) {
System.out.println(pq.poll().num);
outputcnt--;
            }
        }
    }
}
目录
相关文章
|
10天前
|
人工智能 数据可视化 安全
王炸组合!阿里云 OpenClaw X 飞书 CLI,开启 Agent 基建狂潮!(附带免费使用6个月服务器)
本文详解如何用阿里云Lighthouse一键部署OpenClaw,结合飞书CLI等工具,让AI真正“动手”——自动群发、生成科研日报、整理知识库。核心理念:未来软件应为AI而生,CLI即AI的“手脚”,实现高效、安全、可控的智能自动化。
34580 26
王炸组合!阿里云 OpenClaw X 飞书 CLI,开启 Agent 基建狂潮!(附带免费使用6个月服务器)
|
4天前
|
人工智能 自然语言处理 安全
Claude Code 全攻略:命令大全 + 实战工作流(建议收藏)
本文介绍了Claude Code终端AI助手的使用指南,主要内容包括:1)常用命令如版本查看、项目启动和更新;2)三种工作模式切换及界面说明;3)核心功能指令速查表,包含初始化、压缩对话、清除历史等操作;4)详细解析了/init、/help、/clear、/compact、/memory等关键命令的使用场景和语法。文章通过丰富的界面截图和场景示例,帮助开发者快速掌握如何通过命令行和交互界面高效使用Claude Code进行项目开发,特别强调了CLAUDE.md文件作为项目知识库的核心作用。
4259 16
Claude Code 全攻略:命令大全 + 实战工作流(建议收藏)
|
22天前
|
人工智能 JSON 机器人
让龙虾成为你的“公众号分身” | 阿里云服务器玩Openclaw
本文带你零成本玩转OpenClaw:学生认证白嫖6个月阿里云服务器,手把手配置飞书机器人、接入免费/高性价比AI模型(NVIDIA/通义),并打造微信公众号“全自动分身”——实时抓热榜、AI选题拆解、一键发布草稿,5分钟完成热点→文章全流程!
45438 150
让龙虾成为你的“公众号分身” | 阿里云服务器玩Openclaw
|
3天前
|
人工智能 机器人 开发工具
Windows 也能跑 Hermes Agent!完整安装教程 + 飞书接入,全程避坑
Hermes Agent 是一款自学习AI智能体系统,支持一键安装与飞书深度集成。本教程详解Windows下从零部署全流程,涵盖依赖自动安装、模型配置、飞书机器人接入及四大典型兼容性问题修复,助你快速构建企业级AI协作平台。(239字)
3828 10
|
2天前
|
人工智能 供应链 安全
|
11天前
|
人工智能 JSON 监控
Claude Code 源码泄露:一份价值亿元的 AI 工程公开课
我以为顶级 AI 产品的护城河是模型。读完这 51.2 万行泄露的源码,我发现自己错了。
5169 21
|
4天前
|
机器学习/深度学习 存储 人工智能
还在手写Skill?hermes-agent 让 Agent 自己进化能力
Hermes-agent 是 GitHub 23k+ Star 的开源项目,突破传统 Agent 依赖人工编写Aegnt Skill 的瓶颈,首创“自我进化”机制:通过失败→反思→自动生成技能→持续优化的闭环,让 Agent 在实践中自主构建、更新技能库,持续自我改进。
940 2

热门文章

最新文章

下一篇
开通oss服务