Description

Zty很痴迷数学问题.。一天,yifenfei出了个数学题想难倒他,让他回答1 / n。但Zty却回答不了^_^. 请大家编程帮助他.
 

Input

第一行整数T,表示测试组数。后面T行,每行一个整数 n (1<=|n|<=10^5).
 

Output

输出1/n. (是循环小数的,只输出第一个循环节).
 

Sample Input

4
2
3
7
168
 

Sample Output

0.5
0.3
0.142857
0.005952380

和我名字那么相近的题目,当然要AC了!

//如果余数出现重复就表示有循环节
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <deque>
#include <string>
#include <string.h>
#include <vector>
#include <stack>
#include <ctype.h>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <time.h>
#include <bitset>
#include <list> using namespace std; int f[100000];
int flag[100000];
int main()
{
int t,m,y,cnt,n,i;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
if(n<0) //如果是负数
{
printf("-");//首先打印负号
n*=-1;//取反后当做正数处理
}
if(n==1)
{
printf("1\n");
continue;
}
y=1;
cnt=0;
memset(flag,0,sizeof(flag));//初始化为0
flag[1]=1;
while(y)
{
y*=10;
f[cnt++]=y/n;
y%=n;
if(flag[y])//如果使用过,说明出现循环数节
break;
flag[y]=1;//记录余数是否使用过
}
printf("0.");
for(i=0; i<cnt; i++)
printf("%d",f[i]);
printf("\n");
}
return 0;
}

ACM题目————A simple problem的更多相关文章

  1. ACM题目————The Blocks Problem

    代码参考:http://www.hankcs.com/program/uva-q101-the-blocks-problem.html Description Background Many area ...

  2. ACM: A Simple Problem with Integers 解题报告-线段树

    A Simple Problem with Integers Time Limit:5000MS Memory Limit:131072KB 64bit IO Format:%lld & %l ...

  3. [ACM] poj 3468 A Simple Problem with Integers(段树,为段更新,懒惰的标志)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 55273   ...

  4. hdu 5349 MZL's simple problem

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5349 MZL's simple problem Description A simple proble ...

  5. hdu_3483A Very Simple Problem(C(m,n)+快速幂矩阵)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3483 A Very Simple Problem Time Limit: 4000/2000 MS ( ...

  6. 2018 ACMICPC上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节) 链接:https://ac.nowcoder.co ...

  7. A - 敌兵布阵 ——B - I Hate It——C - A Simple Problem with Integers(线段树)

    C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况.由于 ...

  8. POJ 3468 A Simple Problem with Integers(线段树 成段增减+区间求和)

    A Simple Problem with Integers [题目链接]A Simple Problem with Integers [题目类型]线段树 成段增减+区间求和 &题解: 线段树 ...

  9. POJ 3468 A Simple Problem with Integers(线段树/区间更新)

    题目链接: 传送门 A Simple Problem with Integers Time Limit: 5000MS     Memory Limit: 131072K Description Yo ...

随机推荐

  1. 查看python的路径

    >>> import sys >>> sys.path

  2. cache与SDRAM

    hugohong hugohong 本版等级:   #2 得分:20回复于: 2009-04-19 21:51:03 牛人说的,拿出来分享一下:cache是高速缓冲, 解决高速cpu和相对低速sdra ...

  3. Make Rules

    target: components ls TAB rule main:main.o mytool1.o mytool2.o gcc -o main main.o mytool1.o mytool2. ...

  4. Lambda表达式实用

    public List<SettlementExportView> querySettlementExport(SettlementDemandQueryReq req) { JdbcQu ...

  5. 给表追加主键-----报错ORA-02437: 无法验证 (DENGCHAO.TEST) - 违反主键

    由于 这次 项目 做了 数据库 迁移(从 mysql 转到oracle  用的是navicat) 的工具  所以导致很多主键都丢失了 导致数据库很多 数据的id重复  导致系统修改一条数据的时候 出现 ...

  6. Java基础之读文件——使用缓冲读取器读取文件(ReaderInputFromFile)

    控制台程序,本例读取Java基础之写文件部分(WriterOutputToFile)写入的Saying.txt. import java.io.*; import java.nio.file.*; i ...

  7. MD5和DES加密方法

        /// <summary>         /// MD5加密         /// </summary>         /// <param name=&q ...

  8. PostgreSQL Replication之第十一章 使用Skytools(3)

    11.3 管理 pgq-queues Skytools 的一个核心组件是pgq.它提供了一个通用排队接口,它可以让您把消息从一个消息提供者传送到一个任意数目的接收者. 现在的问题是:一般来说,一个队列 ...

  9. 树链剖分(单点更新,求区间最值,区间求和Bzoj1036)

    1036: [ZJOI2008]树的统计Count Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 5759  Solved: 2383 [Submi ...

  10. Maven2的配置文件settings.xml(转)

    当Maven运行过程中的各种配置,例如pom.xml,不想绑定到一个固定的project或者要分配给用户时,我们使用settings.xml中的settings元素来确定这些配置.这包含了本地仓库位置 ...