ax+by+c=0可以转化为ax+by=-c;

可以用扩展欧几里德算法来求ax1+by1=gcd(a,b)来求出x1,y1

此时gcd(a,b)不一定等于-c,假设-c=gcd(a,b)*z,可得z=-c/gcd(a,b);

则ax+by=-c <==> (ax1+by1)*z=gcd(a,b)z;

<==> ax1*z+bx2*z=gcd(a,b)z;

因此可以得知x与x1的关系,y与y1的关系:

x=x1*z,y = y1*z(z上面已经求出来了)

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm> using namespace std; typedef long long ll;
ll r; void gcd(ll a, ll b, ll &x, ll &y)
{
if(b == )
{
x = ;
y = ;
r = a;
return ;
}
gcd(b, a % b, x, y);
int t = x;
x = y;
y = t - a / b * y;
} int main()
{
ll a, b, c, x, y;
while(~scanf("%lld%lld%lld", &a, &b, &c))
{
c = -c;
gcd(a, b, x, y);
if(c % r != )
printf("-1\n");
else
printf("%lld %lld\n", c / r * x, c / r * y);
}
return ;
}

CodeForces 7C Line的更多相关文章

  1. 解题报告:codeforce 7C Line

    codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the pl ...

  2. 欧几里德和扩展欧几里德详解 以及例题CodeForces 7C

    欧几里德定理: 对于整数a,b来说,gcd(a, b)==gcd(b, a%b)==d(a与b的最大公约数),又称为辗转相除法 证明: 因为a是d的倍数,b是d的倍数:所以a%d==0:b%d==0: ...

  3. CF 7C. Line(扩展欧几里德)

    题目链接 AC了.经典问题,a*x+b*y+c = 0整数点,有些忘记了扩展欧几里德,复习一下. #include <cstdio> #include <iostream> # ...

  4. Codeforces 7C 扩展欧几里得

    扩展欧几里得是计算 ax + by = gcd(a,b) 的 x,y的整数解. 现在是ax + by + c = 0; 只要 -c 是 gcd(a,b) 的整数倍时有整数解,整数解是 x = x*(- ...

  5. B - 楼下水题(扩展欧几里德)

    B - 楼下水题 Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit St ...

  6. [codeforces 549]G. Happy Line

    [codeforces 549]G. Happy Line 试题描述 Do you like summer? Residents of Berland do. They especially love ...

  7. [Educational Codeforces Round 16]B. Optimal Point on a Line

    [Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...

  8. CodeForces 549G Happy Line

    Happy Line Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit  ...

  9. Codeforces Round #189 (Div. 1) B. Psychos in a Line 单调队列

    B. Psychos in a Line Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/p ...

随机推荐

  1. 用HTML5 Canvas为网页添加动态波浪背景

    查看所有代码请去Github 本文出自 “UED” 博客:http://5344794.blog.51cto.com/5334794/1430877 <!DOCTYPE html> < ...

  2. spring mvc出现 Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'endtime'

    在使用spring mvc中,绑定页面传递时间字符串数据给Date类型是出错: Failed to convert property value of type [java.lang.String] ...

  3. Spring MVC 下index.jsp访问

    spring-mvc.xml配置 <!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 --> <bean class="org.springframework.we ...

  4. cookie随便写的一点笔记(抄书的)

    cookie是保存在客户端的文本,能够在一定程度上提高用户体验.Servlet API 中提供了Cookie类,可以创建Cookie对象,并通过响应中的addCookie方法,将cookie保存到客户 ...

  5. 旧书重温:0day2【3】 详细解读PEB法 查找kener32地址

    题外话:上一篇文章中的 PEB法查找kerner32地址的方法 对TEB.PEB .PE结构 知识要求很高,确实在写汇编代码时候小编 感觉自己能力,信手啪啪一顿乱撸,结果一运行,非法访问了,没办法翻阅 ...

  6. mac出现一个白条

    mac出现一个白条,除了finder没有任何程序运行,出现好几次了,怎么解决? 打开finder输中文出现 按esc键

  7. RAC 之 RMAN 备份

    这篇主要介绍的是RAC 环境下的RMAN 备份. 关于Oracle 备份与恢复的一些理论知识参考我的Blog:       Oracle 备份 与 恢复 概述 http://blog.csdn.net ...

  8. mysql添加用户和用户权限

    Mysql添加用户使用可以对mysql数据库用户表有操作权限的用户名登陆mysqlinsert into user(Host,User,Password) values('%','name','pas ...

  9. 使用JQuery Mobile实现手机新闻浏览器

    jQuery Mobile项目是jQuery项目下的在移动开发方面的又一力作,在本文中,笔者将带你一步步更深入学习使用jQuery Mobile框架去实现一个能在android手机上运行的新闻浏览器, ...

  10. shell 中数学计算总结

    shell中的赋值和操作默认都是字符串处理,在此记下shell中进行数学运算的几个特殊方法,以后用到的时候可以来看,呵呵.   1.错误方法举例   a)   var=1+1   echo $var  ...