Esspe-Peasee 解方程求最大的x整数解
来源:互联网 发布:淘宝网食用菌种植方法 编辑:程序博客网 时间:2024/05/03 06:35
Esspe-Peasee
Time Limit: 10000ms
Memory Limit: 131072KB
This problem will be judged on UVALive. Original ID: 6170
64-bit integer IO format: %lld Java class name: Main
Prev Submit Status Statistics Discuss Next
Font Size: + -
[PDF Link]
Esspe-Peasee is an ancient game played by children throughout the land of Acmania. The rules are simple:
A player simply quibs the yorba at the kwonk. If the yorba hurms the kwonk the player gets a foom. If the yorba hurfs the kwonk the player gets a foob.
The objective is to get a twob with as few quibs as possible.
Every group of children has its own opinion regarding the value of a foom, the value of a foob, and the value of a twob. However, everyone agrees that a foob is worth more than a foom, and that a twob is worth more than a foob. You may assume that a foom and a foob can each be represented by a 32 bit integer, and a twob can be represented by a 64 bit integer.
Input
You will be given a number of game instances to solve. Each instance is specified by 3 non-negative integers that represent the value of a foom, a foob and a twob, respectively. The final line contains three 0's and should not be processed.
Output
For each instance your program should print `A fooms and B foobs for a twob!', on a line by itself as shown in the samples below, where the value of ``A" fooms plus ``B" foobs add up to a twob, and the sum of ``A" and ``B" is as small as possible. ``fooms" and ``foobs" should be appropriately pluralised, as shown in ``Sample Output" below.
If there is no such pair you should print out the age-old chant: `Unquibable!'
Sample Input
1 6 15
7 9 22
7 9 32
0 9 18
2 5 9
0 0 0
Sample Output
3 fooms and 2 foobs for a twob!
Unquibable!
2 fooms and 2 foobs for a twob!
0 fooms and 2 foobs for a twob!
2 fooms and 1 foob for a twob!
Source
Time Limit: 10000ms
Memory Limit: 131072KB
This problem will be judged on UVALive. Original ID: 6170
64-bit integer IO format: %lld Java class name: Main
Prev Submit Status Statistics Discuss Next
Font Size: + -
[PDF Link]
Esspe-Peasee is an ancient game played by children throughout the land of Acmania. The rules are simple:
A player simply quibs the yorba at the kwonk. If the yorba hurms the kwonk the player gets a foom. If the yorba hurfs the kwonk the player gets a foob.
The objective is to get a twob with as few quibs as possible.
Every group of children has its own opinion regarding the value of a foom, the value of a foob, and the value of a twob. However, everyone agrees that a foob is worth more than a foom, and that a twob is worth more than a foob. You may assume that a foom and a foob can each be represented by a 32 bit integer, and a twob can be represented by a 64 bit integer.
Input
You will be given a number of game instances to solve. Each instance is specified by 3 non-negative integers that represent the value of a foom, a foob and a twob, respectively. The final line contains three 0's and should not be processed.
Output
For each instance your program should print `A fooms and B foobs for a twob!', on a line by itself as shown in the samples below, where the value of ``A" fooms plus ``B" foobs add up to a twob, and the sum of ``A" and ``B" is as small as possible. ``fooms" and ``foobs" should be appropriately pluralised, as shown in ``Sample Output" below.
If there is no such pair you should print out the age-old chant: `Unquibable!'
Sample Input
1 6 15
7 9 22
7 9 32
0 9 18
2 5 9
0 0 0
Sample Output
3 fooms and 2 foobs for a twob!
Unquibable!
2 fooms and 2 foobs for a twob!
0 fooms and 2 foobs for a twob!
2 fooms and 1 foob for a twob!
Source
Regionals 2012, South Pacific
代码:
#include <iostream>#include <stdio.h>#include <cstring>#include <cmath>#include <algorithm>using namespace std;const int M=100005;long long x,y;long long a,b,c;long long solve(long long a,long long b,long long &x,long long &y){ if(b==0) { x=1,y=0; return a; } long long g=solve(b,a%b,x,y); long long t=x; x=y; y=t-(a/b)*y; return g;}int main(){ while(scanf("%lld%lld%lld",&a,&b,&c)!=EOF) { if(!a && !b && !c)break; long long g=solve(a,b,x,y); if(c % g) { printf("Unquibable!\n"); continue; } x=((x%(b/g)*((c/g)%(b/g)))%(b/g)+(b/g))%(b/g); y=(c-a*x)/b; if(y<0) { printf("Unquibable!\n"); continue; } if(x==1) printf("1 foom and "); else printf("%lld fooms and ",x); if(y==1) printf("1 foob for a twob!\n"); else printf("%lld foobs for a twob!\n",y); } return 0;}
- Esspe-Peasee 解方程求最大的x整数解
- ACM 数论 UVALive 6170 Esspe-Peasee 解二元一次方程 扩张欧几里得算法
- UVALive 6170 Esspe-Peasee
- poj 1601(扩展欧几里德求不定方程的整数解)
- 不定式方程求整数解(爱因斯坦的数学题)
- 不定式方程求整数解(换分币)
- 求方程的解
- 二分法求方程的解
- 解含有[x]的方程
- 不定式方程求整数解(年龄问题)
- 不定式方程求整数解(三色球问题)
- 不定式方程求整数解(马克思手稿中的数学题)
- UVALive 6170 (LA 6170) Esspe-Peasee 扩展欧几里得
- poj 2115 求满足同余方程的最小整数解
- 方程整数解条件
- 方程整数解
- UVALive_6170_Esspe-Peasee(求解不定方程)
- 二分法求方程2x³-4x²+3x-6=0的近似解
- 我的博客开通了
- raw soket
- 建网站流程
- 凭证冲销FB08
- SQL Server触发器创建、删除、修改、查看示例
- Esspe-Peasee 解方程求最大的x整数解
- 内存映射文件
- 批处理命令大全
- source insight 函数名出现乱码的解决办法
- 不明觉厉的spring(1)---whyspring
- JavaMail 发送邮件的实例
- C++编程 10.12
- 二维码、条形码扫描——使用Google ZXing
- Debug error R6010 abort() has been called