数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog
/*
数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围
t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束
详细解释:http://blog.csdn.net/u014357885/article/details/46044287
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std; typedef long long ll; const int MAXN = 1e3 + ;
const int INF = 0x3f3f3f3f; int main(void) //Codeforces Round #305 (Div. 2) C. Mike and Frog
{
int m;
ll h1, a1, x1, y1, h2, a2, x2, y2;
while (scanf ("%d%I64d%I64d%I64d%I64d%I64d%I64d%I64d%I64d", &m, &h1, &a1, &x1, &y1, &h2, &a2, &x2, &y2) == )
{
ll t1 = -, t2 = -, p1 = -, p2 = -;
for (int i=; i<=m; ++i) //get t1, p1
{
h1 = (h1 * x1 + y1) % m;
if (h1 == a1) {t1 = i; break;}
}
if (t1 == -) {puts ("-1"); continue;}
for (int i=; i<=m; ++i)
{
h1 = (h1 * x1 + y1) % m;
if (h1 == a1) {p1 = i; break;}
} for (int i=; i<=m; ++i) //get t2, p2
{
h2 = (h2 * x2 + y2) % m;
if (h2 == a2) {t2 = i; break;}
}
if (t2 == -) {puts ("-1"); continue;}
for (int i=; i<=m; ++i)
{
h2 = (h2 * x2 + y2) % m;
if (h2 == a2) {p2 = i; break;}
} bool ok = false; //get t1 == t2
for (int i=; i<=*m; ++i)
{
if (t1 == t2) {ok = true; printf ("%I64d\n", t1); break;}
if (t1 < t2) t1 += p1;
else t2 += p2;
}
if (!ok) puts ("-1");
} return ;
} /*
5
4 2
1 1
0 1
2 3
1023
1 2
1 0
1 2
1 1
*/
数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog的更多相关文章
- 暴力 Codeforces Round #305 (Div. 2) B. Mike and Fun
题目传送门 /* 暴力:每次更新该行的num[],然后暴力找出最优解就可以了:) */ #include <cstdio> #include <cstring> #includ ...
- Codeforces Round #305 (Div. 1) A. Mike and Frog 暴力
A. Mike and Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/547/pr ...
- set+线段树 Codeforces Round #305 (Div. 2) D. Mike and Feet
题目传送门 /* 题意:对于长度为x的子序列,每个序列存放为最小值,输出长度为x的子序列的最大值 set+线段树:线段树每个结点存放长度为rt的最大值,更新:先升序排序,逐个添加到set中 查找左右相 ...
- 字符串处理 Codeforces Round #305 (Div. 2) A. Mike and Fax
题目传送门 /* 字符串处理:回文串是串联的,一个一个判断 */ #include <cstdio> #include <cstring> #include <iostr ...
- Codeforces Round #305 (Div. 2) B. Mike and Fun 暴力
B. Mike and Fun Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/548/pro ...
- Codeforces Round #305 (Div. 2) A. Mike and Fax 暴力回文串
A. Mike and Fax Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/548/pro ...
- Codeforces Round #305 (Div. 1) B. Mike and Feet 单调栈
B. Mike and Feet Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/547/pro ...
- Codeforces Round #305 (Div. 2)D. Mike and Feet(单调栈)
题意 n个值代表n个熊的高度 对于size为x的group strength值为这个group(连续的几个熊)中熊的最小的height值 对于x(1<=x<=n) 求出最大的strengt ...
- Codeforces Round #305 (Div. 2) D. Mike and Feet 单调栈
D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
随机推荐
- IOS------Warning
本文转载至 http://blog.csdn.net/shijiucdy/article/details/8755667 处理警告: 1,Validate Project Settings(updat ...
- CentOS笔记-目录结构(转载了菜鸟教程里的)
在linux系统中,有几个目录是比较重要的,平时需要注意不要误删除或者随意更改内部文件. /etc: 上边也提到了,这个是系统中的配置文件,如果你更改了该目录下的某个文件可能会导致系统不能启动. /b ...
- jQuery.ajaxSetup()
jQuery.ajaxSetup()函数用于设置AJAX的全局默认设置. 该函数用于更改jQuery中AJAX请求的默认设置选项.之后执行的所有AJAX请求,如果对应的选项参数没有设置,将使用更改后的 ...
- VC FTP服务器程序分析(三)
CControlSocket类的分析,CControlSocket类的内容比较多,为什么呢.因为通信控制命令的传输全部在这里,通信协议的多样也导致了协议解析的多样. 1.OnReceive 其大致说 ...
- CLI和CGI的区别
CGI :“公共网关接口”(Common Gateway Interface),HTTP服务器与你的或其它机器上的程序进行“交谈”的一种工具,其程序须运行在网络服务器上.以CGI方式运行时,web s ...
- IE8 下背景图标不显示
如图所示 : 微博微信前方各应有个图标,但是IE8下图标没有显示 css如下 .weibo_icon{background: url(../ieImages/weibo_icon.png)no-rep ...
- HDU4292 Food —— 最大流 + 拆点
题目链接:https://vjudge.net/problem/HDU-4292 Food Time Limit: 2000/1000 MS (Java/Others) Memory Limit ...
- hdu 1075 What Are You Talking About(map)
题意:单词翻译 思路:map #include<iostream> #include<stdio.h> #include<string.h> #include< ...
- 网站页面打开浏览器table中显示图片
就类似博客园这种:
- 西交校赛 F. GZP and Poker
F. GZP and Poker GZP often plays games with his friends.Today they went to a board game.There are n ...