UVa 654 - Ratio (枚举)
来源:互联网 发布:佳美迅授课软件 编辑:程序博客网 时间:2024/04/27 21:22
题意
这题目读得我蛋疼。
简单地说,就是先给一组数据,让我们从分母为1开始,逐步增加精度,如果发现某个数精度大于上一个精度,就输出。
思路
枚举分母暴力!
用round得出分子,然后把结果和上一次的比较。
因为可能出现可以约分的分数,我就用了gcd。。
代码
#include <cstdio>
#include <stack>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <cmath>
#define LL long long
#define SZ(x) (int)x.size()
#define Lowbit(x) ((x) & (-x))
#define MP(a, b) make_pair(a, b)
#define MS(arr, num) memset(arr, num, sizeof(arr))
#define PB push_back
#define F first
#define S second
#define ROP freopen("input.txt", "r", stdin);
#define MID(a, b) (a + ((b - a) >> 1))
#define LC rt << 1, l, mid
#define RC rt << 1|1, mid + 1, r
#define LRT rt << 1
#define RRT rt << 1|1
#define BitCount(x) __builtin_popcount(x)
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
using namespace std;
const int MAXN = 150 + 10;
const int MOD = 1e9 + 7;
//const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
typedef pair<int, int> pii;
typedef vector<int>::iterator viti;
typedef vector<pii>::iterator vitii;
int main()
{
// ROP;
double win, lose;
int i, j;
bool first = true;
while (~scanf("%lf%lf", &win, &lose))
{
if (!first) puts("");
first = false;
double cri = win / lose, last = INF;
for (i = 1; i <= lose; i++)
{
double k = round(win * i / lose);
if (__gcd((int)k, i) != 1) continue;
if (fabs(cri - k / i) < last)
{
printf("%d/%d\n", (int)k, i);
last = fabs(cri - k / i);
}
}
}
return 0;
}
0 0
- UVa 654 - Ratio (枚举)
- UVA 654 - Ratio(枚举)
- uva 654 - Ratio(暴力)
- UVA - 654 Ratio
- UVA - 654 Ratio
- UVA 654 Ratio(水题)
- UVA654- Ratio(暴力枚举)
- ratio
- ratio
- hdu 2489 Minimal Ratio Tree(枚举+最小生成树)
- hdu 2489 Minimal Ratio Tree(dfs枚举 + 最小生成树)~~~
- hdu - 2489 - Minimal Ratio Tree(枚举 + MST)
- POJ 3925 Minimal Ratio Tree(枚举+最小生成树)
- HDU 2489 Minimal Ratio Tree(枚举组合+最小生成树)
- dfs枚举 + 最小生成树 hdoj2489 Minimal Ratio Tree
- hdu 2489 Minimal Ratio Tree 最小生成树+枚举
- uva 10167 枚举
- UVA 585 - Triangles(枚举)
- POJ2631——Roads in the North
- 面向对象
- 扫描二维码自动识别手机APP下载地址
- hdu 1284
- hdu 5044 Tree(树链剖分)
- UVa 654 - Ratio (枚举)
- smack连接ejabberd笔记二
- 《信息检索》第9讲:文件管理新境界 及 大学两种生活态度
- oracle TNS:协议适配器错误
- leetcode记录-Two Sum
- Codeforces Round #273 (Div. 2) --C Table Decorations
- 【读书心得】 高质量C++/C编程指南-林锐
- zoj 3820(2014牡丹江现场赛B题)
- STM32的IO口的8种配置