BZOJ 1477: 青蛙的约会
二次联通门 : BZOJ 1477: 青蛙的约会
/*
BZOJ 1477: 青蛙的约会 扩展欧几里得
列出方程, 判断一下
*/
#include <iostream>
#include <cstdio>
typedef long long LL;
#define rg register
void read (LL &n)
{
rg char c = getchar ();
for (n = ; !isdigit (c); c = getchar ());
for (; isdigit (c); n = n * + c - '', c = getchar ());
}
LL Extend_Euclid (LL a, LL b, LL &x, LL &y)
{
if (!b) { x = , y = ; return a; }
LL now = Extend_Euclid (b, a % b, x, y);
LL res = x; x = y, y = res - a / b * y; return now;
}
LL N, M, Length, X, Y;
int main (int argc, char *argv[])
{
read (X), read (Y), read (M), read (N), read (Length);
LL now_1, now_2, now = Extend_Euclid ((N - M), Length, now_1, now_2);
LL R = Length / now;
if ((X - Y) % now) printf ("Impossible");
else printf ("%lld", ((X - Y) / now * now_1 % R + R) % R); return ;
}
BZOJ 1477: 青蛙的约会的更多相关文章
- 【扩展欧几里得】Bzoj 1477:青蛙的约会
Description 两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面.它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止.可是它们出发之前忘记了一件很重要的事 ...
- bzoj 1477: 青蛙的约会【exgcd】
列出式子是\( mx+s1\equiv nx+s2(mod L) (m-n)x+Ly=s2-s1 \),注意如果n-m<0的话,就把ac都乘-1变成正数,然后exgcd求解,最后注意x为负的话要 ...
- 【BZOJ】1477 青蛙的约会
[算法]扩展欧几里德算法(模线性方程) [题解]http://hzwer.com/2121.html 一些问题写在http://www.cnblogs.com/onioncyc/p/6146143.h ...
- BZOJ-1477 青蛙的约会 拓展欧几里德
充权限之前做的...才来交 1477: 青蛙的约会 Time Limit: 2 Sec Memory Limit: 64 MB Submit: 369 Solved: 233 [Submit][Sta ...
- 【POJ】【1061】/【BZOJ】【1477】青蛙的约会
扩展欧几里德 根据题意列出不定方程: (x+m*T)-(y+n*T)=k*L; //T表示跳了T次,由于是环,可能追了多圈,所以结果应为k*L 化简得 T(m-n)-kL=y-x; 这就成了我们熟悉 ...
- 【POJ】1061 青蛙的约会 / 【BZOJ】1477(扩欧)
青蛙的约会 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 119148 Accepted: 25070 Descript ...
- POJ1061青蛙的约会[扩展欧几里得]
青蛙的约会 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 108911 Accepted: 21866 Descript ...
- poj 1061 青蛙的约会 拓展欧几里得模板
// poj 1061 青蛙的约会 拓展欧几里得模板 // 注意进行exgcd时,保证a,b是正数,最后的答案如果是负数,要加上一个膜 #include <cstdio> #include ...
- POJ 1061青蛙的约会(拓展欧几里德算法)
题目链接: 传送门 青蛙的约会 Time Limit: 1000MS Memory Limit: 65536K Description 两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见 ...
随机推荐
- Redis主从架构搭建和哨兵模式(四)
一主一从,往主节点去写,在从节点去读,可以读到,主从架构就搭建成功了 1.启用复制,部署slave node wget http://downloads.sourceforge.net/tcl/tcl ...
- .net 使用SqlBulkCopy批量插入数据库
//一次批量插入100W条数据到数据库 static void Main(string[] args) { System.Random a = new Random(System.DateTime.N ...
- P1018 乘积最大(DP)
题目 P1018 乘积最大 解析 区间DP 设\(f[i][j]\)表示选\(i\)个数,插入\(j\)个乘号时的最大值 设\(num[i][j]\)是\(s[i,j]\)里的数字 转移方程就是\(f ...
- Python进阶----SOCKET套接字基础, 客户端与服务端通信, 执行远端命令.
Python进阶----SOCKET套接字基础, 客户端与服务端通信, 执行远端命令. 一丶socket套接字 什么是socket套接字: 专业理解: socket是应用层与TCP/IP ...
- permission 权限清单
<uses-permission android:name="android.permission.READ_CALENDAR" /> <uses-permiss ...
- JavaWeb 之 Filter:过滤器
一.Filter 概述 1.概念 web 中的过滤器:当访问服务器的资源时,过滤器可以将请求拦截下来,完成一些特殊的功能. 2.作用 一般用于完成通用的操作.如:登录验证.统一编码处理.敏感字符等功能 ...
- FI-BTEs增强FIBF
https://wenku.baidu.com/view/8a31a4bafd0a79563c1e72f6.html 1.事务码FIBF 2.激活
- 2647673 - HANA Installation Failure with signal 11 core dumped
Symptom HANA 2.0 SPS03 installation using hdblcmgui failed due to the below error message. [Error] / ...
- win下maridb 10.1.8下主从复制配置
主库配置 server_id=1read-only=0replicate-do-db=mydatalog-bin=mysql-bin 主库权限设置 GRANT replication slave ON ...
- pgrep,pkill
pgrep, pkill - look up or signal processes based on name and other attributes 根据名称和其它属性来查找进程 pgrep: ...