[AtCoder3856]Ice Rink Game - 模拟
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 A1, A2, ..., 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:
K
A1 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
4
3 4 3 2
Sample Output
6 8 怎么说呢,这题在愚人节出真的是耐人寻味,赤裸裸的模拟题啊。
显然,因为给定了结束时的人数,我们可以通过倒推求解。
对于min值,若上轮的每组人数正好可以整除当前人数,不做任何操作;否则,更新为当前人数和上轮每组人数的最小公倍数。
对于max值,记k为当前人数除以上轮每组人数向下取整,则更新为(k+1)*上轮每组人数-1。
对于无解情况,可以证明此时max小于min。
上代码!
#include<cstdio>
#include<cstring>
typedef long long ll;
int n;
ll a[],ans1=,ans2=;
int main(){
scanf("%d",&n);
for(int i=;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]+)*a[i]-;
}
if(ans1>ans2)puts("-1");
else printf("%lld %lld\n",ans1,ans2);
return ;
}
[AtCoder3856]Ice Rink Game - 模拟的更多相关文章
- 【Atcoder】AGC 020 B - Ice Rink Game 递推
[题意]n个人进行游戏,每轮只保留最大的a[i]倍数的人,最后一轮过后剩余2人,求最小和最大的n,或-1.n<=10^5. [算法]递推||二分 [题解]令L(i),R(i)表示第i轮过后的最小 ...
- AGC 020 B - Ice Rink Game
题面在这里! 倒着维护可以取的范围区间,判一下可不可能无解即可. #include<bits/stdc++.h> #define ll long long using namespace ...
- AtCoder-3856
An adult game master and N children are playing a game on an ice rink. The game consists of K rounds ...
- 【AtCoder】AGC020
A - Move and Win 题解 看两个人相遇的时候谁先手即可,相遇之后第一个移动的人必输 代码 #include <bits/stdc++.h> #define fi first ...
- AtCoder Grand Contest 020
A - Move and Win Time limit : 1sec / Memory limit : 512MB Score : 300 points Problem Statement A gam ...
- ICE CAVE(BFS搜索(模拟))
Description You play a computer game. Your character stands on some level of a multilevel ice cave. ...
- CodeForces 686A Free Ice Cream (水题模拟)
题意:给定初始数量的冰激凌,然后n个操作,如果是“+”,那么数量就会增加,如果是“-”,如果现有的数量大于等于要减的数量,那么就减掉,如果小于, 那么孩子就会离家.问你最后剩下多少冰激凌,和出走的孩子 ...
- 模拟--poj1835宇航员的故事
这道题委实无语了,刚开始以为是很一般的方位模拟题,懒得看样例直接写的代码,然后敲了好几个switch结果样例居然没出来.. 仔细分析了样例之后才发现原来随着宇航员方位的改变他的左手方向以及头顶方向是跟 ...
- ICE学习——异步1
ICE的AMI和AMD: AMI:指的是客户端的调用.一般有一个代理类,一个回调类. 从服务端返回的数据在回调类中的ice_response函数中. AMD:指的是服务端对客户端的调用分派.一般进行业 ...
随机推荐
- dba_segements 没有所有的表的信息
这是oracle11g新增的功能,假设一个一般的用户user新建了一张表user_table,这时切换到sys用户查看dba_segments 查看user_table的信息,发现dba_segmen ...
- Q - N! HDU - 1042
使用java还不熟练,错误在于读入.应用in.hasNext() 代码 import java.text.ParseException; import java.text.SimpleDateForm ...
- Linux使用CFSSL自签TLS证书
⒈安装CFSSL wget https://pkg.cfssl.org/R1.2/cfssl_linux-amd64 wget https://pkg.cfssl.org/R1.2/cfssljson ...
- No grammar constraints (DTD or XML Schema) referenced in the document.
问题描述 web.xml 使用 Servlet4.0 版本,No grammar constraints (DTD or XML Schema) referenced in the document. ...
- MapReduce流量统计
准备数据access.log 要用到的只有第二个手机号,倒数第三上行流量,倒数第二下行流量. 1363157985066 13726230503 00-FD-07-A4-72-B8:CMCC 120. ...
- C++中的继承(2)类的默认成员
在继承关系里面, 在派生类中如果没有显示定义这六个成员函数, 编译系统则会默认合成这六个默认的成员函数. 1.构造与析构函数的调用关系 调用关系先看一段代码: class Base { public ...
- 小程序+node+mysql做的小项目
git源码地址: https://github.com/songkangle/weixin_node 小程序页面 数据库 user表 dream表 node的express框架index.js var ...
- Spark SQL官网阅读笔记
Spark SQL是Spark中用于结构化数据处理的组件. Spark SQL可以从Hive中读取数据. 执行结果是Dataset/DataFrame. DataFrame是一个分布式数据容器.然而D ...
- Javascript数据结构与算法--队列(顺序队列、优先队列、循环队列)的实现与用法
前言 队列和栈非常类似,前面已经讲过了栈的实现与用法,现在我们来说说队列. 队列介绍 队列遵循FIFO(First In First Out,先进先出)原则的一组有序的项. 队列是一种特殊的线性表,特 ...
- Angular动画——路由动画及高阶动画函数
一.路由动画 路由动画需要在host元数据中指定触发器.动画注意不要过多,否则适得其反. 内容优先,引导用户去注意到某个内容.动画只是辅助手段. 定义一个进场动画,一个离场动画. 因为进场动画和离场动 ...