Codeforces ABBYY Cup 3.0 / 316A1 316A2 Special Task(模拟&贪心&组合数学)

A1&A2. Special Task
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types there.

The content special agent has got an important task: to get the latest research by British scientists on the English Language. These developments are encoded and stored in a large safe. The Beaver's teeth are strong enough, so the authorities assured that upon arriving at the place the beaver won't have any problems with opening the safe.

And he finishes his aspen sprig and leaves for this important task. Of course, the Beaver arrived at the location without any problems, but alas. He can't open the safe with his strong and big teeth. At this point, the Smart Beaver get a call from the headquarters and learns that opening the safe with the teeth is not necessary, as a reliable source has sent the following information: the safe code consists of digits and has no leading zeroes. There also is a special hint, which can be used to open the safe. The hint is string s with the following structure:

  • if si = "?", then the digit that goes i-th in the safe code can be anything (between 0 to 9, inclusively);
  • if si is a digit (between 0 to 9, inclusively), then it means that there is digit si on position i in code;
  • if the string contains letters from "A" to "J", then all positions with the same letters must contain the same digits and the positions with distinct letters must contain distinct digits.
  • The length of the safe code coincides with the length of the hint.

For example, hint "?JGJ9" has such matching safe code variants: "51919", "55959", "12329", "93539" and so on, and has wrong variants such as: "56669", "00111", "03539" and "13666".

After receiving such information, the authorities change the plan and ask the special agents to work quietly and gently and not to try to open the safe by mechanical means, and try to find the password using the given hint.

At a special agent school the Smart Beaver was the fastest in his platoon finding codes for such safes, but now he is not in that shape: the years take their toll ... Help him to determine the number of possible variants of the code to the safe, matching the given hint. After receiving this information, and knowing his own speed of entering codes, the Smart Beaver will be able to determine whether he will have time for tonight's show "Beavers are on the trail" on his favorite TV channel, or he should work for a sleepless night...

Input

The first line contains string s — the hint to the safe code. String s consists of the following characters: ?, 0-9, A-J. It is guaranteed that the first character of string s doesn't equal to character 0.

The input limits for scoring 30 points are (subproblem A1):

  • 1 ≤ |s| ≤ 5.

The input limits for scoring 100 points are (subproblems A1+A2):

  • 1 ≤ |s| ≤ 105.

Here |s| means the length of string s.

Output

Print the number of codes that match the given hint.

Sample test(s)
input
AJ
output
81
input
1?AA
output
100

简单模拟,注意第一个数不是0.

对于较长的密文的处理,有两个小技巧~(详见下方A2代码)


完整代码:

A1

/*30ms,0KB*/

#include<cstdio>
#include<cstring>

char str[5];
bool vis[75];

int main(void)
{
	scanf("%s", str);
	int count = 1, len = strlen(str), j = 10;
	if (str[0] == '?')
		count *= 9;
	else if (str[0] > 64)
	{
		count *= 9;
		j=9;
		vis[str[0]] = true;
	}
	for (int i = 1; i < len; ++i)
	{
		if (str[i] == '?')
			count *= 10;
		else if (str[i] > 64 && !vis[str[i]])
		{
			vis[str[i]] = true;
			count *= j--;
		}
	}
	printf("%d", count);
	return 0;
}


A2

用了点小技巧~

/*30ms,100KB*/

#include<cstdio>
#include<cstring>

char str[100000];
bool vis[75];

int main()
{
	scanf("%s", str);
	int count = 1, charcount = 0, questioncount = 0, len = strlen(str), i, j = 10;
	if (str[0] == '?')
		count *= 9;///这个问号不统计在questioncount中
	else if (str[0] > 64)
	{
		count *= 9;
		j = 9;
		vis[str[0]] = true;
		charcount++;
	}
	for (i = 1; i < len; ++i)
	{
		if (str[i] == '?')
			questioncount++;///统计?出现的次数,然后直接在count后面补上就行,详见最后面的代码
		else if (str[i] > 64 && !vis[str[i]])
		{
			vis[str[i]] = true;
			count *= j--;
			charcount++;
		}
		if (charcount == 9)
			break;///统计到9个字母就只用统计?了~
	}
	for (; i < len; ++i)
		if (str[i] == '?')
			questioncount++;
	printf("%d", count);
	while (questioncount--)
		putchar('0');
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您提供的链接是Codeforces的一个问题,问题编号为104377。Codeforces是一个知名的在线编程竞赛平台,经常举办各种编程比赛和训练。Gym是Codeforces的一个扩展包,用于组织私人比赛和训练。您提供的链接指向了一个问题的页面,但具体的问题内容和描述无法通过链接获取。如果您有具体的问题或需要了解关于Codeforces Gym的更多信息,请提供更详细的信息。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [http://codeforces.com/gym/100623/attachments E题](https://blog.csdn.net/weixin_30820077/article/details/99723867)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [http://codeforces.com/gym/100623/attachments H题](https://blog.csdn.net/weixin_38166726/article/details/99723856)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [CodeforcesPP:Codeforces扩展包](https://download.csdn.net/download/weixin_42101164/18409501)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值