Mr. Frog’s Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 312    Accepted Submission(s): 219

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 A≤C≤B,A≤D≤B and AB+BA≤CD+DC

 
Input
first line contains only one integer T (T≤125), which indicates the number of test cases. Each test case contains two integers A and B (1≤A≤B≤1018).
 
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
 
Source
 
Recommend
wange2014   |   We have carefully selected several similar problems for you:  5932 5931 5930 5929 5928 
 

Statistic | Submit | Discuss | Note

题目链接:

  http://acm.hdu.edu.cn/showproblem.php?pid=5924

题目大意:

  题目给定A和B(<=1018),求满足的C和D个个数,并全部输出。

题目思路:

  【模拟】

  +1s 这题一看样例就猜大概只有AB,BA两种情况。不妨假设C<=D

  假设A/B+B/A>A/(B-1)+(B-1)/A,解得条件为B2-B>A2,所以如果要满足,则需要A2>=B2-B,而只有当A=B时满足(B>=A,B=A+1时,B2-B=A(A+1)>A2)

  所以除了A=B的情况,其余都是减的,(C,D)可视为(A,B)->(A,D)->(C,D),每次只改一维,递减,所以最终也是递减的。

  所以最终答案就是AB,BA 注意A=B的情况。

 //HDU 5924
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-10)
#define J 10000
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#define N 100004
using namespace std;
typedef long long LL;
double anss;
LL aans;
int cas,cass;
LL n,m,lll,ans; int main()
{
#ifndef ONLINE_JUDGEW
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
int x,y,z;
// init();
// for(scanf("%d",&cass);cass;cass--)
for(scanf("%d",&cas),cass=;cass<=cas;cass++)
// while(~scanf("%s",s))
// while(~scanf("%d%d",&n,&m))
{
printf("Case #%d:\n",cass);
scanf("%lld%lld",&n,&m);
if(n==m)printf("%d\n%lld %lld\n",,n,m);
else printf("%d\n%lld %lld\n%lld %lld\n",,n,m,m,n);
}
return ;
}
/*
// //
*/

HDU 5924 Mr. Frog’s Problem 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)的更多相关文章

  1. HDU 5926 Mr. Frog's Game 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)

    Mr. Frog's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  2. HDU 5929 Basic Data Structure 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)

    Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  3. HDU 5922 Minimum’s Revenge 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)

    Minimum's Revenge Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  4. HDU 5925 Coconuts 【离散化+BFS】 (2016CCPC东北地区大学生程序设计竞赛)

    Coconuts Time Limit: 9000/4500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  5. HDU 5927 Auxiliary Set 【DFS+树】(2016CCPC东北地区大学生程序设计竞赛)

    Auxiliary Set Time Limit: 9000/4500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  6. 2016CCPC东北地区大学生程序设计竞赛1008/HDU 5929 模拟

    Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  7. 2016CCPC东北地区大学生程序设计竞赛 (2018年8月22日组队训练赛)

    题目链接:http://acm.hdu.edu.cn/search.php?field=problem&key=2016CCPC%B6%AB%B1%B1%B5%D8%C7%F8%B4%F3%D ...

  8. 2016CCPC东北地区大学生程序设计竞赛 1003 HDU5924

    链接http://acm.hdu.edu.cn/showproblem.php?pid=5924 题意:根据公式求C,D 解法:打表找规律 #include <bits/stdc++.h> ...

  9. 2016CCPC东北地区大学生程序设计竞赛 1008 HDU5929

    链接http://acm.hdu.edu.cn/showproblem.php?pid=5929 题意:给你一种数据结构以及操作,和一种位运算,最后询问:从'栈'顶到低的运算顺序结果是多少 解法:根据 ...

随机推荐

  1. IIS配置不正确可能导致“远程服务器返回错误: (404) 未找到"错误一例。

    今天上传附件出现了下图所示的问题: 查找百度发现http://www.cnblogs.com/chuncn/archive/2009/09/08/1562759.html 文中提的比较靠谱. 但是,设 ...

  2. arcgis engine - 添加图例,指北针.

    esri帮助提供了使用比例尺的方法: Working with map surrounds 主要代码为: public void AddMapSurround(IPageLayout pageLayo ...

  3. HTML基础(1) 全局架构标签,特殊字符

    最基本的网页文件组成部分 其中 <head></head> 这个标签对中内容不会显示在网页中 <body></body> 中的内容可以显示在网页中. b ...

  4. 第4条:多用类型常量,少用#define预处理指令

    定义常量的几种方式: 1.#define ANIMATION_DURAION 0.3         //定义了一个动画时长的常量, 预处理过程会把碰到的所有ANIMATION_DURAION一律替换 ...

  5. 关于Java的一道内存的题目

    import java.util.Arrays; import java.util.EmptyStackException; public class MyStack<T> { priva ...

  6. 设计模式之 Observer Pattern 观察者模式

    1.Subject通过一个容器保存零到多个Observer. 2.Subject通过Add,Delete方法调整Observer. 3.Subject的notifyObservers方法实际是逐个调用 ...

  7. pip 的 Assert Error

    在Ubuntu 14.04 中安装了Python之后,使用pip freeze,出现AssertError. 发现是pip版本太低,只有1.5.6 更新pip之后就OK了.

  8. struts2 package元素

    <package../>元素         name         必选    包名         extends     可选    继承         namespace    ...

  9. Android新建项目 默认布局改为 LinearLayout

    目前此方法仅适用于eclipse 需要修改SDK 目录 android-sdk/tools/templates/activities/BlankActivity/root/res/layout 文件: ...

  10. awk 多分隔符

    #!/bin/bash log_path="./log/" dates=`date -d '-1 days' +'%Y%m%d'` cd $log_path; for i in ` ...