链接:https://ac.nowcoder.com/acm/contest/1086/F
来源:牛客网

题目描述

A full moon casts some sort of spell on the cows and, like their cousins the wolves and coyotes, they bay at the moon -- mooing instead of howling, of course.
Each 'moo' lasts a certain amount of time. A short 'moo' might last time 1; a longer one might last time 24 or even 1,000,000,000 or longer (cows can really moo when they want to). No 'moo' will last more than or equal to 2^63.
It should come as no surprise that the cows have a pattern to their moos. Bessie will choose an integer c (1 <= c <= 100) that is the initial length of a moo.
After Bessie moos for length c, the cows calculate times for subsequent moos. They apply two formulae to each moo time to yield even more moo times. The two formulae are:
f1(c)=a1*c/d1+b1 (integer divide, of course) and
f2(c)=a2*c/d2+b2.
They then successively use the two new times created by evaluating f1(c) and f2(c) to create even more mooing times. They keep a sorted list of all the possible mooing times (discarding duplicates).
They are allowed to moo a total of N times (1 <= N <= 4,000,000). Please determine the length of the longest moo before they must quit.
The constants in the formulae have these constraints: 1 <= d1 < a1; d1 < a1 <= 20; 0 <= b1 <= 20; 1 <= d2 < a2; d2 < a2 <= 20; 0 <= b2 <= 20.
Consider an example where c=3 and N=10. The constants are:
a1=4 b1=3 d1=3
a2=17 b2=8 d2=2
The first mooing time is 3, given by the value of c. The total list of mooing times is:
1. c=3 -> 3 6. f2(3)=17*3/2+8 -> 33
2. f1(3)=4*3/3+3 -> 7 7. f1(28)=4*28/3+3 -> 40
3. f1(7)=4*7/3+3 -> 12 8. f1(33)=4*33/3+3 -> 47
4. f1(12)=4*12/3+3 -> 19 9. f1(40)=4*40/3+3 -> 56
5. f1(19)=4*19/3+3 -> 28 10. f1(47)=4*47/3+3 -> 65
The tenth time is 65, which would be the proper answer for this set of inputs.

输入描述:

* Line 1: Two space-separated integers: c and N
* Line 2: Three space-separated integers: a1, b1, and d1
* Line 3: Three space-separated integers: a2, b2, and d2

输出描述:

* Line 1: A single line which contains a single integer which is the length of the Nth moo

示例1

输入


输出


一道类似两个序列合并的东西,通法就是上一个优先队列就好了,但是这道题会超时。

但是,仔细观察一下,序列是单增的(a>c),这就很好办了,类似做一个归并就好了。

 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <math.h>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
const int maxn=*1e6+;
using namespace std; LL ans[maxn];//ans数组是一个递增队列 int main()
{
int c,n,a1,b1,d1,a2,b2,d2;
scanf("%d %d %d %d %d %d %d %d",&c,&n,&a1,&b1,&d1,&a2,&b2,&d2);
int cnt=;//队列计数器
int f1=,f2=;//函数计数器
ans[cnt++]=c;//初始元素c入队
while(cnt<=n)
{
LL t=min(a1*ans[f1]/d1+b1, a2*ans[f2]/d2+b2);//取F1()和F2()中的较小值
ans[cnt++]=t;//将该较小值入队
if(t==a1*ans[f1]/d1+b1)//如果较小值来自F1(),则将F1()的指针f1+1
f1++;
if(t==a2*ans[f2]/d2+b2)//如果较小值来自F2(),则将F2()的指针f2+1
f2++;
}//重点理解while循环的内容。因为算出的F1()或F2()的数据单调递增,所以可以用这样的方式生成整个数列
printf("%lld",ans[n]);//最后输出即可。
return ;
}

