UVa 10338 - Mischievous Children

题目:求一个字符串的字母集合,能组成的不同的字符串的个数。

分析:组合,计数。求出所有字母的全排列,然后除以每个字母的内部重复排列即可。

说明:(⊙_⊙)

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>

using namespace std;

int  times[26];
char str[25];

long long ans;
long long fac(int n)
{
	long long value = 1LL;
	for (int k = 2 ; k <= n ; ++ k)
		value *= k;
	return value;
}

int main()
{
	int n,len;
	while (~scanf("%d",&n))
	for (int t = 1 ; t <= n ; ++ t) {
		scanf("%s",str);
		len = strlen(str);
		for (int j = 0 ; j < 26 ; ++ j)
			times[j] = 0;
		ans = fac(len);
		for (int j = 0 ; j < len; ++ j)
			times[str[j]-'A'] ++;
		for (int j = 0 ; j < 26 ; ++ j)
			if (times[j] > 0)
				ans /= fac(times[j]);

		printf("Data set %d: %lld\n",t,ans);
	}
	return 0;
}
时间: 2024-10-29 08:26:05

UVa 10338 - Mischievous Children的相关文章

uva Children&#39;s Game

非常巧妙的题目,巧用cmp,注意cmp的重载 #include <iostream> #include <algorithm> using namespace std; string a[55]; bool cmp(string a, string b){ return a+b > b+a; } int main(int argc, char const *argv[]) { int n; while(cin >> n && n){ for(int

UVA - 10905 - Children&#39;s Game (简单排序)

UVA - 10905 Children's Game Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description 4thIIUCInter-University Programming Contest, 2005 A Children's Game Input: standard input Output: standard output Problems

uva 10905 Children&#39;s Game(排序或者有点贪心)

今天配置vim没有成功,老是显示什么error,唉,其实之前成功过的,只不过是重装了dev,然后就变了,可能环境 变量的问题,但是我都改了的啊,以后再调吧... 这道题其实不是我想出来的看的题解,又看题解了...好吧,既然看了题解就得好好掌握才是.用到了我刚刚在 c++ primer里面学的string类,挺好用的,以后我准备写程序尽量用c++内容,多练练.. 又加深理解了qsort调用的cmp函数,它的两个参数其实都是要比较的元素的指针,比如这道题中的元素是string类 型,那么他们都是st

uva 10905 Children&#39;s Game

题意:给n个数字,将它们重新排序得到一个最大的数字, 分析:写一个比较函数每次调用,比较a+b>b+a; 1 #include<iostream> 2 #include<cstdio> 3 #include<string> 4 #include<algorithm> 5 using namespace std; 6 7 string s[60]; 8 int n; 9 10 bool cmp(string a,string b) 11 { 12 ret

uva 10905 Children&#39;s Game (用String的话,就是水题)

本以为string会耗时,就用数组,结果老是WA,没了耐心找错误,就换成string,秒过! #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <string> #include <stack> #include <cmath> #include <queue> #include <

贪心:Children&#39;s Game UVA - 10905

贪心策略:就是s1+s2>s2+s1这个贪心策略非常容易发现. #include<iostream> #include<algorithm> #include<string> using namespace std; const int maxn = 55; bool cmp(string s1, string s2){ return s1 + s2 > s2 + s1; } string a[maxn]; int n; int main(){ while

【字符串排序,技巧!】UVa 10905 - Children’s Game

There are lots of number games for children. These games are pretty easy to play but not so easy to make. We will discuss about an interesting game here. Each player will be given N positive integer. (S)He can make a big integer by appending those in

uva live 6170

Esspe-Peasee Esspe-Peasee is an ancient game played by children throughout the land of Acmania. The rules are simple: A player simply quibs the yorba at the kwonk. If the yorba hurms the kwonk the player gets a foom. If the yorba hurfs the kwonk the

UVA 10603 Fill(正确代码虽然很搓,网上许多代码都不能AC)

在做用户查找时 因为要把查找的结果动态加载和显示,所以,那些html元素要由Ajax动态生成.用户打开查找界面时,有系统推荐的用户,而当用户按条件查找后,查找的结果动态加载和显示.所以考虑到用js来搞. 这个for循环就是移除已有的表单.然后根据Ajax请求过来的数据,动态生成新的表单对象.一定要注意j变量从大往小循环,否则,删除div元素后会引起serchResultLenth=serchResult.children.length;长度的变化(这个问题摸索了好久,才搞定,切记) for(va