解题报告:codeforce 7C Line
codeforce 7C
C. Line
time limit per test1 second
memory limit per test256 megabytes
A line on the plane is described by an equation Ax + By + C = 0. You are to find any point on this line, whose coordinates are integer numbers from - 5·1018 to 5·1018 inclusive, or to find out that such points do not exist.
Input
The first line contains three integers A, B and C ( - 2·109 ≤ A, B, C ≤ 2·109) — corresponding coefficients of the line equation. It is guaranteed that A2 + B2 > 0.
Output
If the required point exists, output its coordinates, otherwise output -1.
Examples
input
2 5 3
output
6 -3
代码如下:
#include <iostream>
using namespace std;
typedef long long ll;
ll ex_gcd(ll a, ll b, ll&x, ll&y)
{
if(b == 0)
{
x = 1;
y = 0;
return a;
}
int ans = ex_gcd(b,a%b,x,y);
int tmp = x;
x = y;
y = tmp - a/b * y;
return ans;
}
int main()
{
ll x, y;
ll a, b, c;
cin >> a >> b >> c;
c *= -1;
ll gcd = ex_gcd(a,b,x,y);
if(c%gcd)
{
cout << "-1" << endl;
}
else
{
int k = c/gcd;
x *= k;
y *= k;
cout << x << " " << y << endl;
}
return 0;
}
扩展欧几里得算法
解题报告:codeforce 7C Line的更多相关文章
- LeetCode 解题报告索引
最近在准备找工作的算法题,刷刷LeetCode,以下是我的解题报告索引,每一题几乎都有详细的说明,供各位码农参考.根据我自己做的进度持续更新中...... ...
- ACM: Just a Hook 解题报告 -线段树
E - Just a Hook Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u D ...
- Facebook Hacker Cup 2014 Qualification Round 竞赛试题 Square Detector 解题报告
Facebook Hacker Cup 2014 Qualification Round比赛Square Detector题的解题报告.单击这里打开题目链接(国内访问需要那个,你懂的). 原题如下: ...
- C-C Radar Installation 解题报告
C-C Radar Installation 解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#pr ...
- 2015 Multi-University Training Contest 6 solutions BY ZJU(部分解题报告)
官方解题报告:http://bestcoder.hdu.edu.cn/blog/2015-multi-university-training-contest-6-solutions-by-zju/ 表 ...
- ZOJ_3950_How Many Nines 解题报告及如何对程序进行测试修改
The 17th Zhejiang University Programming Contest Sponsored by TuSimple Solution: #include <stdio. ...
- HDU 4303 Hourai Jeweled 解题报告
HDU 4303 Hourai Jeweled 解题报告 评测地址: http://acm.hdu.edu.cn/showproblem.php?pid=4303 评测地址: https://xoj. ...
- CYJian的水题大赛2 解题报告
这场比赛是前几天洛谷上 暮雪﹃紛紛dalao的个人公开赛,当时基本上都在水暴力分......也没有好好写正解(可能除了T1) 过了几天颓废的日子之后,本蒟蒻觉得应该卓越一下了qwq,所以就打算写一个解 ...
- ACM-ICPC 2017 Asia HongKong 解题报告
ACM-ICPC 2017 Asia HongKong 解题报告 任意门:https://nanti.jisuanke.com/?kw=ACM-ICPC%202017%20Asia%20HongKon ...
随机推荐
- Storm-源码分析-LocalState (backtype.storm.utils)
LocalState A simple, durable, atomic K/V database. *Very inefficient*, should only be used for occas ...
- 策略(strategy)模式
Head First一书中对于策略(strategy)模式的正式定义是:策略模式定义了算法族,分别封装起来,让他们之间可以相互替换,此模式让算法的变化独立于使用算法的客户. 为了介绍这个算法,书中讲了 ...
- linux物理页面的换入换出简析
2017-04-25 我们都知道,现代操作系统使用分页机制和虚拟内存,同时为了提高物理页面的利用率,采用了请求调页的机制,即物理内存的分配只有在真正需要的时候才会进行,比如发生了真正的读写操作,而普通 ...
- 进程Process之join、daemon(守护)、terminate(关闭)
一.Process 参数介绍: 1 group参数未使用,值始终为None 2 target表示调用对象,即子进程要执行的任务 3 args表示调用对象的位置参数元组,args=(1,2,'a',) ...
- mysql删除重复数据,保留最新的那一条
因为数据库没键外键,在关联查询的时候,会碰到查询条数多余数据库实际条数,这因为关联字段在表中有重复值而导致的. 解决方案: 1.数据库脚本删除重复数据,保留最新的一条 2.对关联字段增加唯一约束 例如 ...
- mysql 约束条件 auto_increment 自动增长 创建表时设置自增字段
auto_increment mysql) )auto_increment; Query OK, rows affected (0.01 sec) mysql> show create tabl ...
- DiskLruCache详解 From GuoLin Blogs.
作者:郭霖老师,<第一行代码>作者,开源框架LitePal作者 http://blog.csdn.net/guolin_blog/article/details/28863651 概述 记 ...
- JQuery能够高效地操作页面元素
关于DOM和CSS的页面元素选择: $("span"); //全部span元素 $("#elem"); //id为elem的元素 $(".c ...
- 判断是否关注了微信公众号 subscribe 0=未关注 1=已关注
$appid=''; $secret=''; //微信网页授权获取openid $web_url='http://www.xxxx.com/shouquan.php'; if (!isset($_GE ...
- C的指针疑惑:C和指针10(结构和联合)
结构也可以作为传递给函数的参数,它们也可以作为返回值从函数返回,相同类型的结构体变量相互之间可以赋值. 申明结构时使用另一种良好技巧是用typedef创建一种新的类型. typedef struct{ ...