UVa 10093 - An Easy Problem!

题目:给你一个62进制的数字R,找到最小的N使得R整除N-1。

分析:数论。从小到大枚举N即可,最小值为出现的字符中最大的值+1,最大值为62。

说明:注意数据可能很长,计算时保留余数即可。

#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>

char list[63] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
int  maps[128];

int  deal(char* buf)
{
	int min = 2;
	for (int i = 0 ; buf[i] ; ++ i)
		if (min <= maps[buf[i]])
			min = maps[buf[i]]+1;
	for (int i = min ; i < 63 ; ++ i) {
		int r = 0;
		for (int j = 0 ; buf[j] ; ++ j)
			r = (r*i+maps[buf[j]])%(i-1);
		if (r == 0) return i;
	}
	return -1;
}

int main()
{
	for (int i = 0 ; list[i] ; ++ i)
		maps[list[i]] = i;
	char buf[10000];
	while (~scanf("%s",buf)) {
		int v = deal(buf);
		if (v != -1) printf("%d\n",v);
		else printf("such number is impossible!\n");
	}
    return 0;
}
时间: 2024-10-10 20:39:59

UVa 10093 - An Easy Problem!的相关文章

UVa 10633 - Rare Easy Problem

题目:给定一个数N,去掉末尾的数变成M,现在已知N-M,确定N. 分析:数论,简单题. 设N = 10*a + b { 其中0 ≤ b ≤ 9 },则M = a: N - M = N - a = 9*a + b,枚举所有的b计算出满足条件的N即可. 说明:目标500题(⊙_⊙). #include <iostream> #include <cstdlib> #include <cmath> using namespace std; int main() { long l

(DS 《算法入门经典》)UVA 11991 Easy Problem from Rujia Liu?(求第k个v出现的索引)

题目大意: 求第k个v出现的索引 解题思路: 如果能构造出一个数据结构,使得data[v][k]就是第k个v出现的索引值即可求解.data[v]表示数v出现的索引数组, data[v][k]表示第k个v出现的索引. Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, regional contests like Xi'an 200

[UVA] 11991 - Easy Problem from Rujia Liu? [STL应用]

11991 - Easy Problem from Rujia Liu? Time limit: 1.000 seconds Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, regional contests like Xi'an 2006, Beijing 2007 and Wuhan 2009, or UVa OJ con

uva Easy Problem from Rujia Liu?

Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, regional contests like Xi'an 2006, Beijing 2007 and Wuhan 2009, or UVa OJ contests like Rujia Liu's Presents 1 and 2), he occasionally sets

uva 11991 Easy Problem from Rujia Liu? Data Structure

// uva 11991 Easy Problem from Rujia Liu? // 给一个包含n个数的数组,需要回答若干个询问,每次询问两个整数 // k和v,输出从左到右第k个v的下标 // // 本题因为n比较大,所以直接开二维数组是不现实的 // 如果直接用vector的话,也是会有大量的浪费 // 所以可以先离散化一下,找到一共有多少个不同的数 // 再用vector动态数组就可以搞定了 // // 看着书上的map写的挺精彩的,我就习用了下来 // // 非常精彩,继续练吧...

uva 11991 - Easy Problem from Rujia Liu?(STL)

题目链接:uva 11991 - Easy Problem from Rujia Liu? 题目大意:给出一个包含n个整数的数组,你需要回答若干询问,每次询问两个整数k和v,输出从左到右第k个v的下标 解题思路:用map映射一个vector,对应即为map<int>即为一个可变长的数组,读取数组的时候将对应值放入即可. #include <cstdio> #include <cstring> #include <map> #include <vecto

11991 - Easy Problem from Rujia Liu?(的基础数据结构)

UVA 11991 - Easy Problem from Rujia Liu? 题目链接 题意:给一个长度n的序列,有m询问,每一个询问会问第k个出现的数字的下标是多少 思路:用map和vector搞,map[i][j]直接保存的就是数字i第j个出现,每次直接输出就可以 代码: #include <cstdio> #include <cstring> #include <vector> #include <map> using namespace std;

UVA11991 Easy Problem from Rujia Liu?(第K个V的位置)

Easy Problem from Rujia Liu? Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, regional contests like Xi'an 2006, Bei

11991 - Easy Problem from Rujia Liu?(基础数据结构)

UVA 11991 - Easy Problem from Rujia Liu? 题目链接 题意:给一个长度n的序列,有m询问,每个询问会问第k个出现的数字的下标是多少 思路:用map和vector搞,map[i][j]直接保存的就是数字i第j个出现,每次直接输出即可 代码: #include <cstdio> #include <cstring> #include <vector> #include <map> using namespace std; i