J - Romantic
The Sky is Sprite.
The Birds is Fly in the Sky.
The Wind is Wonderful.
Blew Throw the Trees
Trees are Shaking, Leaves are Falling.
Lovers Walk passing, and so are You.
................................Write in English class by yifenfei

Girls are clever and bright. In HDU every girl like math. Every girl like to solve math problem!
Now tell you two nonnegative integer a and b. Find the nonnegative integer X and integer Y to satisfy Xa + Yb = 1. If no such answer print "sorry" instead.
Input
The input contains multiple test cases.
Each case two nonnegative integer a,b (0<a, b<=2^31)
Output
output nonnegative integer X and integer Y, if there are more answers than the X smaller one will be choosed. If no answer put "sorry" instead.
Sample Input
77 51
10 44
34 79
Sample Output
2 -3
sorry
7 -3
直接用拓展欧几里得,但是注意Find the nonnegative integer X and integer Y,f there are more answers than the X smaller one will be choosed.
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define pb push_back
#define mm(a,b) memset((a),(b),sizeof(a))
#include<vector>
typedef __int64 ll;
typedef long double ld;
const ll mod=1e9+7;
using namespace std;
const double pi=acos(-1.0);
ll exgcd(ll a,ll b,ll &x,ll &y)//x,y在输入的时候不用定义
{
int d, t;
if(b==0)
{
x=1;
y=0;
return a;
}else
{
d = exgcd(b, a % b,x,y);
t = x - a / b * y;
x = y;
y = t;
return d;
}
}
int main()
{
ll a,b,r,x,y;
while(~scanf("%I64d%I64d",&a,&b))
{
r=exgcd(a,b,x,y);
if(r!=1)
pf("sorry\n");
else
{
while(x<0)
{
x+=b;
y-=a;
}
pf("%I64d %I64d\n",x,y);
}
}
return 0;
}
J - Romantic的更多相关文章
- HDU 4901 The Romantic Hero
The Romantic Hero Time Limit: 3000MS Memory Limit: 131072KB 64bit IO Format: %I64d & %I64u D ...
- HDU4901 The Romantic Hero 计数DP
2014多校4的1005 题目:http://acm.hdu.edu.cn/showproblem.php?pid=4901 The Romantic Hero Time Limit: 6000/30 ...
- HDU 4901 The Romantic Hero(二维dp)
题目大意:给你n个数字,然后分成两份,前边的一份里面的元素进行异或,后面的一份里面的元素进行与.分的时候依照给的先后数序取数,后面的里面的全部的元素的下标一定比前面的大.问你有多上种放元素的方法能够使 ...
- HDU 4901 The Romantic Hero 题解——S.B.S.
The Romantic Hero Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- HDOJ 4901 The Romantic Hero
DP....扫两次合并 The Romantic Hero Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 ...
- 【Java并发编程实战】-----“J.U.C”:CAS操作
CAS,即Compare and Swap,中文翻译为"比较并交换". 对于JUC包中,CAS理论是实现整个java并发包的基石.从整体来看,concurrent包的实现示意图如下 ...
- 【Java并发编程实战】-----“J.U.C”:Exchanger
前面介绍了三个同步辅助类:CyclicBarrier.Barrier.Phaser,这篇博客介绍最后一个:Exchanger.JDK API是这样介绍的:可以在对中对元素进行配对和交换的线程的同步点. ...
- 【Java并发编程实战】-----“J.U.C”:CountDownlatch
上篇博文([Java并发编程实战]-----"J.U.C":CyclicBarrier)LZ介绍了CyclicBarrier.CyclicBarrier所描述的是"允许一 ...
- 【Java并发编程实战】-----“J.U.C”:CyclicBarrier
在上篇博客([Java并发编程实战]-----"J.U.C":Semaphore)中,LZ介绍了Semaphore,下面LZ介绍CyclicBarrier.在JDK API中是这么 ...
随机推荐
- C# ConcurrentQueue实现
我们从C# Queue 和Stack的实现知道Queue是用数组来实现的,数组的元素不断的通过Array.Copy从一个数组移动到另一个数组,ConcurrentQueue我们需要关心2点:1线程安全 ...
- spark run using IDE / Maven
来自:http://stackoverflow.com/questions/26892389/org-apache-spark-sparkexception-job-aborted-due-to-st ...
- 解决nginx access日志中400 bad request 错误(转)
在access.log中有大量400错误,并以每天几百M的速度增加,占用大量空间.tail -f /opt/nginx/logs/access.log 116.236.228.180 - - [15/ ...
- <转>房租分配问题
本文转自:https://blog.codingnow.com/2012/12/share_rent.html 今天读到策划同学的周报中提到的一个关于合租房子的分摊房租问题. 引用周报中的一节如下: ...
- 门户级UGC系统的技术进化路线 [转]
原文链接 :http://weibo.com/p/1001603789147444803230 新闻门户网站的评论系统,或者称为跟帖.留言板,是所有门户网站的核心标准服务组件之一.与论坛.博客等其 ...
- VisualVM、JConsole
VisualVM.JConsole 需要熟悉JVM内存模型 https://blog.csdn.net/libaolin198706231987/article/details/55057149 ht ...
- Java Web开发基础零星知识
1. Web的三个核心标准 万维网的核心标准有三个,分别是URL.HTTP和HTML. URL(统一资源定位符,Universal Resource Locator),为描述Internet上的网页以 ...
- 从NSTimer的失效性谈起(二):关于GCD Timer和libdispatch
一.GCD Timer的创建和安放 尽管GCD Timer并不依赖于NSRunLoop,可是有没有可能在某种情况下,GCD Timer也失效了?就好比一開始我们也不知道NSTimer相应着一个runl ...
- 每天一个linux命令(8):scp使用
不同的Linux之间copy文件常用有3种方法:1.使用ftp,也就是其中一台Linux安装ftp Server,这样可以另外一台使用ftp的client程序来进行文件的copy.2.采用samba服 ...
- Adam算法
结合了Momentum 和RMSprop算法的优点