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. Win7平台下Cocos2d-x环境搭建

    一.Win7下Cocos2d-x环境搭建 Cocos开发者平台官网——在这里下载游戏引擎           解压放到某个目录下即可 https://www.python.org/downloads/ ...

  2. [转载] mysql5.6 删除之前的ibdata1文件后再重新生成,遇到[Warning] Info table is not ready to be used. Table 'mysql.slave_master_info' cannot be opened.问题

    [转载] mysql5.6 删除之前的ibdata1文件后再重新生成,遇到[Warning] Info table is not ready to be used. Table 'mysql.slav ...

  3. PS4破解

    1.输入序列号: # 序列号: # 1330-1082-3503-2270-3738-6738# 1330-1776-8671-6289-7706-2916# 1330-1567-6599-8775- ...

  4. 【英语】Bingo口语笔记(22) - Talk系列

    talk back 顶嘴 talk somebody in to something 劝某人做某事 tal somebody out of something 劝某人不做某事

  5. where group by联合使用

    where group by联合使用   select 列a,聚合函数 from 表名 where 过滤条件 group by 列a having 过滤条件 group by 字句也和where条件语 ...

  6. unity, surface shader access world position and localposition

    一,surface shader中访问worldposition 在surface shader中访问世界坐标,只需在Input结构体中声明float3 worldPos即可,如下:  struct  ...

  7. ios ViewController 页面跳转

    从一个Controller跳转到另一个Controller时,一般有以下2种: 1.利用UINavigationController,调用pushViewController,进行跳转:这种采用压栈和 ...

  8. ECSide标签属性说明之<ec:table>

    <ec:table>标签说明 ◆ 属性: tableId描述: 设置列表的唯一标识,默认为"ec",当一个页面内有多个ECSIDE列表时,必须为每个列表指定不同的tab ...

  9. [Everyday Mathematic]20150213

    设 $f:\bbR\to\bbR$ 三阶可微, 试证: 存在 $\xi\in (-1,,1)$, 使得 $$\bex \frac{f'''(\xi)}{6}=\frac{f(1)-f(-1)}{2}- ...

  10. 【leetcode】Find Minimum in Rotated Sorted Array II JAVA实现

    一.题目描述 Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed ...