博客
关于我
1041 Be Unique
阅读量:733 次
发布时间:2019-03-21

本文共 1405 字,大约阅读时间需要 4 分钟。

The task at hand is to determine the winning number in a unique lottery system designed for Martian inhabitants. The game works by participants betting on numbers from a specific range, and the winner is the first to bet on a unique number not previously chosen.

Input and Output

Each test case consists of a line starting with an integer N (≤ 10^5), followed by N bets. These bets are separated by spaces. The output should be the winning number only if there is one. If no unique number exists after all bets, return "None".

Example 1

Input:

7 5 31 5 88 67 88 17
The program processes each bet, keeping track of each number. The first unique number is "31", so it is printed.

Output:

31

Example 2

Input:

5 888 666 666 888 888
In this case, the bets go 5 times. The program counts occurrences: 888 appears 3 times, 666 appears 2 times, and both have duplicates. Thus, no unique winner exists, and the output is "None".

Technology in Action

The provided C++ implementation uses an efficient array-based approach to track bets:

  • Read the number of bets and store each in an array.
  • Maintain a frequency array to count occurrences.
  • After processing all bets, iterate through the frequency array to find the first count that equals 1.
  • Output this number or "None" if no unique number exists.
  • This approach ensures that the solution is both simple and efficient, handling up to the maximum constraints smoothly.

    转载地址:http://qahgz.baihongyu.com/

    你可能感兴趣的文章
    NIFI从MySql中离线读取数据再导入到MySql中_无分页功能_02_转换数据_分割数据_提取JSON数据_替换拼接SQL_添加分页---大数据之Nifi工作笔记0037
    查看>>
    NIFI从Oracle11G同步数据到Mysql_亲测可用_解决数据重复_数据跟源表不一致的问题---大数据之Nifi工作笔记0065
    查看>>
    NIFI从PostGresql中离线读取数据再导入到MySql中_带有数据分页获取功能_不带分页不能用_NIFI资料太少了---大数据之Nifi工作笔记0039
    查看>>
    nifi使用过程-常见问题-以及入门总结---大数据之Nifi工作笔记0012
    查看>>
    NIFI分页获取Mysql数据_导入到Hbase中_并可通过phoenix客户端查询_含金量很高的一篇_搞了好久_实际操作05---大数据之Nifi工作笔记0045
    查看>>
    NIFI分页获取Postgresql数据到Hbase中_实际操作---大数据之Nifi工作笔记0049
    查看>>
    NIFI同步MySql数据_到SqlServer_错误_驱动程序无法通过使用安全套接字层(SSL)加密与SQL Server_Navicat连接SqlServer---大数据之Nifi工作笔记0047
    查看>>
    NIFI同步MySql数据源数据_到原始库hbase_同时对数据进行实时分析处理_同步到清洗库_实际操作06---大数据之Nifi工作笔记0046
    查看>>
    Nifi同步过程中报错create_time字段找不到_实际目标表和源表中没有这个字段---大数据之Nifi工作笔记0066
    查看>>
    【Flink】Flink 1.9 版本 web UI 突然没有日志
    查看>>
    NIFI大数据进阶_FlowFile拓扑_对FlowFile内容和属性的修改删除添加_介绍和描述_以及实际操作---大数据之Nifi工作笔记0023
    查看>>
    NIFI大数据进阶_FlowFile生成器_GenerateFlowFile处理器_ReplaceText处理器_处理器介绍_处理过程说明---大数据之Nifi工作笔记0019
    查看>>
    NIFI大数据进阶_FlowFile生成器_GenerateFlowFile处理器_ReplaceText处理器_实际操作---大数据之Nifi工作笔记0020
    查看>>
    NIFI大数据进阶_Json内容转换为Hive支持的文本格式_实际操作_02---大数据之Nifi工作笔记0032
    查看>>
    NIFI大数据进阶_Json内容转换为Hive支持的文本格式_操作方法说明_01_EvaluteJsonPath处理器---大数据之Nifi工作笔记0031
    查看>>
    NIFI大数据进阶_Kafka使用相关说明_实际操作Kafka消费者处理器_来消费kafka数据---大数据之Nifi工作笔记0037
    查看>>
    NIFI大数据进阶_Kafka使用相关说明_实际操作Kafka生产者---大数据之Nifi工作笔记0036
    查看>>
    NIFI大数据进阶_NIFI的模板和组的使用-介绍和实际操作_创建组_嵌套组_模板创建下载_导入---大数据之Nifi工作笔记0022
    查看>>
    NIFI大数据进阶_NIFI监控功能实际操作_Summary查看系统和处理器运行情况_viewDataProvenance查看_---大数据之Nifi工作笔记0026
    查看>>
    NIFI大数据进阶_NIFI监控的强大功能介绍_处理器面板_进程组面板_summary监控_data_provenance事件源---大数据之Nifi工作笔记0025
    查看>>