[USACO09MAR]Moon哞哞叫Moon Mooing(模拟)的更多相关文章

  1. jQuery Mobile案例,最近用Moon.Web和Moon.Orm做了一套系统

      一.简介 先说说,我们的主题.jQuery Mobile,最近用Moon.Web和Moon.Orm做了一套系统 jQuery Mobile是jQuery 在手机上和平板设备上的版本.jQuery ...

  2. Ubuntu 搭建 Zerotier One MOON 根目录服务器

    原文转摘:http://www.congan.wang/archives/947 博主倒腾了一天,总算搞定了,主要是受到各种搭建教程的错误引导,导致关键过程错误.官网的MOON搭建教程:https:/ ...

  3. 永久免费云服务器搭建国内Moon服务加速ZeroTier

    ZeroTier One本身的服务器都在国外访问速度很慢.可以通过搭建国内Moon服务加速解决连接慢的问题. 但是需要有固定外网IP的服务器,可以注册sanfengyun账号申请免费云服务器. 下面是 ...

  4. Codeforces Round #373 (Div. 2) A B C 水 贪心 模拟(四舍五入进位)

    A. Vitya in the Countryside time limit per test 1 second memory limit per test 256 megabytes input s ...

  5. 【重点突破】——two.js模拟绘制太阳月亮地球转动

    一.引言 自学two.js第三方绘图工具库,认识到这是一个非常强大的类似转换器的工具,提供一套固定的接口,可用在各种技术下,包括:Canvas.Svg.WebGL,极大的简化了应用的开发.这里,我使用 ...

  6. 《转载》PAT 习题

    博客出处:http://blog.csdn.net/zhoufenqin/article/details/50497791 题目出处:https://www.patest.cn/contests/pa ...

  7. NOIP2016普及组复赛解题报告

    提高组萌新,DAY1DAY2加起来骗分不到300,写写普及组的题目聊以自慰. (附:洛谷题目链接 T1:https://www.luogu.org/problem/show?pid=1909 T2:h ...

  8. HTML5资料

    1 Canvas教程 <canvas>是一个新的用于通过脚本(通常是JavaScript)绘图的HTML元素.例如,他可以用于绘图.制作图片的组合或者简单的动画(当然并不那么简单).It ...

  9. Codeforces水题集合[14/未完待续]

    Codeforces Round #371 (Div. 2) A. Meeting of Old Friends |B. Filya and Homework A. Meeting of Old Fr ...

随机推荐

  1. SublimeText3和插件的安装

    SublimeText3和插件的安装 步骤一:进入官网下载SublimeText3(http://www.sublimetext.com/3),安装并打开SublimeText3   步骤二:进入Su ...

  2. PAT Advanced 1013 Battle Over Cities (25) [图的遍历,统计连通分量的个数,DFS,BFS,并查集]

    题目 It is vitally important to have all the cities connected by highways in a war. If a city is occup ...

  3. SAP_ABAP常用事务代码

    ST05: 性能跟踪(Performance Trace) SE30/SAT: ABAP对象性能分析 ST12: 单个对象性能分析(Single transaction analysis)

  4. html5有哪些新特性、移除了那些元素?

    新增的元素: HTML5 现在已经不是 SGML 的子集,主要是关于图像,位置,存储,多任务等功能的增加. 拖拽释放(Drag and drop) API 语义化更好的内容标签(header,nav, ...

  5. redis常用命令--zsets

    zsets常用命令: zadd key score1 mb1 [score2 mb2....]:像key中添加元素和这个元素的分数,如果元素已经存在,则替换分数. zscore key mb :获取k ...

  6. python类(4)——自己造第一个轮子

    先做简单版本,再一步步增加功能 1.简单目的:要实现这样一个功能,能够连接服务器,登录账号,查询账号委托信息,如果有委托信息,撤销委托. 属性(不同账户之间差别):账户,密码 方法(不同账户之间都要用 ...

  7. 家中WIFI被人用WiFi万能钥匙共享后,我们应该怎么做?

    据之前WiFi万能钥匙官方称,其用户总数已经超过了8亿,且日活用户达到2亿,在海量APP中仅次于微信和QQ.可以想象有着数量如此庞大的用户,家里的WiFi是如何的"不保险". 而据 ...

  8. HTML5中的行级标签和块级标签

    行级标签 1.行级标签又称为内联标签,行级标签不会单独占据一行,设置宽高无效. 2.行内内部可以容纳其他行内元素,但不可以容纳块元素.有span.strong.em.b.i.input.a.img.u ...

  9. arp攻击 (可查看同一局域网他人手机照片)

    国家法律一定要遵守,知识要用在对的地方. 本贴只为了和大家交流学习,请勿用在其他地方,损害任何人的利益. 今天我,来说一下arp攻击的原理和教程 原理什么的还是自行百度好,因为专业的说明是严谨而又经得 ...

  10. python笔记(很乱)、打算抽个时间再好好整理

    最近刚开始学python.总结的可能不是很好 print:打印值 input:可以进行等候赋值.进行一个交互 python中 需要两个==才为判断 变量:数字.字母.下划线组成 类型:int整数.st ...