传送门

思想有点像蚯蚓那个题

#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. IOSButton自定义

    + (APCCustomBackButton *)customBackButtonWithTarget:(id)aTarget action:(SEL)anAction tintColor:(UICo ...

  2. jdbc接口的一种类比——打酱油

    jdbc很简单,这里只是为了方便自己的记忆.模型也许有缺陷,但本质是相同的. jdbc可以屏蔽数据库的底层的不同,让我们有能力用java语言统一访问不同的数据库.就像打酱油一样,可以去超市买,也可以去 ...

  3. mysql利用binlog恢复数据详细例子

    模拟数据恢复的案例 有些时候脑瓜就会短路,难免会出错 场景:在生产环境中,我们搭建了mysql主从,备份操作都是在从备份数据库上 前提:有最近一天或者最近的全备 或者最近一天相关数据库的备份 最重要的 ...

  4. CPP-基础:友元

    友元可以是一个函数,该函数被称为友元函数:友元也可以是一个类,该类被称为友元类. 我们已知道类具有封装和信息隐藏的特性.只有类的成员函数才能访问类的私有成员,程序中的其他函数是无法访问私有成员的.非成 ...

  5. objdump命令

    0x00 objdump命令是Linux下的反汇编目标文件或者可执行文件的命令 0x01 objdump -f   显示test的文件头信息 $ objdump -f levellevel: file ...

  6. js常用技巧汇总

    将彻底屏蔽鼠标右键 oncontextmenu="window.event.returnvalue=false" <table border oncontextmenu=re ...

  7. 【NOIP2017提高A组冲刺11.8】购物

    这个范围对DP不友好,和CF的一道C题非常像,贪心+后悔. 先使用k个优惠券购买k个q最小的(钱不购买则退出),同时把这k个p[i]-q[i]放入小根堆,然后将剩下的n-k个按p升序排序,记小根堆堆顶 ...

  8. (65)login as guest zabbix无法进入登陆界面

    很早之前有一位群友告知zabbix登陆不了,一直有如下提示:Access denied.Your are logged in as guest. You have no permissions to ...

  9. struts 乱码

    在进行struts开发的过程中,总也是出现很多的乱码问题 ,但归根到底,也只是以下三种情况: ㈠页面显示中文乱码 ㈡传递参数中文乱码 ㈢国际化资源文件乱码 下面就这三中情况介绍怎么在具体项目中处理这些 ...

  10. Hive 将本地数据导入hive表中

    # 导入 load data local inpath '/root/mr/The_Man_of_Property.txt' insert into table article; # 提示 FAILE ...