[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 ...
随机推荐
- 阿里云栖社区dubbo 资源整理
1.apache dubbo pdf git 地址:https://github.com/dubbo/awesome-dubbo/tree/master/slides/meetup/201905%40 ...
- 小tip: 使用CSS将图片转换成黑白(灰色、置灰)[转]
小tip: 使用CSS将图片转换成黑白(灰色.置灰) 这篇文章发布于 2012年08月19日,星期日,20:41,归类于 css相关, SVG相关. 阅读 159943 次, 今日 146 次 ...
- Android学习总结(十八) ———— SQLite数据库使用
一.基本概念 数据库最经典的四个操作 添加.删除.修改.查找,在处理大量数据的时候使用数据库可以帮我们迅速定位当前须要处理的数据,举个例子 好比现在要实现一个搜索功能 用数据库的话只须要其中一个搜索条 ...
- 洛谷 P2362 围栏木桩
题目描述 某农场有一个由按编号排列的n根木桩构成的首尾不相连的围栏.现要在这个围栏中选取一些木桩,按照原有的编号次序排列之后,这些木桩高度成一个升序序列.所谓的升序序列就是序列中的任何一个数都不小于它 ...
- sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) Cannot add a NOT NULL column with default value NULL [SQL: u'ALTER TABLE address_scopes ADD COLUMN ip_version INTEGER NOT NULL']
root@hett-virtual-machine:~# su -s /bin/sh -c "neutron-db-manage --config-file /etc/neutron/neu ...
- 使用javap深入理解Java整型常量和整型变量的区别
我下图代码第五行和第九行分别定义了一个整型变量和一个整型常量: static final int number1 = 512; static int number3 = 545; Java程序员都知道 ...
- dfs染色法判定二分图
#include<iostream> #include<cstring> using namespace std; ][],color[],n; int dfs(int x,i ...
- django 2.0 + pycharm2017 出现的问题
在创建完成app之后,在models文件里创建两个类:BlogType , Blog, 创建超级用户,注册admin,在登陆admin之后发现,发现 BlogType , Blog,并没有导入到adm ...
- Linux网络管理及基础设置
一.网络管理 1 临时配置网络(ip,网关,dns) 用ifconfig命令设定网卡的IP地址: ens33网卡的IP地址为192.168.16.154, ifconfig ens33 192.168 ...
- windows10 下安装、配置、启动mysql
下载mysql 可以自行去百度 或者 https://dev.mysql.com/downloads/mysql/5.7.html#downloads 解压mysql-5.7.26-winx64.zi ...