POJ 3340 & HDU 2410 Barbara Bennett's Wild Numbers(数学)
题目链接:
PKU:http://poj.org/problem?id=3340
HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2410
Description
A wild number is a string containing digits and question marks (like 36?1?8). A number X matches a wild number W if they have the same length, and every non-question mark character in X is equal to the character in the
same position in W (it means that you can replace a question mark with any digit). For example, 365198 matches the wild number 36?1?
8, but 360199, 361028, or 36128 does not. Write a program that reads a wild number W and a number X from
input, both of length n, and determines the number of n-digit numbers that match W and are greater than X.
Input
There are multiple test cases in the input. Each test case consists of two lines of the same length. The first line contains a wild number W, and the second line contains an integer number X. The length of input lines is between 1 and 10
characters. The last line of input contains a single character #.
Output
For each test case, write a single line containing the number of n-digit numbers matching W and greater than X (n is the length of W and X).
Sample Input
36? 1? 8
236428
8?3
910
?
5
#
Sample Output
100
0
4
Source
题意:
给出两个数字字符串,串一中有'?',问在‘?’位置填数字共同拥有多少中填法,保证串一大于串二!
代码例如以下:
#include <cstdio>
#include <cstring>
#include <cmath>
const int maxn = 17;
typedef __int64 LL;
int cont;
LL ans;
char s1[maxn];
char s2[maxn];
LL POW(LL n, LL k)
{
LL s = 1;
for(LL i = 0; i < k; i++)
{
s*=n;
}
return s;
}
void solve(int len, int k)
{
for(int i = 0; i < len; i++)
{
if(s1[i] == '? ')
{
ans+=(9-(s2[i]-'0'))*POW(10,--cont);
}
else if(s1[i] < s2[i])
return ;
else if(s1[i] > s2[i])
{
ans+=POW(10,cont);
return ;
}
}
}
int main()
{
while(~scanf("%s",s1))
{
ans = 0;
cont = 0;
if(s1[0] == '#')
break;
scanf("%s",s2);
int len = strlen(s1);
for(int i = 0; i < len; i++)
{
if(s1[i] == '?')
cont++;
}
solve(len,0);
printf("%I64d\n",ans);
}
return 0;
}
POJ 3340 & HDU 2410 Barbara Bennett's Wild Numbers(数学)的更多相关文章
- hdu 2410 Barbara Bennett's Wild Numbers
Problem - 2410 挺好玩的一道题目.这道题的意思是给出一个模糊值以及一个确定值,要求求出模糊值中大于确定值的个数有多少. 这题我是直接用dfs的方法搜索的,对于每一位如果之前位置的形成的数 ...
- poj 3340 Barbara Bennett's Wild Numbers(数位DP)
Barbara Bennett's Wild Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3153 A ...
- POJ 3344 & HDU 2414 Chessboard Dance(模拟)
题目链接: PKU:http://poj.org/problem? id=3344 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2414 Descrip ...
- POJ 3831 & HDU 3264 Open-air shopping malls(几何)
题目链接: POJ:id=3831" target="_blank">http://poj.org/problem?id=3831 HDU:http://acm.h ...
- POJ 3691 & HDU 2457 DNA repair (AC自己主动机,DP)
http://poj.org/problem?id=3691 http://acm.hdu.edu.cn/showproblem.php?pid=2457 DNA repair Time Limit: ...
- POJ 3481 & HDU 1908 Double Queue (map运用)
题目链接: PKU:http://poj.org/problem?id=3481 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1908 Descript ...
- POJ 3835 & HDU 3268 Columbus’s bargain(最短路 Spfa)
题目链接: POJ:http://poj.org/problem?id=3835 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=3268 Problem ...
- POJ 3928 & HDU 2492 Ping pong(树阵评价倒数)
主题链接: PKU:http://poj.org/problem?id=3928 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2492 Descript ...
- ●线段树的三个题(poj 3225,hdu 1542,hdu 1828)
●poj 3225 Help with Intervals(线段树区间问题) ○赘述题目 给出以下集合操作: 然后有初始的一个空集S,和以下题目给出的操作指令,并输入指令: 要求进行指令操作后,按格式 ...
随机推荐
- JS firebug小技巧
实际上前端的发展与进步也离不开浏览器的支持,而对于开发者来讲,浏览器最好的支持,就是对于debug的良好支持,甚至在某些兴许接手的项目中,前端的debug甚至能够解决好多问题--不说了,都是泪啊!还是 ...
- asp.net下用js实现弹出子窗口选定值并返回
对应上一篇博客代码: 父页面: <head runat="server"> <meta http-equiv="X-UA-Compatible" ...
- 【zigbee】开启及清除NV_RESTORE信息的方法
1.NV_RESTORE宏的作用 问:coo和终端都已经组网成功 1.这时将coo断电,又一次上电,组网后终端的短地址是否不变? 2.这时终端断电,又一次上电,组网后终端的短地址是否不变? 3.这时C ...
- Kendo UI开发教程(25): 单页面应用(三) View
View为屏幕上某个可视部分,可以处理用户事件. View可以通过HTML创建或是通过script元素.缺省情况下View将其所包含的内容封装在一个Div元素中.Kendo创建View有两种方式: 使 ...
- android面试题目大全<完结部分>,android笔试题目集锦
1. 下列哪些语句关于内存回收的说明是正确的? (b ) A. 程序员必须创建一个线程来释放内存 B.内存回收程序负责释放无用内存 C.内存回收程序允许程序员直接释放内存 D.内存回收 ...
- ASP.NET - 服务器控件button 先执行js 再执行后台的方法
关于button这个服务器控件,我一直想减少它向服务器提交数据.那些检测,还是在客户端实现就好了.这就需要javascript,但是我发现仅仅有javascript还是不够的.button服务器控件的 ...
- UVA 11464 - Even Parity(枚举方法)
D Even Parity Input: Standard Input Output: Standard Output We have a grid of size N x N. Each cell ...
- 采购订单me22n 或者me21n增强 (点击保存和回车)
IF_EX_ME_PROCESS_PO_CUST DATA:l_header TYPE mepoheader, l_item TYPE mepoitem. DATA:lt_items TYPE pur ...
- PL/SQL批处理语句(BULK COLLECT子句和FORALL语句)
Oracle为PL/SQL中的SQL相关功能提供了FORALL语句和BULK COLLECT子句,显著的增强了SQL相关功能.这两个语句一起被称作PL/SQL的批处理语句.Oracle为什么要提供这两 ...
- 如果是在有master上开启了该参数,记得在slave端也要开启这个参数(salve需要stop后再重新start),否则在master上创建函数会导致replaction中断。
如果是在有master上开启了该参数,记得在slave端也要开启这个参数(salve需要stop后再重新start),否则在master上创建函数会导致replaction中断.