A simple problem

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 3866    Accepted Submission(s): 1444

Problem 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
 
Author
yifenfei
 
Source
 
Recommend
gaojie   |   We have carefully selected several similar problems for you:  1496 1280 1264 2600 2523

/*其实这一道题跟一般的数学除法很像,只是真正的小数除法都是在小数点后边,
但是那样在c语言中是行不通的,所以每一步乘以10来计算,vis标记是否出现过*/
#include<stdio.h>
#include<string.h>
#define 100000+100
int vis[MAX];
int main()
{
int yu,t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
if(n==1)
{
printf("1\n");
continue;
}
if(n<0)
{
printf("-");
n=-n;
}
printf("0.");
memset(vis,0,sizeof(vis));
yu=1,vis[1]=1;
while(yu)
{
yu*=10;
printf("%d",yu/10);
yu%=10;
if(vis[yu])
break;
vis[yu]=1;
}
printf("\n");
}
return 0;
}

hdoj--2522--A simple problem(数学模拟)的更多相关文章

  1. HDOJ 4267 A Simple Problem with Integers (线段树)

    题目: Problem Description Let A1, A2, ... , AN be N elements. You need to deal with two kinds of opera ...

  2. HDU 2522 A simple problem (模拟)

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

  3. HDU 2522 A simple problem( 分数循环节 )

    链接:Here! 思路:模拟除法,当余数再次出现的时候一定是遇到了循环节( 可看下图例子 ),否则的话继续除法的步骤,直到被除数为 0 . 注意:这道题不需要重新申请一个数组来单独存放答案,如果符合要 ...

  4. mutiset HDOJ 5349 MZL's simple problem

    题目传送门 /* 这题可以用stl的mutiset容器方便求解,我对这东西不熟悉,TLE了几次,最后用读入外挂水过. 题解有O(n)的做法,还以为我是侥幸过的,后来才知道iterator it写在循环 ...

  5. HDU-2522 A simple problem

    http://acm.hdu.edu.cn/showproblem.php?pid=2522 学习://除数的运算的应用和算法.除法的本质,如果余数出现重复就表示有循环节 A simple probl ...

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

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

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

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

  8. poj 3468:A Simple Problem with Integers(线段树,区间修改求和)

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

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

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

随机推荐

  1. POJ 1416 DFS

    题目翻译: 公司现在要发明一种新的碎纸机,要求新的碎纸机能够把纸条上的数字切成最接近而不超过target值.比如,target的值是50,而纸条上的数字是12346,应该把数字切成四部分,分别是1.2 ...

  2. 第6章 服务模式 在 .NET 中实现 Service Interface

    上下文 您 的应用程序部署在 Microsoft Windows? 操作系统上.您决定将应用程序的某一块功能作为 ASP.NET Web Service 公开.互操作性是一个关键问题,因此您无法使用仅 ...

  3. HTML实现图片360度循环旋转

    <style> .header{ -webkit-animation:rotateImg 5s linear infinite;<!--修改旋转周期--> border: 1p ...

  4. Array.of()和Array()区别

    Array.of方法用于将一组值,转换为数组. Array.of(3, 11, 8) // [3,11,8] Array.of(3) // [3] Array.of(3).length // 1 这个 ...

  5. wpf ComboBox 获取选中项的文本内容

    一:根据数据源类型获取选中项 类: public class Region { public int REGION_ID { get; set; } public string REGION_CODE ...

  6. 智能家居控制APPUI界面设计

    2017年,随着智能化产业进入新的市场格局,千家品牌实验室也迎来全新的升级,致力为智能产业生态链提供更全更新更深度的行业分析和品牌数据监测服务.本文为大家带来关于中国智能家居行业发展APP设计欣赏. ...

  7. eclipse离线安装pydev

    首先,下载去http://pydev.org/下载Python的Eclipse插件PyDev. 目前的最新版是PyDev 2.7.1.zip,将压缩文件解压出来.得到features和plugins两 ...

  8. ubuntu 搭建简易的https网站

    ubuntu 搭建简易的https网站 环境:ubuntu 12.04.5 openssl (1)创建一个ssl的保存路径 sudo mkdir /opt/nginx/ssl (2)生存密钥sudo ...

  9. Centos7 执行firewall-cmd –permanent –add-service=mysql报错“ModuleNotFoundError: No module named 'gi'”

    因为目前环境Python3.x与Python2.x版本并存,所以导致以上问题. 解决方法: 第一步,vim  /usr/bin/firewall-cmd, 将#!/usr/bin/python -Es ...

  10. NP是什么意思?

    举例叙述(转自百度百科,纯为学习笔记) 编辑 在一个周六的晚上,你参加了一个盛大的晚会.由于感到局促不安,你想知道这一大厅中是否有你已经认识的人.你的主人向你提议说,你一定认识那位正在甜点盘附近角落的 ...