POJ 3039 搜索??? (逼近)
思路:
抄的题解
这叫搜索?
难以理解
我觉得就是枚举+逼近
//By SiriusRen
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,recx,recy,x,y;
int gcd(int a,int b){
return b?gcd(b,a%b):a;
}
int main(){
while(~scanf("%d%d",&x,&y)){
double temp,a,minn=66666.666;
a=(double)x/y;
int n=x,m=y;
x=y=1;
while(x<=32767&&y<=32767){
temp=(double)x/y;
int p=gcd(x,y),dx=x/p,dy=y/p;
if(abs(temp-a)<abs(minn-a)&&(!(dx==n&&dy==m)))
minn=temp,recx=dx,recy=dy;
if(temp<a)x++;
else y++;
}
printf("%d %d\n",recx,recy);
}
}
POJ 3039 搜索??? (逼近)的更多相关文章
- catch that cow POJ 3278 搜索
catch that cow POJ 3278 搜索 题意 原题链接 john想要抓到那只牛,John和牛的位置在数轴上表示为n和k,john有三种移动方式:1. 向前移动一个单位,2. 向后移动一个 ...
- [Vjudge][POJ][Tony100K]搜索基础练习 - 全题解
目录 POJ 1426 POJ 1321 POJ 2718 POJ 3414 POJ 1416 POJ 2362 POJ 3126 POJ 3009 个人整了一些搜索的简单题目,大家可以clone来练 ...
- poj 2251 搜索
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13923 Accepted: 5424 D ...
- poj 1011 搜索减枝
题目链接:http://poj.org/problem?id=1011 #include<cstdio> #include<cstring> #include<algor ...
- 生日蛋糕 POJ - 1190 搜索 数学
http://poj.org/problem?id=1190 题解:四个剪枝. #define _CRT_SECURE_NO_WARNINGS #include<cstring> #inc ...
- poj 2531 搜索剪枝
Network Saboteur Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u ...
- poj 折半搜索
poj2549 Sumsets 题目链接: http://poj.org/problem?id=2549 题意:给你一个含有n(n<=1000)个数的数列,问这个数列中是否存在四个不同的数a,b ...
- poj 3278 搜索
描述: Farmer John has been informed of the location of a fugitive cow and wants to catch her immediate ...
- poj 1129 搜索
Channel Allocation Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64 ...
随机推荐
- 【转载】eclipse中批量修改Java类文件中引入的package包路径
原博客地址:http://my.oschina.net/leeoo/blog/37852 当复制其他工程中的包到新工程的目录中时,由于包路径不同,出现红叉,下面的类要一个一个修改包路径,类文件太多的话 ...
- 《剑指offer》合并两个排序的链表
一.题目描述 输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则. 二.输入描述 两个递增排序的链表 三.输出描述 合并成一个递增排序的链表 四.牛客网提供的框 ...
- 认识javascript的引擎之--1
前言: 一:每一款浏览器里面都能执行js脚本,那是因为制造商在浏览器里面加入了js引擎.也就是说js引擎在浏览器里面占有一席之地. 1.开始的时候js处于沉睡状态,直到运行页面遇到 <scrip ...
- 关于table布局
html-table 宝贝 状态 单价 数量 商品总价 运费 1sdsdf 2 3fffff 4sdfsfsffsdfs 5dsfs 6
- Hello World基于.net framework中CLR的执行
static void Main(string[] args) { Console.WriteLine("Hello,World!"); Console.WriteLine(&qu ...
- js中数组增删查改unshift、push、pop、shift、slice、indexOf、concat、join
js中数组增删查改unshift.push.pop.shift.slice.indexOf.concat.join
- 题解 P3374 【【模板】树状数组 1】
恩,这是AC的第一道树状数组呢. 本蒟蒻以前遇到RMQ问题一般都用线段树或ST表,可惜ST表不支持在线修改,而线段树代码量又太大. 如今终于找到了折中方案:树状数组!!!!代码量小,还支持修改! 树状 ...
- 洛谷—— P2934 [USACO09JAN]安全出行Safe Travel || COGS ——279|| BZOJ——1576
https://www.luogu.org/problem/show?pid=2934 题目描述 Gremlins have infested the farm. These nasty, ugly ...
- Maven的SSH搭建以及部署
本人有点傻,研究Maven研究了有一段时间,刚刚有些入门,记录下来方便以后使用 工作环境:jdk7 myeclipse10 maven3.1.1 1 下载maven3.1.1 http://maven ...
- BestCoder Round #11 (Div. 2)
太菜,仅仅能去Div2.(都做不完 ORZ... 各自是 HDU: 5054pid=5054"> Alice and Bob 5055Bob and math problem 5056 ...