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

分析:本题最重要的是在给出的直线是不是平行于坐标轴,即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. JPA设置表名和实体名,表字段与实体字段的对应

    转自:https://blog.csdn.net/LQW_java_home/article/details/53079363 首先 你的jpaProperties配置项中要有 <prop ke ...

  2. struts的工作流程

    - 一个请求过来,走前端控制器StrutsPrepareAndExecuteFilter        -前端控制器是一个过滤器,过滤器中的核心方法是doFilter(),doFilter方法中首先处 ...

  3. 3.TinkPHP中的模型

    1.配置数据库的连接设置 数据库的连接配置项可以在系统的主配置文件中 2.什么是模型? 模型是MVC 三大组成部分的M,作用是负责与数据表达额交互(CRUD) 3.模型的创建 命名规范:不带前缀的标明 ...

  4. tomcat 启动服务器日志小结

    1.tomcat 启动服务配置: 目前主要有  ①把编译好war或者项目直接扔到webapps 目录下, 启动bin目录下的startup.bat 即可   ②  在conf目录下 修改  serve ...

  5. js-字符串方法

    字符串 遍历字符串 方法:(类似数组) 使用for 或 for… in      结果:得到字符串中的每个字符 查找字符 ²  charAt(索引值) 注: 超出索引值范围时,则返回空字符 ²  ch ...

  6. mybatis 高级映射和spring整合之逆向工程(7)

    mybatis 高级映射和spring整合之逆向工程(7) 4.0 逆向工程 4.1 mybatis需要程序员自己编写sql语句,mybatis官方提供逆向工程,可以针对单表自动生成mybatis执行 ...

  7. 编译OpenCV遇到Qmake问题

    1.Ubuntu安装OpenCv,出现:qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or ...

  8. SciPy和Numpy处理能力

    1.SciPy和Numpy的处理能力: numpy的处理能力包括: a powerful N-dimensional array object N维数组: advanced array slicing ...

  9. 查看tomcat的内存情况

    查看现有tomcat的内存大小情况 1.启动tomcat 2.访问 http://localhost:8080/manager/status ,并输入您在安装tomcat时输入的用户与口令,如 adm ...

  10. (转)RabbitMQ学习之exchange总结

    http://blog.csdn.net/zhu_tianwei/article/details/53969674 前面介绍了几类exchange的作用,这个总结一下: direct:消息会被推送至绑 ...