zoukankan      html  css  js  c++  java
  • NEU 1681: The Singles

    题目描述

    The Signals’ Day has passed for a few days. Numerous sales promotion campaigns on the shopping sites make us forget that 11.11 is the Signals’ Day. So we should do something to enhance the concept of Singles’ Day.

    Let’s give a number a, you should find the minimum number n only consist of digit 1(ie. 111,11111…) which can be divided by a. If the number exist, you should output "Singles' Day is on n.", otherwise you should output "There is no Singles' Day!".

    输入

    Several test cases.

    For each test case:

    Input is a integer a(1<=a<=1000000),as described above.

    输出

    For each test case:

    Output "Singles' Day is on n." or  "There is no Singles' Day!" in one line.

    样例输入

    1
    2
    3

    样例输出

    Singles' Day is on 1.
    There is no Singles' Day!
    Singles' Day is on 111.

    题目的意思就是 找到 一个只由1组成的数x 使得 x%a==0
    一开始是这么 做得枚举 x 然后判断是否能被a整除。结果 wa了。
    得用高精度做。从左边模拟每一位1除以a 具体看代码
    /* ***********************************************
    Author        :guanjun
    Created Time  :2016/3/5 11:58:53
    File Name     :neu1681.cpp
    ************************************************ */
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <stdio.h>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    #include <list>
    #include <deque>
    #include <stack>
    #define ull unsigned long long
    #define ll long long
    #define mod 90001
    #define INF 0x3f3f3f3f
    #define maxn 1001000
    #define cle(a) memset(a,0,sizeof(a))
    const ull inf = 1LL << 60;
    const double eps=1e-5;
    using namespace std;
    priority_queue<int,vector<int>,greater<int> >pq;
    struct Node{
        int x,y;
    };
    struct cmp{
        bool operator()(Node a,Node b){
            if(a.x==b.x) return a.y> b.y;
            return a.x>b.x;
        }
    };
     
    bool cmp(int a,int b){
        return a>b;
    }
    int mp[maxn];
    int main()
    {
        #ifndef ONLINE_JUDGE
        //freopen("in.txt","r",stdin);
        #endif
        //freopen("out.txt","w",stdout);
        ll a;
        while(cin>>a){
            cle(mp);
            int num=0;
            int n=1;
            while(1){
                num++;
                n=n%a;
                if(n==0){
                    printf("Singles' Day is on ");
                    for(int i=1;i<=num;i++){
                        printf("1");
                    }
                    printf(".
    ");
                    break;
                }
                if(mp[n]){
                    puts("There is no Singles' Day!");break;
                }
                else mp[n]=1;
                n=n*10+1;
            }
        }
        return 0;
    }
     
  • 相关阅读:
    Linux下MySQL主从同步配置
    Tortoisegit图文使用教程
    C语言I博客作业06
    第十周助教总结
    C语言I博客作业04
    C语言I博客作业02
    第十一周助教总结
    第十二周助教总结
    第九周助教总结
    C语言I博客作业02
  • 原文地址:https://www.cnblogs.com/pk28/p/5305411.html
Copyright © 2011-2022 走看看