博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[AtCoder3856]Ice Rink Game - 模拟
阅读量:4933 次
发布时间:2019-06-11

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

Problem Statement

An adult game master and N children are playing a game on an ice rink. The game consists of K rounds. In the i-th round, the game master announces:

  • Form groups consisting of Ai children each!

Then the children who are still in the game form as many groups of Ai children as possible. One child may belong to at most one group. Those who are left without a group leave the game. The others proceed to the next round. Note that it's possible that nobody leaves the game in some round.

In the end, after the K-th round, there are exactly two children left, and they are declared the winners.

You have heard the values of A1A2, ..., AK. You don't know N, but you want to estimate it.

Find the smallest and the largest possible number of children in the game before the start, or determine that no valid values of N exist.

Constraints

  • 1≤K≤105
  • 2≤Ai≤109
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

KA1 A2 … AK

Output

Print two integers representing the smallest and the largest possible value of N, respectively, or a single integer −1 if the described situation is impossible.

Sample Input 

43 4 3 2

Sample Output 

6 8 怎么说呢,这题在愚人节出真的是耐人寻味,赤裸裸的模拟题啊。 显然,因为给定了结束时的人数,我们可以通过倒推求解。 对于min值,若上轮的每组人数正好可以整除当前人数,不做任何操作;否则,更新为当前人数和上轮每组人数的最小公倍数。 对于max值,记k为当前人数除以上轮每组人数向下取整,则更新为(k+1)*上轮每组人数-1。 对于无解情况,可以证明此时max小于min。 上代码!
#include
#include
typedef long long ll;int n;ll a[100005],ans1=2,ans2=2;int main(){ scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%d",&a[i]); for(int i=n;i;i--){ if(ans1%a[i])ans1/=a[i],ans1=ans1*a[i]+a[i]; ans2=(ans2/a[i]+1)*a[i]-1; } if(ans1>ans2)puts("-1"); else printf("%lld %lld\n",ans1,ans2); return 0;}
View Code

 

转载于:https://www.cnblogs.com/Marser/p/8724117.html

你可能感兴趣的文章
C#中泛型之Dictionary
查看>>
强连通分量
查看>>
Linux 入门 bash语句 第三课
查看>>
LeetCode 27. 移除元素
查看>>
【原创】phpcms v9 0day
查看>>
杂谈SharpDx中的WIC组件——我们需要WIC的图片编码功能么?
查看>>
移动端弹性盒
查看>>
觉得比较重要的一张触发器的图,高手跳过哈!
查看>>
JAVA中使用jcifs集成AD域用户认证
查看>>
SSH框架 jar包版本的选择
查看>>
1699. Turning Turtles
查看>>
1048. Find Coins (25)
查看>>
(八十六)使用系统自带的分享框架Social.framework
查看>>
C# 使用IP端口网络打印图片
查看>>
OSI与TCP/IP你了解多少?
查看>>
压缩解压缩相关基础知识
查看>>
javaweb之MVC设计模式
查看>>
[APIO2015]巴厘岛的雕塑
查看>>
使用Code First模式开发如何更新数据库(转载)
查看>>
Mybatis实例增删改查(二)
查看>>