HDU ACM 2522 A simple problem 模拟除法

分析:在除的过程中,当出现相同余数时即出现循环节。

#include<iostream>
using namespace std;

bool h[100002];

void div(int x)
{
	int t;

	memset(h,false,x*sizeof(h[0])+1);
	h[1]=true;
	t=1;
	while(t)
	{
		t=t*10;
		cout<<t/x;
		t=t%x;
		if(h[t])  //再次出现相同余数,表示出现循环节
			break;
		h[t]=true;
	}
}

int main()
{
	int T,n;

	cin>>T;
	while(T--)
	{
		cin>>n;
		if(n<0)
		{
			cout<<"-";
			n=-n;
		}
		if(n==1)
		{
			cout<<1<<endl;
			continue;
		}
		cout<<"0.";
		div(n);
		cout<<endl;
	}
    return 0;
}
时间: 2024-08-27 18:47:13

HDU ACM 2522 A simple problem 模拟除法的相关文章

HDU ACM 4143 A Simple Problem

分析:y^2=n+x^2=>y^2-x^2=n. (y-x)(y+x)=n. 令k1=y-x:k2=y+x. 则有:y=(k1+k2)/2,x=y-k1. 枚举n的所有因数k1,k2使得y为整数.则最小的x即为所求. 注意:x不能为0. #include<iostream> #include<cmath> using namespace std; void Solve(int n) { int i,x,y,minx; minx=0x7fffffff; for(i=1;i<

hdu 5349 MZL&#39;s simple problem

Problem Description A simple problem Problem Description You have a multiple set,and now there are three kinds of operations: 1 x : add number x to set 2 : delete the minimum number (if the set is empty now,then ignore it) 3 : query the maximum numbe

【multiset】hdu 5349 MZL&#39;s simple problem

[multiset]hdu 5349 MZL's simple problem 题目链接:hdu 5349 MZL's simple problem 题目大意 n次操作,插入元素.删除最小元素.查询最大元素并输出. C++STL的multiset的使用 set--多元集合(元素不可重复),multiset--可重复元素的多元集合 多元集合(MultiSets)和集合(Sets)相像,只不过支持重复对象.(具体用法请参照set容器) set和multiset内部是以平衡二叉树实现的: 从内部数据结

hdu 5349 MZL&#39;s simple problem(multiset)

代码: #include<set> #include<cstdio> using namespace std; multiset<int> st; int main() { int n; multiset<int>::iterator it; while(scanf("%d",&n)==1) { st.clear(); int k,num; for(int i=0; i<n; i++) { scanf("%d&qu

hdu - 5349 MZL&#39;s simple problem(解题报告)

A - MZL's simple problem Time Limit:1500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description A simple problem Problem Description You have a multiple set,and now there are three kinds of operations: 1 x : add number

HDU 5349 MZL&#39;s simple problem(优先队列)

MZL's simple problem Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 776    Accepted Submission(s): 375 Problem Description A simple problem Problem Description You have a multiple set,and now

HDU 2522 A simple problem

A simple problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3368    Accepted Submission(s): 1249 Problem Description Zty很痴迷数学问题..一天,yifenfei出了个数学题想难倒他,让他回答1 / n.但Zty却回答不了^_^.  请大家编程帮助他. In

HDU 4267 A Simple Problem with Integers 多个树状数组

A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4000    Accepted Submission(s): 1243 Problem Description Let A1, A2, ... , AN be N elements. You need to deal with

hdoj 2522 A simple problem 【模拟】

题意:算出1/n的结果,循环小数只输出第一个循环节 策略:模拟1除去n即可. 判断是否是循环节只需要找到%n之后的模是否出现就好了. 代码: #include <stdio.h> #include <string.h> #define M 100005 bool vis[M]; int main(){ int t, n; scanf("%d", &t); while(t --){ scanf("%d", &n); if(n =