HDU - Mr. Frog’s Problem(数学判断)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5924
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)

Problem Description

One day, you, a clever boy, feel bored in your math class, and then fall asleep without your control. In your dream, you meet Mr. Frog, an elder man. He has a problem for you.

He gives you two positive integers A and B, and your task is to find all pairs of integers (C, D), such that  and 

Input

first line contains only one integer T (), which indicates the number of test cases. Each test case contains two integers A and B ().

Output

For each test case, first output one line "Case #x:", where x is the case number (starting from 1). 

Then in a new line, print an integer s indicating the number of pairs you find.

In each of the following s lines, print a pair of integers C and D. pairs should be sorted by C, and then by D in ascending order.

Sample Input

2
10 10
9 27

Sample Output

Case #1:
1
10 10
Case #2:
2
9 27
27 9

Problem solving report:

Description: 给你两个正整数A和B,要求找出所有的整数对(C,D)满足:A≤C≤B,A≤D≤B且A/B+B/A≤C/D+D/C。
Problem solving: 因为C/D+D/C是对称的,所以我们不妨假设D≥C,故可令D=C+e,(e>=0)
为了简化运算,我们令D=C+k(k≥0),即C=D-k,

因由上式可知,当k越大时,C/D+D/C越大,而k又是D与C的差值,故当C=min(C)=A,D=max(D)=B时,k才是最大的,此时C/D+D/C达到最大,等于A/B+B/A,即C/D+D/C的最大值为A/B+B/A,故满足A/B+B/A≤C/D+D/C的情况只有A/B+B/A=C/D+D/C这种情况,故满足A/B+B/A≤C/D+D/C的解仅有A==C&&B==D||A==D&&B==C,而当A==B时,解唯一,即A==B==C==D。

Accepted Code:

/* 
 * @Author: lzyws739307453 
 * @Language: C++ 
 */
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t, kase = 0;
    long long A, B;
    scanf("%d", &t);
    while (t--) {
        scanf("%lld%lld", &A, &B);
        printf("Case #%d:\n", ++kase);
        if (A != B) {
            puts("2");
            if (A > B)
                swap(A, B);
            printf("%lld %lld\n", A, B);
            printf("%lld %lld\n", B, A);
        }
        else printf("1\n%lld %lld\n", A, B);
    }
    return 0;
}
全部评论

相关推荐

千千倩倩:简历问题有点多,加v细聊
点赞 评论 收藏
分享
头像
昨天 16:48
已编辑
百度_高级研发工程师
事实是检验真理的唯一标准。&nbsp;无论我们怎么去说,去讲述,去证明,都抵不过一个offer来得实在,无论我们怎么去复现求职中的摸爬滚打、扒皮抽筋、狼狈不堪,都抵不过你在简历写上大厂的名字(外包不算)。&nbsp;所以在我求职期间,我什么话都不说,什么话都不讲,因为没有意义,虽然我总讲过程才是意义,但只有当你上岸的那一刻,你才有资格回想在水里的挣扎,只有等你出了山,你才知道山的全貌。&nbsp;我为什么一定要离开华为OD,难道它不稳定吗,不能赚钱吗。为了证明自己,那肯定有的。其实更多的是印证我的认知是否真的正确。&nbsp;(给不了解我的人交代一下背景,在下双非一本,gap一年,华为OD外包,摸爬滚打4个月,艰难上岸百度正编)一、...
先锋战士:说得很真诚。鄙视链自古有之,学历,家庭背景,财富,权利。从小有之,小学羡慕那些当班委的,中学羡慕那些学生会的,高中羡慕尖子班拿教学金的,大学羡慕高绩点,毕业了羡慕进大厂的。工作了,又羡慕高职级的,再后来又羡慕别人早早结婚的。我想表达的观点很简单,无论是华为od还是百度,都是经历,没有孰高孰低,为了抵达下一个风景,总会付出更多东西,但不就是人生吗?正如登山,每个阶段的山,都要想办法攀登,在博主的文字中,见到了坚持和积极寻找问题解决办法的心态
学历对求职的影响
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务