CF787A - The Monster
/*
CF787A - The Monster
http://codeforces.com/contest/787/problem/A
数学 扩展欧几里得
注意x或y为0的时候要特判
并且结果要大于b和d
*/
#include <cstdio>
int ex_gcd(int a,int b,int &x,int &y)//solve x,y in a*x+b*y=ex_gcd(a,b,x,y)=gcd(a,b);
{
if(b==)
{
x=;
y=;
return a;
}
int ans=ex_gcd(b,a%b,x,y);
int tmp=x;
x=y;
y=tmp-a/b*y;
return ans;
//x = x0 + (b/gcd)*t
//y = y0 – (a/gcd)*t }
int main()
{
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
int l=d-b;
int x,y;
if((b-d)%c== && (b-d)/c>= )//特判x==0时
{
printf("%d\n",b);
return ;
}
if((d-b)%a== && (d-b)/a>= )//特判y==0时
{
printf("%d\n",d);
return ;
}
int gcd=ex_gcd(a,c,x,y);
if(l%gcd)
{
printf("-1\n");
return ;
}
x*=l/gcd;
c/=gcd;
if(c<)
c=-c;
x%=c;
while(x<= || b+x*a<d)//结果要大于b和d
x+=c;
printf("%d\n",b+x*a);
return ;
}
CF787A - The Monster的更多相关文章
- hdu4950 Monster (水题)
4950 Monster Monster Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- codeforces 487A A. Fight the Monster(二分)
题目链接: A. Fight the Monster time limit per test 1 second memory limit per test 256 megabytes input st ...
- 【BZOJ】【3856】Monster
又是一道水题…… 重点是分情况讨论: 首先我们很容易想到,如果a*k-b*(k+1)>0的话那么一定能磨死Monster. 但即使不满足这个条件,还有可能打死boss: 1.h-a<1也就 ...
- HDU 4950 Monster (水题)
Monster 题目链接: http://acm.hust.edu.cn/vjudge/contest/123554#problem/I Description Teacher Mai has a k ...
- Codeforces Round #278 (Div. 1) A. Fight the Monster 暴力
A. Fight the Monster Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/ ...
- Codeforces Round #328 (Div. 2) B. The Monster and the Squirrel 打表数学
B. The Monster and the Squirrel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/c ...
- 前端性能优化工具--DOM Monster
当我们开发web应用的时候,性能是一个永远不能回避的问题.其实对于DOM的性能调试也是一个不可或缺的过程.使用DOM monster你只需要添加到你的”书签中“,在任何需要调试的页面点击这个书签,它就 ...
- HDU 2616 Kill the monster (暴力搜索 || 终极全阵列暴力)
主题链接:HDU 2616 Kill the monster 意甲冠军:有N技能比赛HP有M怪物,技能(A,M),能伤害为A.当怪兽HP<=M时伤害为2*A. 求打死怪兽(HP<=0)用的 ...
- 3856: Monster
3856: Monster Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 351 Solved: 161[Submit][Status][Discuss ...
随机推荐
- JVM —— Java 对象占用空间大小计算
零. 为什么要知道 Java 对象占用空间大小 缓存的实现: 在设计 JVM 内缓存时(不是借助 Memcached. Redis 等), 须要知道缓存的对象是否会超过 JVM 最大堆限制, 假设会超 ...
- leetCode 74.Search a 2D Matrix(搜索二维矩阵) 解题思路和方法
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...
- luogu3953 逛公园
正解:SPFA+DP 将POJ3463中maxDist(Target)由minDist(Target)+1改为minDist(Target+K)即可.判断0环,需要对每个节点建立下标为maxDist- ...
- Linux - xshell 链接CentOS 设置高亮
默认是黑白的! 用了vim 指令还是黑白的. 两种途径设置,一种是通过Alt+P. 一种是选择配色方案来设置.
- CodeForces 660A
Description You are given an array of n elements, you must make it a co-prime array in as few moves ...
- poj--3624--Charm Bracelet(动态规划 水题)
Home Problem Status Contest Add Contest Statistic LOGOUT playboy307 UPDATE POJ - 3624 Charm Bracelet ...
- [HDU 6318] Swaps and Inversions
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6318 [算法] 线段树 / 树状数组 [代码] #include<bits/stdc++.h ...
- JavaScript --晋级--优
https://zhuanlan.zhihu.com/p/23412169 总计划 JavaScript 教程 http://www.w3school.com.cn/js/ JavaScr ...
- mfs使用指引
客户端工具集 mfsgetgoal #设定副本数 mfssetgoal #获取副本数 mfscopygoal # mfsgetsclass mfssetsclass mfscopysclass mfs ...
- php word转pdf
我们知道,PHP语言的合理运用可以帮助我们实现导出Word文档的功能.今天我们将为大家介绍PHP处理Word转PDF的相关实现方法. PHP关键字this指向当前对象指针 PHP self关键字指向类 ...