传送门

思想有点像蚯蚓那个题

#include <cstdio>
#define N 4000001
#define LL long long
#define min(x, y) ((x) < (y) ? (x) : (y))
#define max(x, y) ((x) > (y) ? (x) : (y)) LL q1[N], q2[N];
LL a1, b1, d1, a2, b2, d2;
int n, h1 = 1, t1 = 1, h2 = 1, t2; int main()
{
int i;
LL x, x1, x2;
scanf("%lld %d", &q1[1], &n);
scanf("%lld %lld %lld", &a1, &b1, &d1);
scanf("%lld %lld %lld", &a2, &b2, &d2);
while(n--)
{
x = ~(1 << 31);
x <<= 32;
if(h1 <= t1) x = min(x, q1[h1]);
if(h2 <= t2) x = min(x, q2[h2]);
if(h1 <= t1 && x == q1[h1]) h1++;
if(h2 <= t2 && x == q2[h2]) h2++;
x1 = a1 * x / d1 + b1;
x2 = a2 * x / d2 + b2;
if(min(x1, x2) > q1[t1]) q1[++t1] = min(x1, x2);
if(max(x1, x2) > q2[t2]) q2[++t2] = max(x1, x2);
else if(max(x1, x2) > q1[t1]) q1[++t1] = max(x1, x2);
}
printf("%lld\n", x);
return 0;
}

  

来自洛谷的更简便的题解

#include <cstdio>
#include <iostream>
typedef unsigned long long ull; //注意本题要用unsigned long long。
const int N = 4000000;
ull a[N+5]; //这里我们将a数组看成一个队列
inline ull mn(ull x, ull y) {
return x < y ? x : y;
}
int main() {
int c, n, a1, b1, d1, a2, b2, d2, i = 1, f1 = 1, f2 = 1;
scanf("%d%d%d%d%d%d%d%d", &c, &n, &a1, &b1, &d1, &a2, &b2, &d2);
a[i++] = c; //初始元素c入队
while(i <= N) {
ull x = mn(a1*a[f1]/d1+b1, a2*a[f2]/d2+b2); //取F1()和F2()中的较小值
a[i++] = x; //将该较小值入队
if(x == a1*a[f1]/d1+b1) f1++; //如果较小值来自F1(),则将F1()的指针f1+1。
if(x == a2*a[f2]/d2+b2) f2++; //如果较小值来自F2(),则将F2()的指针f2+1
} //重点理解while循环的内容。因为算出的F1()或F2()的数据单调递增,所以可以用这样的方式生成整个数列
std::cout << a[n]; //最后输出即可。
return 0;
}
//祝各位早日AC此题!

  

[BZOJ1583] [Usaco2009 Mar]Moon Mooing 哞哞叫(队列)的更多相关文章

  1. 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,求最后能得 ...

  2. 1583: [Usaco2009 Mar]Moon Mooing 哞哞叫

    1583: [Usaco2009 Mar]Moon Mooing 哞哞叫 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 244  Solved: 126 ...

  3. [USACO09MAR]Moon哞哞叫Moon Mooing(模拟)

    链接:https://ac.nowcoder.com/acm/contest/1086/F来源:牛客网 题目描述 A full moon casts some sort of spell on the ...

  4. bzoj 3399: [Usaco2009 Mar]Sand Castle城堡

    3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec  Memory Limit: 128 MB Description 约翰用沙子建了一座城堡.正 ...

  5. BZOJ3401: [Usaco2009 Mar]Look Up 仰望

    3401: [Usaco2009 Mar]Look Up 仰望 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 87  Solved: 58[Submit ...

  6. BZOJ3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队

    3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 89  Solve ...

  7. BZOJ3399: [Usaco2009 Mar]Sand Castle城堡

    3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 22  Solved: 17[Sub ...

  8. BZOJ 3401: [Usaco2009 Mar]Look Up 仰望( 单调栈 )

    n <= 105 , 其实是10 ^ 5 ....坑...我一开始写了个模拟结果就 RE 了.. 发现这个后写了个单调栈就 A 了... ---------------------------- ...

  9. 3399: [Usaco2009 Mar]Sand Castle城堡

    3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 37  Solved: 32[Sub ...

随机推荐

  1. Spring 配置定时器(注解+xml)方式—整理

    一.注解方式 1. 在Spring的配置文件ApplicationContext.xml,首先添加命名空间 xmlns:task="http://www.springframework.or ...

  2. COGS 615. 韩国明星

    [问题描述] 在LazyCat同学的影响下,Roby同学开始听韩国的音乐,并且越来越喜欢H.o.T,尤其喜欢安七炫和Tony,可是,爱学习爱思考的Roby同学想,如果以后喜欢的韩星越来越多怎么办呢?R ...

  3. 6.3 lambda 表达式

    6.3.1 lambda 表达式是一个可传递的代码块,可以在以后执行一次或者多次. 思考(如何按指定时间间隔完成工作,将这个工作放在一个ActionListener的actionPerformed方法 ...

  4. MIPS——分支语句

    有关指令 li $t1,immediate #load immediate,立即数可正可负 la $t1,address #load address move $t1,$t2 #move $t2 to ...

  5. gcc, g++ - GNU 工程的 C 和 C++ 编译器 (egcs-1.1.2)

    总览 (SYNOPSIS) gcc [ option | filename ]... g++ [ option | filename ]... 警告 (WARNING) 本手册页 内容 摘自 GNU ...

  6. 关于img

    为img添加属性max-width min-height之类的属性可以对图片溢出部分实行自动裁剪功能 非常方便!!!!!!!!!(仅适用于那些原始图片大于max-width,max-height的图片 ...

  7. JSONP 跨域请求 - 获取JSON数据

    如何用原生方式使用JSONP? 下边这一DEMO实际上是JSONP的简单表现形式,在客户端声明回调函数之后,客户端通过script标签向服务器跨域请求数据,然后服务端返回相应的数据并动态执行回调函数. ...

  8. 【414】Code::Blocks增加主题

    替换文件地址:C:\Users\z5194293\AppData\Roaming\CodeBlocks 文件下载地址:default.rar 通过 Settings -> Editor... - ...

  9. 2019的hdu暑假作业(欢迎纠错)

    1219 遍历计数. #include<bits/stdc++.h> #define QAQ 0 using namespace std; ]; ]; int main(){ )){ me ...

  10. ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061) : 第一次设置MySQL也适用

    [MySQL的安装环境]:windows7 64位 [MySQL的版本]:mysql-8.0.16-winx64 [错误描述]: ERROR 2003 (HY000): Can't connect t ...