BZOJ1583: [Usaco2009 Mar]Moon Mooing 哞哞叫
给n<=4000000,c,a1,b1,c1,a2,b2,c2,以c为初始得到的数,每次可以把得到的某个数x进行操作f1(x)=a1*x/c1+b1,f2(x)=a2*x/c2+b2,求最后能得到的数的第n个,保证c1<a1,c2<a2。
由于两个函数都单调递增,而且得到的数也是单调递增的,所以就在答案数组里开两个指针,用两种函数扩展就好啦~
一开始还以为是分开算的QAQ
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
//#include<iostream>
using namespace std; int n;
#define LL long long
LL c,a1,b1,c1,a2,b2,c2;
#define maxn 4000011
LL ans[maxn];
int main()
{
scanf("%lld%d",&c,&n);
scanf("%d%d%d%d%d%d",&a1,&b1,&c1,&a2,&b2,&c2);
int p1=,p2=,la=;ans[]=c;
LL s1=a1*c/c1+b1,s2=a2*c/c2+b2;
for (;la<n;)
{
if (s1<s2) {if (ans[la]!=s1) ans[++la]=s1;s1=ans[++p1]*a1/c1+b1;}
else {if (ans[la]!=s2) ans[++la]=s2;s2=ans[++p2]*a2/c2+b2;}
}
printf("%lld\n",ans[n]);
return ;
}
BZOJ1583: [Usaco2009 Mar]Moon Mooing 哞哞叫的更多相关文章
- [BZOJ1583] [Usaco2009 Mar]Moon Mooing 哞哞叫(队列)
传送门 思想有点像蚯蚓那个题 #include <cstdio> #define N 4000001 #define LL long long #define min(x, y) ((x) ...
- 1583: [Usaco2009 Mar]Moon Mooing 哞哞叫
1583: [Usaco2009 Mar]Moon Mooing 哞哞叫 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 244 Solved: 126 ...
- [USACO09MAR]Moon哞哞叫Moon Mooing(模拟)
链接:https://ac.nowcoder.com/acm/contest/1086/F来源:牛客网 题目描述 A full moon casts some sort of spell on the ...
- bzoj 3399: [Usaco2009 Mar]Sand Castle城堡
3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec Memory Limit: 128 MB Description 约翰用沙子建了一座城堡.正 ...
- BZOJ3401: [Usaco2009 Mar]Look Up 仰望
3401: [Usaco2009 Mar]Look Up 仰望 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 87 Solved: 58[Submit ...
- BZOJ3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队
3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 89 Solve ...
- BZOJ3399: [Usaco2009 Mar]Sand Castle城堡
3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 22 Solved: 17[Sub ...
- BZOJ 3401: [Usaco2009 Mar]Look Up 仰望( 单调栈 )
n <= 105 , 其实是10 ^ 5 ....坑...我一开始写了个模拟结果就 RE 了.. 发现这个后写了个单调栈就 A 了... ---------------------------- ...
- 3399: [Usaco2009 Mar]Sand Castle城堡
3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 37 Solved: 32[Sub ...
随机推荐
- 【学习笔记】一:JavaScript简介
1.JavaScript简史 1)JavaScript最初的功能只是用来在客户端做简单的输入验证器,减少客户端与服务器端的数据交互(毕竟那个年代网速有限). 2)JavaScript的飞速发展及Net ...
- zabbix显示中文
- COGS 886. [USACO 4.2] 完美的牛栏
★★☆ 输入文件:stall4.in 输出文件:stall4.out 简单对比时间限制:1 s 内存限制:128 MB USACO/stall4(译by Felicia Crazy) ...
- Gym - 100676G Training Camp (状压dp)
G. Training Camp[ Color: Yellow ]Montaser is planning to train very hard for ACM JCPC 2015; he has p ...
- zabbix实现自动发现功能添加磁盘监控
zabbix实现对磁盘动态监控 - Lenwood 原文 http://www.cnblogs.com/baizhantang/p/3253246.html 主题 Linux命令 zabbix 前言 ...
- nginx 的编译安装及基本操作
下载nginx [root@nginx ~]# wget http://nginx.org/download/nginx-1.14.0.tar.gz --2019-05-02 21:52:23-- h ...
- freemarker list集合去重,实现hashset
在freemarker中没有提供去重的方法,虽然有提供定义hash的方法,如:<#assign myHash = { "name": "mouse", & ...
- Linux-fuser
Linux-fuser 1. 描述 2. 选项3. EXAMPLES4. RESTRICTIONS 限制5. SIGNAL 可用信号 fuser - 使用文件或套接字识别进程 1. 描述 fuser使 ...
- delphi jinchengneicun
http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Configuring_the_Memory_Manager https://docs.micros ...
- 收集的WEB前端程序员需要的网站整理
前端学习资源实在是又多又广,在这样的一个知识的海洋里,我们像一块海绵一样吸收,想要快速提高效率,平时的总结不可缺少,以下总结了一些,排版自我感觉良好,推送出来. 一.插件类网站 jQuery插件库:h ...