[BZOJ1583] [Usaco2009 Mar]Moon Mooing 哞哞叫(队列)
思想有点像蚯蚓那个题
#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 哞哞叫(队列)的更多相关文章
- 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,求最后能得 ...
- 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 ...
随机推荐
- SAP CRM中间件下载equipment时遇到的一个错误
在CRM开发系统上进行equipment下载,发现不工作.调试发现错误信息在下图定96行的WHEN default分支抛出的: MESSAGE ID 'AZ' ... 通过阅读源代码发现,ERP端支持 ...
- java 读取文件转换成字符串
public String readFromFile(File src) { try { BufferedReader bufferedReader = new BufferedReader(new ...
- idea 发布和本地测试问题
1.maven本地打包成jar 提示[错误: 找不到或无法加载主类]修改 配置maven ---->Runner---->VM Optins [-DarchetypeCatalog=loc ...
- 理解 React,但不理解 Redux,该如何通俗易懂的理解 Redux?(转)
作者:Wang Namelos 链接:https://www.zhihu.com/question/41312576/answer/90782136来源:知乎 解答这个问题并不困难:唯一的要求是你熟悉 ...
- C-基础:详解sizeof和strlen,以及strstr
sizeof和strlen (string.h) 先看几个例子(sizeof和strlen之间的区别): (1) 对于一个指针, char* ss ="0123456789"; ...
- HITICS || 2018大作业 程序人生 Hello's P2P
摘 要 本文通过分析一个hello.c的完整的生命周期,从它开始被编译,到被汇编.链接.在进程中运行,讲解了Linux计算机系统执行一个程序的完整过程. 关键词:操作系统,进程,程序的生命周期 目 ...
- 7.逻辑运算 and or not
1)优先级 ()> not > and > o r and:真真为真,真假为假 ,假假为假 or:真真为真,真假为真,假假为假 print(2 > 1 and 1 < ...
- tomcat常用的优化和配置
Tomcat 5常用优化和配置 1.JDK内存优化: Tomcat默认可以使用的内存为128MB,Windows下,在文件{tomcat_home}/bin/catalina.bat,Unix下,在文 ...
- 二. python函数与模块
第四章.内置函数与装饰器详解 1.内置函数补充1 注:红色圆圈:必会: 紫红色方框:熟练: 绿色:了解 callable() 判断函数是否可以被调用执行 def f1(): pass f1() ...
- python virtualenv学习
补充:在开发Python应用程序的时候,系统安装的Python3只有一个版本:3.4.所有第三方的包都会被pip安装到Python3的site-packages目录下. virtualenv就是 ...