HDU2522 A simple problem 【模拟】

A simple problem

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

Total Submission(s): 3133    Accepted Submission(s): 1144

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

HDU 2008-10 Programming Contest

#include <stdio.h>
#include <string.h>
#define maxn 100002

bool vis[maxn];

int main()
{
    int n, i, t, m;
    scanf("%d", &t);
    while(t--){
        scanf("%d", &n);
        if(n < 0){
            printf("-"); n = -n;
        }
        if(n == 1){
            printf("1\n"); continue;
        }
        memset(vis, 0, sizeof(bool) * n);
        printf("0."); m = 1; vis[0] = 1;
        while(!vis[m]){
            vis[m] = 1; m *= 10;
            printf("%d", m / n);
            m %= n;
        }
        printf("\n");
    }
    return 0;
}
时间: 2024-08-24 12:32:57

HDU2522 A simple problem 【模拟】的相关文章

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; } }

HDU 4974 A simple water problem 模拟(水

水题. #include <cstdio> #include <iostream> #include <queue> #include <algorithm> using namespace std; typedef long long ll; priority_queue<int> q; int main() { int T, cas = 0; scanf("%d", &T); while(T-- > 0) {

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

NYOJ 707 A Simple Problem(结构体排序) 睡前一水~~

链接:click here 题意: A Simple Problem 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 You know, just as the title imply, this is a simple problem. In a contest, given the team-id, solved, penalty of all the teams, tell me the champion.If the numbers of solved pr

E - A Simple Problem with Integers

#include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> using namespace std; #define N 100002 struct node { int l,r; long long lz,w; }q[4*N]; void pushup(int rt) { q[rt].w=q[rt*2].w+q[rt*2+1].w; } void pushdo

POJ 3468 A Simple Problem with Integers

链接:http://poj.org/problem?id=3468 A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 77302 Accepted: 23788 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two ki

poj 3468 A Simple Problem with Integers(线段树+区间更新+区间求和)

题目链接:id=3468http://">http://poj.org/problem? id=3468 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 83959   Accepted: 25989 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. Yo

poj3468 A Simple Problem with Integers 线段树区间更新

A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 97722   Accepted: 30543 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of

POJ 3468 A Simple Problem with Integers(树状数组区间更新)

A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 97217   Accepted: 30358 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of