博客
关于我
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/

    你可能感兴趣的文章
    MySql创建数据表
    查看>>
    MySQL创建新用户以及ERROR 1396 (HY000)问题解决
    查看>>
    MySQL创建用户与授权
    查看>>
    MySQL创建用户报错:ERROR 1396 (HY000): Operation CREATE USER failed for 'slave'@'%'
    查看>>
    MySQL创建索引时提示“Specified key was too long; max key length is 767 bytes”
    查看>>
    mysql初始密码错误问题
    查看>>
    MySQL删除数据几种情况以及是否释放磁盘空间【转】
    查看>>
    Mysql删除重复数据通用SQL
    查看>>
    mysql判断某一张表是否存在的sql语句以及方法
    查看>>
    mysql加入安装策略_一键安装mysql5.7及密码策略修改方法
    查看>>
    mysql加强(1)~用户权限介绍、分别使用客户端工具和命令来创建用户和分配权限
    查看>>
    mysql加强(3)~分组(统计)查询
    查看>>
    mysql加强(4)~多表查询:笛卡尔积、消除笛卡尔积操作(等值、非等值连接),内连接(隐式连接、显示连接)、外连接、自连接
    查看>>
    mysql加强(5)~DML 增删改操作和 DQL 查询操作
    查看>>
    mysql加强(6)~子查询简单介绍、子查询分类
    查看>>
    mysql加强(7)~事务、事务并发、解决事务并发的方法
    查看>>
    MySQL千万级多表关联SQL语句调优
    查看>>
    mysql千万级大数据SQL查询优化
    查看>>
    MySQL千万级大表优化策略
    查看>>
    MySQL单实例或多实例启动脚本
    查看>>