• ural 1104. Don’t Ask Woman about Her Age暴力


    1104. Don’t Ask Woman about Her Age

    Time limit: 1.0 second
    Memory limit: 64 MB
     
    Mrs Little likes digits most of all. Every year she tries to make the best number of the year. She tries to become more and more intelligent and every year studies a new digit. And the number she makes is written in numeric system which base equals to her age. To make her life more beautiful she writes only numbers that are divisible by her age minus one. Mrs Little wants to hold her age in secret.
    You are given a number consisting of digits 0, …, 9 and Latin letters A, …, Z, where A equals 10, B equals 11 etc. Your task is to find the minimal number k satisfying the following condition: the given number, written in k-based system is divisible by k−1.

    Input

    Input consists of one string containing no more than 106 digits or uppercase Latin letters.

    Output

    Output the only number k, or "No solution." if for all 2 ≤ k ≤ 36 condition written above can't be satisfied. By the way, you should write your answer in decimal system.

    Sample

    inputoutput
    A1A
    
    22
    

    Problem Author: Igor Goldberg
    Problem Source: Tetrahedron Team Contest May 2001

    思路:从小到大暴力,注意年龄 >= 2

    #include <iostream>
    #include <sstream>
    #include <fstream>
    #include <string>
    #include <vector>
    #include <deque>
    #include <queue>
    #include <stack>
    #include <set>
    #include <map>
    #include <algorithm>
    #include <functional>
    #include <utility>
    #include <bitset>
    #include <cmath>
    #include <cstdlib>
    #include <ctime>
    #include <cstdio>
    #include <string>
    using namespace std;
    int N, T;
    int main() {
        //freopen("in.txt", "r", stdin);
        string s;
        cin >> s;
        int cnt = 2;
        for(int i = 0; i < s.size(); i++){
            if(s[i] >= 'A' && s[i] <= 'Z' && s[i] - 'A' + 10 >= cnt){
                cnt = s[i] - 'A' + 11;
            }else if(s[i] >= '0' && s[i] <= '9'&& s[i] - '0' >= cnt){
                cnt = s[i] - '0' + 1;
            }
        }
        long long int sum = 0, now;
        for(int k = cnt; k <= 36; k++){
                if(s[s.size()-1] >= 'A' && s[s.size()-1] <= 'Z') sum = s[s.size()-1] - 'A' + 10;
                else sum = s[s.size()-1] - '0';
                sum %= (k-1);
            for(int i = s.size()-2; i >= 0; i--){
                 if(s[i] >= 'A' && s[i] <= 'Z') now = s[i] - 'A' + 10;
                else now = s[i] - '0';
                sum += now*k;
                sum %= (k-1);
            }
            if(sum == 0) {
                printf("%d
    ", k);
                exit(0);
            }
        }
        printf("No solution.
    ");
        return 0;
    }
  • 相关阅读:
    【译】SQL Server误区30日谈Day3即时文件初始化特性可以在SQL Server中开启和关闭
    有关TSQL的10个好习惯
    【译】SQL Server误区30日谈Day6有关NULL位图的三个误区
    一次由重复索引导致的问题
    【译】SQL Server误区30日谈Day2DBCC CHECKDB会导致阻塞
    【译】SQL Server误区30日谈Day1正在运行的事务在服务器故障转移后继续执行
    CodeFileBaseClass 属性
    Mako 模板系统文档翻译(2) 语法
    终于搞定了 django 的 ajax 方式上传图片
    ASP.NET Ajax 调试技巧:用 FireBug 调试 UpdatePanel 不更新问题
  • 原文地址:https://www.cnblogs.com/cshg/p/5892370.html
Copyright © 2020-2023  润新知