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,和以下题目给出的操作指令,并输入指令: 要求进行指令操作后,按格式 ...
随机推荐
- jquery Deferred使用经验
这周做了个小活动(http://aoqi.100bt.com/zt-2016duanzi/index.html),刚开始时候没看好需求,逻辑都写一块了 最后各种坑要填补,从中也获取了些经验和教训,下面 ...
- IP编辑控件(因为封装的是系统自带控件,所以也使用了CreateSubClass,不过为啥要封装CN_COMMAND和CN_NOTIFY不是很明白)
最近需要用一个IP输入控件,网上找了几个,都不符合效果,有些还有一些奇怪的Bug.后来发现原来系统已经提供了IP地址编辑控件,只是系统提供的控件不能设置只读效果.网上找了下资料,封装了一下,自己迂回一 ...
- Delphi体系内部的4种消息传递办法(Send,Post,Perform,Dispatch)
一.什么是消息? 消息是windows对应用程序发送的有关‘发生了某种事件’的通知.例如点击鼠标,调整窗口大小或键盘上按下一个键,都会引起windows发送一条消息到应用程序中去,去通知应用程序发生了 ...
- webBrowser中操作网页元素全攻略
原文 webBrowser中操作网页元素全攻略 1.获取非input控件的值: webBrowser1.Document.All["控件ID"].InnerText; 或webBr ...
- ajax终结篇
Ajax中post和get的区别 在ajax中有这个方法 xmlreq.open("post","servlet/MyServlet?time="+newDat ...
- Swift - 后台获取数据(Background Fetch)的实现
前面讲了如何让程序申请后台短时运行.但这个额外延长的时间毕竟有限.所以从iOS7起又引入两种在后台运行任务的方式:后台获取和后台通知. 1,后台获取介绍 后台获取(Background Fetch)是 ...
- Eclipse用法和技巧十:显示代码outline
在一个文件中快速找到某一个方法或者某一个作用域,可以使用 Ctrl+O或者Ctrl+F3,快速显示当前代码的outline,进行快速查找.效果如下: 这里主要是补充一些后续操作,能更加方 ...
- 极限挑战—C#100万条数据导入SQL SERVER数据库仅用4秒 (附源码)
原文:极限挑战-C#100万条数据导入SQL SERVER数据库仅用4秒 (附源码) 实际工作中有时候需要把大量数据导入数据库,然后用于各种程序计算,本实验将使用5中方法完成这个过程,并详细记录各种方 ...
- ArcGIS制图——多图层道路压盖处理
[1] 启动ArcMap,载入各道路要素类.生成名为All-Roads的图层组,如他所看到的,符号级别绘制将对图层组内图层符号起作用: 图层组设置符号等级 [2] 在内容列表中,右 ...
- asp.net微软认证全新考试题库及答案1
1.你创建了一个ASP.net应用程序,该程序将运行在TK公司的WEB站点上.你的应用程序包括100个WEB页面.你想配置你的应用程序,当HTTP代码发生错误时,可显示自定义的错误信息给用户.同时你想 ...