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中是这么 ...
随机推荐
- Python中Queue模块及多线程使用
Python的Queue模块提供一种适用于多线程编程的FIFO实现.它可用于在生产者(producer)和消费者(consumer)之间线程安全(thread-safe)地传递消息或其它数据,因此多个 ...
- 小度WiFi
这个东西真不错,详情查看: http://wifi.baidu.com 是在京东上抢购的,但是那次抢购体验做得很次:首先,只能预约一种颜色;其次,第一天抢购了,第2天就不能抢购了;第三,等抢购完了,如 ...
- [Canvas]Bombman v1.00
爆破小人Canvas版,请点此下载,并用浏览器打开试玩. 图例: 源码: <!DOCTYPE html> <html lang="utf-8"> <m ...
- ArrayList vs LinkedList 空间占用
空间占用上,ArrayList完胜 看下两者的内存占用图 这三个图,横轴是list长度,纵轴是内存占用值.两条蓝线是LinkedList,两条红线是ArrayList,可以看到,LinkedLis ...
- pycharm调整代码长度分割线
1.File -> Settings -> Code Style -> Right margin (columns) 的值为80,大功告成. 2.具体设置的数值可以根据个人电脑 ...
- Swift 计算三角形角度、两条边夹角
/// 计算三点之间的角度 /// /// - Parameters: /// - p1: 点1 /// - p2: 点2(也是角度所在点) /// - p3: 点3 /// - Returns: 角 ...
- R中统计假设检验总结(一)
先PS一个:考虑到这次的题目本身的特点 尝试下把说明性内容都直接作为备注写在语句中 另外用于说明的部分例子参考了我的教授Guy Yollin在Financial Data Analysis and M ...
- 讲一讲MySQL如何防止“老鼠屎”类型的SQL语句
[原谅我标题党了] 当然不可能有哪一个SQL语句会这么出名,以至于大家叫它“老鼠屎”:但是有一些SQL语句确实主是做着这样的事:由于程序的 局部性原理,数据库会把常用的数据缓存到内存中,对于这种场景通 ...
- 服务端怎样暴露IBinder接口对象
服务端怎样暴露IBinder接口对象: package com.example.mydownload; import android.app.Service; import android.conte ...
- JAVA和JAVAC 命令行
转自:http://www.blogjava.net/pdw2009/archive/2008/06/12/207413.html?opt=admin javac和java命令行中的-classpat ...