A simple problem(hdu2522)
A simple problemTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2709 Accepted Submission(s): 946 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
|
关键处理循环小数。。。。。
/* 原理是:eg:1/4....商0,余1;
1*10/4....商2,余2;
2*10/4.....商5余0;
1/3....
1/3....商0,余1;
1*10/3....商3,余1;
余数相同,退出..... */
详见代码,,,,,,
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
//出现余数为零,或者余数出现过,即为循环节终止。
int a[];
int hash[];
int main()
{
int T;
cin>>T;
while(T--)
{
int n,cn=,mod=;
int sig=; //符号
cin>>n;
if(n== || n==- )
{
cout<<n<<endl;
continue;
}
n<?(n=-n,sig=):;
memset(hash,,sizeof(hash));//手误hash
memset(a,,sizeof(a));
hash[mod]=; //首先就是 1/n....商0,余1;
while()
{
mod*=;
a[cn++]=mod/n;
mod%=n;
if(hash[mod]||!mod)
break;
hash[mod]=; } printf(!sig?"-0.":"0.");
for(int i=;i<cn;i++)
{
cout<<a[i];
}
cout<<endl;
}
return ;
}
A simple problem(hdu2522)的更多相关文章
- HDU 2522 A simple problem (模拟)
题目链接 Problem Description Zty很痴迷数学问题..一天,yifenfei出了个数学题想难倒他,让他回答1 / n.但Zty却回答不了^_^. 请大家编程帮助他. Input 第 ...
- 【BZOJ3489】A simple rmq problem(KD-Tree)
[BZOJ3489]A simple rmq problem(KD-Tree) 题面 BZOJ 题解 直接做肯定不好做,首先我们知道我们是一个二维平面数点,但是限制区间只能出现一次很不好办,那么我们给 ...
- 【CF954I】Yet Another String Matching Problem(FFT)
[CF954I]Yet Another String Matching Problem(FFT) 题面 给定两个字符串\(S,T\) 求\(S\)所有长度为\(|T|\)的子串与\(T\)的距离 两个 ...
- 洛谷 P1581 A+B Problem(升级版)
P1581 A+B Problem(升级版) 题目背景 小明这在写作业,其中有一道A+B Problem ,他想啊想啊想,就是想不出来,于是就找到了会编程的你...... 题目描述 这里的A+B是很奇 ...
- nyoj 844-A+B Problem(V) (string[::-1] 字符串反转)
844-A+B Problem(V) 内存限制:64MB 时间限制:1000ms 特判: No 通过数:14 提交数:17 难度:1 题目描述: 做了A+B Problem之后,Yougth感觉太简单 ...
- MNIST手写数字分类simple版(03-2)
simple版本nn模型 训练手写数字处理 MNIST_data数据 百度网盘链接:https://pan.baidu.com/s/19lhmrts-vz0-w5wv2A97gg 提取码:cgnx ...
- A simple problem(湘大邀请赛)
A simple problem Accepted : 61 Submit : 418 Time Limit : 15000 MS Memory Limit : 655360 KB Probl ...
- hdu 1016 Prime Ring Problem(DFS)
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- A/B Problem(大数)
描述 做了A+B Problem,A/B Problem不是什么问题了吧! 输入 每组测试样例一行,首先一个号码A,中间一个或多个空格,然后一个符号( / 或者 % ),然后又是空格,后面又是一个号码 ...
随机推荐
- Android TV 开发(5)
本文来自网易云社区 作者:孙有军 问题3:TV launcher中没有入口图标 如果需要出现入口图标,你必须要在AndroidManifest中配置action为android.intent.acti ...
- ArrayBlockingQueue源码解析(1)
此文已由作者赵计刚授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 注意:在阅读本文之前或在阅读的过程中,需要用到ReentrantLock,内容见<第五章 Reentr ...
- 关于IE9 table显示错位的问题
首先,win10无法安装IE9,所以需要用IE11模拟IE9,这样:http://www.w10zj.com/Win10xy/Win10yh_638.html: 其次,table显示错位的可能原因:h ...
- BZOJ 3940--[Usaco2015 Feb]Censoring(AC自动机)
3940: [Usaco2015 Feb]Censoring Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 723 Solved: 360[Subm ...
- Django自带的后台管理样式找不到的问题。
今天发现自己用uwsgi,nginx部署完服务器后,又想用自带的Django服务器进行后台管理调试,发现Django后代管理页面样式找不到.又查看了路径发现是正确的.网上看了很多方法.最后才发现自己把 ...
- 性能优化中CPU、内存、磁盘IO、网络性能的依赖(转)
关于系统性能优化,推荐一篇不错的博客! 系统优化是一项复杂.繁琐.长期的工作,优化前需要监测.采集.测试.评估,优化后也需要测试.采集.评估.监测,而且是一个长期和持续的过程,不 是说现在优化了,测试 ...
- Math.log()对数的妙用
###对数log 的妙用... formatBytes(bytes) { if (bytes === '0' || isNaN(bytes)) return ''; var s = ['Bytes', ...
- (转) JVM Crash with SIGSEGV - problematic frame - libzip.so
原文:https://stackoverflow.com/questions/38057362/jvm-crash-with-sigsegv-problematic-frame-libzip-so h ...
- Shell 流程控制 if while for
if else if if 语句语法格式: if condition then command1 command2 ... commandN fi 写成一行(适用于终端命令提示符): if [ $(p ...
- vscode中PyLint报错Unable to import解决方案
在导入其它文件夹中py文件的时候,即使在代码中添加了指定路径,由于Pylint 无法检测到该文件,会给出Unable to import 'xxx'的错误提示 需要在项目目录下添加.pylintrc文 ...