乍看题目感觉有难度,实际分析后其实是道简单题

 /*
 ID: yingzho1
 LANG: C++
 TASK: fracdec
 */
 #include <iostream>
 #include <fstream>
 #include <string>
 #include <map>
 #include <vector>
 #include <set>
 #include <algorithm>
 #include <stdio.h>
 #include <queue>
 #include <cstring>
 #include <cmath>
 #include <list>

 using namespace std;
 #define inf 10000000

 ifstream fin("fracdec.in");
 ofstream fout("fracdec.out");

 int N, D;
 vector<int> rec;
 set<int> recset;

 int GCD(int a, int b)
 {
    ) return a;
    return GCD(b,a%b);
 }

 string intToString(int n) {
     string ret;
     ) ";
     while (n) {
         );
         ret += tmp;
         n /= ;
     }
     reverse(ret.begin(), ret.end());
     return ret;
 }

 int main()
 {
     fin >> N >> D;
     int gcd = GCD(N, D);
     N /= gcd, D/= gcd;
     ) {
         fout << N << ".0" << endl;
         ;
     }
     int first = N / D;
     int second = N % D;
     string res;
     ;
     ) {
         )) {
             for (; againindex < rec.size(); againindex++) {
         //        cout << rec[againindex] << endl;
                 ) {
                     againindex++;
                     break;
                 }
             }
             break;
         }
         res = res + /D);
         rec.push_back(second*);
         recset.insert(second*);
       //  cout << "second: " << second << endl;
         second = second *  % D;
     }
     //cout << res << endl;
     //cout << againindex << endl;
     if (againindex) {
         res.insert(againindex-, "(");
         //cout << res << endl;
         res += ")";
     }
     string ret = intToString(first) + "." + res;
     //cout << ret;
     ; i < ret.size(); i++) {
         fout << ret[i];
          ==  && i > ) fout << endl;
     }
      != ) fout << endl;
     //if (first > 0) fout << first << "." << res << endl;
     //else fout << "0." << res << endl;

     ;
 }

USACO Section 2.4: Fractions to Decimals的更多相关文章

  1. 【USACO 2.4】Fractions to Decimals(分数转小数)

    题意:给你N/D的分数,让你输出等价的小数,如果是循环小数,用括号把循环节包起来.如果是整数,后面保留一位小数.每行最多输出76个字符. 题解:模拟除法,如果余数是第二次出现,则代表第一次出现的位置到 ...

  2. 洛谷P1530 分数化小数 Fractions to Decimals

    P1530 分数化小数 Fractions to Decimals 103通过 348提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交  讨论  题解 最新讨论 暂时没有讨论 题目 ...

  3. Luogu P1530 分数化小数 Fractions to Decimals(模拟)

    P1530 分数化小数 Fractions to Decimals 题意 题目描述 写一个程序,输入一个形如\(N/D\)的分数(\(N\)是分子,\(D\)是分母),输出它的小数形式.如果小数有循环 ...

  4. YTU 1439: 2.4.5 Fractions to Decimals 分数化小数

    1439: 2.4.5 Fractions to Decimals 分数化小数 时间限制: 1 Sec  内存限制: 64 MB 提交: 194  解决: 13 题目描述 写一个程序,输入一个形如N/ ...

  5. USACO Section 2.1 Ordered Fractions

    /* ID: lucien23 PROG: frac1 LANG: C++ */ #include <iostream> #include <fstream> #include ...

  6. USACO Section 2.1 Ordered Fractions 解题报告

    题目 题目描述 给定一个数N(1<=N<=160),需要产生所有的分数,这些分数的值必须要在0~1之间.而且每个分数的分母不能超过N.如下例所示: N = 5 产生所有的分数:0/1 1/ ...

  7. USACO Section 1.3 题解 (洛谷OJ P1209 P1444 P3650 P2693)

    usaco ch1.4 sort(d , d + c, [](int a, int b) -> bool { return a > b; }); 生成与过滤 generator&& ...

  8. USACO Section 3.3: Riding the Fences

    典型的找欧拉路径的题.先贴下USACO上找欧拉路径的法子: Pick a starting node and recurse on that node. At each step: If the no ...

  9. USACO Section 3.3 Camlot(BFS)

    BFS.先算出棋盘上每个点到各个点knight需要的步数:然后枚举所有点,其中再枚举king是自己到的还是knight带它去的(假如是knight带它的,枚举king周围的2格(网上都这么说,似乎是个 ...

随机推荐

  1. windows 2008 下C#调用office组件访问拒绝的解决方法(failed due to the following error: 80070005 拒绝访问)

    "组件服务"- >"计算机"- >"我的电脑"- >"DCOM配置"->找到word->属 ...

  2. Node.js 学习(四)Node.js 回调函数

    Node.js 异步编程的直接体现就是回调. 异步编程依托于回调来实现,但不能说使用了回调后程序就异步化了. 回调函数在完成任务后就会被调用,Node 使用了大量的回调函数,Node 所有 API 都 ...

  3. js判断浏览器滚动条是否拉到底

    $(window).scroll(function(){ // 当滚动到最底部以上n像素时, 加载新内容 if ($(document).height() - $(this).scrollTop() ...

  4. websphere OSGi应用环境下服务调用saaj包加载问题分析报告

    websphere OSGi应用环境下服务调用saaj包加载问题分析报告 作者:bingjava 版权声明:本文为博主原创文章,转载请说明出处:http://www.cnblogs.com/bingj ...

  5. JS--事件对象中部份浏览器不兼容方法

    测试时主要用的浏览器是Firefox 28.0.IE11.IE8.Chrome 34.0  一.什么是事件对象:当触发某个事件的时候,会产生一个事件对象,这个对象包含着所有的与事件有关的信息,包括导致 ...

  6. bnuoj 34985 Elegant String DP+矩阵快速幂

    题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=34985 We define a kind of strings as elegant s ...

  7. [百度空间] [note] pointer to member is a POD type

    C++03 3.9-10: 1 Arithmetic types (3.9.1), enumeration types, pointer types, and pointer to member ty ...

  8. 【转】Sublime text 3 中文文件名显示方框怎么解决

    引用自:http://www.zhihu.com/question/24029280 如图,中文文件名打开全是乱码,内容倒是装了converttoutf8没什么太大的问题. 这个是sublime te ...

  9. Altium Designer Summer 09创建半圆焊盘方法

    关于异形焊盘的创建,可参看下面的半圆PAD的制作:1.新建一个PCB文件,然后在里面画一个半圆的Arc,即Place放置(P)>Arc,并且要将其开口处 封闭,即可用Place   放置(P)& ...

  10. 使用tomcat7创建异步servlet

    该篇文章翻译自:http://developerlife.com/tutorials/?p=1437 一.简介 Servlet API 3.0 之前,需要使用类似Comet的方式来实现创建异步的Ser ...