题意:本题给出一个直线,推断是否有整数点在这条直线上;

分析:本题最重要的是在给出的直线是不是平行于坐标轴,即A是不是为0或B是不是为0.。此外。本题另一点就是C输入之后要取其相反数,才干进行扩展欧几里得求解

关于扩展欧几里得详见:http://blog.csdn.net/qq_27599517/article/details/50888092

代码例如以下:

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <math.h>
#include <vector>
#include <utility>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <functional> using namespace std;
long long gcd(long long a,long long b){
if(b==0)return a;
return gcd(b,a%b);
}
void _gcd(long long a,long long b,long long &x,long long &y){
if(b==1){
x=1;
y=1-a;
return;
}
else{
long long x1,y1;
_gcd(b,a%b,x1,y1);
x=y1;
y=x1-(a/b)*x;
}
}
int main(){
long long a,b,c;
scanf("%I64d%I64d%I64d",&a,&b,&c);
c=-c;
if(a==0&&b==0){
puts("-1");
return 0;
}
if(a==0&&b!=0){
if(c%b==0){
cout<<0<<" "<<c/b<<endl;
}
else puts("-1");
return 0;
}
if(a!=0&&b==0){
if(c%a==0){
cout<<c/a<<" "<<0<<endl;
}
else puts("-1");
return 0;
}
int g=gcd(a,b);
if(c%g!=0){
puts("-1");
return 0;
}
c/=g;
a/=g;
b/=g;
long long x,y;
_gcd(a,b,x,y);
x=(x*c%b+b)%b;
y=(c-a*x)/b;
cout<<x<<" "<<y<<endl;
return 0;
}

Line(扩展欧几里得)的更多相关文章

  1. Codeforces7C 扩展欧几里得

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

  2. POJ2115(扩展欧几里得)

    C Looooops Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23700   Accepted: 6550 Descr ...

  3. Root(hdu5777+扩展欧几里得+原根)2015 Multi-University Training Contest 7

    Root Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Su ...

  4. UVA 10090 Marbles(扩展欧几里得)

    Marbles Input: standard input Output: standard output I have some (say, n) marbles (small glass ball ...

  5. [ACM] hdu 3923 Invoker (Poyla计数,高速幂运算,扩展欧几里得或费马小定理)

    Invoker Problem Description On of Vance's favourite hero is Invoker, Kael. As many people knows Kael ...

  6. Root(hdu5777+扩展欧几里得+原根)

    Root                                                                          Time Limit: 30000/1500 ...

  7. Gym100812 L 扩展欧几里得

    L. Knights without Fear and Reproach time limit per test 2.0 s memory limit per test 256 MB input st ...

  8. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C.Ray Tracing (模拟或扩展欧几里得)

    http://codeforces.com/contest/724/problem/C 题目大意: 在一个n*m的盒子里,从(0,0)射出一条每秒位移为(1,1)的射线,遵从反射定律,给出k个点,求射 ...

  9. UVA 12169 Disgruntled Judge 枚举+扩展欧几里得

    题目大意:有3个整数 x[1], a, b 满足递推式x[i]=(a*x[i-1]+b)mod 10001.由这个递推式计算出了长度为2T的数列,现在要求输入x[1],x[3],......x[2T- ...

随机推荐

  1. C++_class_powerpoint_1.1

    Types and Declarations Boolean Type bool type – boolean , logic type bool literal – true, falseint a ...

  2. mysql 从库落后主库太多优化

    有时候为了避免master.info和中继日志崩溃,在容忍额外的fsync()带来的开销,推荐设置sync_master_info = 1sync_relay_log = 1sync_relay_lo ...

  3. xenserver&nbsp;增加新硬盘

    xenserver 增加新硬盘 1.XS创建本地存储 首先 分区好的的硬盘接到服务器上 查看所有硬盘了的id ls -l /dev/disk/by-id/ 记下硬盘的全称.接下来开始挂载  xe sr ...

  4. php obstart

    PHP ob_start() 函数介绍 2010-03-29 php ob_start 与 ob_end_flush() 是 php 的缓冲输出函数. ob_start([string output_ ...

  5. 48.自用qss

    /* R1 */ QDialog { background-image: url(:/images/background.png); } /* R2 */ QLabel { font: 9pt; co ...

  6. linux下恢复被删除的文件

    https://cloud.tencent.com/developer/article/1028317

  7. 解决启动httpd报: apr_sockaddr_info_get() failed for错误

    我测试库里 service httpd start 时报 下面错误 httpd: apr_sockaddr_info_get() failed for fengxin.wzjzt.centoshttp ...

  8. vs code格式化代码快捷键

    windows:shift+alt+F ubuntu: ctrl+shift+i

  9. Substring Uva 11468_记忆化搜索 + AC自动机

    Code: #include<cstdio> #include<cstring> #include<queue> using namespace std; cons ...

  10. 洛谷P1941飞扬的小鸟 完全背包

    思维难度不大,就是有许多细节要注意. 1.不能开滚动数组. 2.要特判飞过天花板的情况. Code: #include<cstdio> #include<algorithm> ...