HDU 2410 Barbara Bennett's Wild Numbers (想法题)

题目链接:HDU 2410 Barbara Bennett‘s Wild Numbers

题意:给出两串数w,s(长度相同),第一串中有“?”,问“?”取的值使w对应的数大于s对应的数 的最大方案数。

思路:W,S一一对应比较;

遇到第一个’?‘之前比较情况

1.w[i]<s[i] 方案数0种;break;

2.w[i]>s[i] break。之后有n个‘’?‘ 方案数就有10的n次方种。

3.w[i]=s[i] 继续比较,重复1.2两个条件。

遇到’?‘

1.能取数个数是 ’9‘-x[i]。之后10的n次方。

2.取等于x[i] ,继续比较。

AC代码:

#include<stdio.h>
#include<string.h>
char w[20],x[20];
int get(int i,int temp,int len)
{
    int j;
    for(j=i+1; j<len; j++)
    {
        if(w[j]=='?')
            temp*=10;
    }
    return temp;
}

int main()
{
    int len,i,j;
    while(scanf("%s",w)!=EOF)
    {
        if(strcmp(w,"#")==0)
            break;
        scanf("%s",x);
        len=strlen(w);
        int ans=0;
        for(i=0; i<len; i++)
        {
            if(w[i]=='?')
                ans+=get(i,'9'-x[i],len);
            else
            {
                if(w[i]==x[i])
                    continue;
                if(w[i]>x[i])
                    ans+=get(i,1,len);
                break;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}
/*
12?4?
12354
12?5?
12354
*/

HDU 2410 Barbara Bennett's Wild Numbers (想法题)

时间: 2024-10-13 16:10:02

HDU 2410 Barbara Bennett's Wild Numbers (想法题)的相关文章

POJ 3340 &amp; HDU 2410 Barbara Bennett&#39;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

HDU 2410 Barbara Bennett&amp;#39;s Wild Numbers (想法题)

题目链接:HDU 2410 Barbara Bennett's Wild Numbers 题意:给出两串数w,s(长度同样),第一串中有"?",问"?"取的值使w相应的数大于s相应的数 的最慷慨案数. 思路:W,S一一相应比較: 遇到第一个'?'之前比較情况 1.w[i]<s[i] 方案数0种:break: 2.w[i]>s[i] break. 之后有n个''?' 方案数就有10的n次方种. 3.w[i]=s[i] 继续比較.反复1.2两个条件. 遇到'

poj 3340 Barbara Bennett&#39;s Wild Numbers(数位DP)

Barbara Bennett's Wild Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3153   Accepted: 1143 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 hav

HDU - 5806 NanoApe Loves Sequence Ⅱ 想法题

http://acm.hdu.edu.cn/showproblem.php?pid=5806 题意:给你一个n元素序列,求第k大的数大于等于m的子序列的个数. 题解:题目要求很奇怪,很多头绪但写不出,选择跳过的题,简称想法题. 首先考虑区间的更新方法:区间左端l不动,右端r滑动, 滑到有k个数>=m时,此区间符合条件,并且发现右端点再往右滑到底,此条件一直符合(因为若加入的数小于"第K大的数",则毫无影响.若不然,加入该数会产生一个新的第k大数,保证>="第K大

HDU 4972 Bisharp and Charizard 想法题

Bisharp and Charizard Time Limit: 1 Sec  Memory Limit: 256 MB Description Dragon is watching NBA. He loves James and Miami Heat. Here's an introduction of basketball game:http://en.wikipedia.org/wiki/Basketball. However the game in Dragon's version i

hdu 5641 King&#39;s Phone(暴力模拟题)

Problem Description In a military parade, the King sees lots of new things, including an Andriod Phone. He becomes interested in the pattern lock screen. The pattern interface is a 3×3 square lattice, the three points in the first line are labeled as

HDU - 4813 Hard Code (长春赛区水题)

Description Some strange code is sent to Da Shan High School. It's said to be the prophet's note. The note is extremely hard to understand. However, Professor Meng is so smart that he successfully found the pattern of the code. That is, the length of

hdu 1312 Red and Black(BFS水题)

Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9684    Accepted Submission(s): 6021 Problem Description There is a rectangular room, covered with square tiles. Each tile is colore

HDU 4937 (杭电多校 #7 1003题)Lucky Number(瞎搞)

题目地址:HDU 4937 多校的题以后得重视起来...每道题都错好多次...很考察细节.比如这道....WA了无数次.... 这题的思路自己真心想不到...这题是将进制后的数分别是1位,2位,3位和更多位的分开来计算. 当是1位的时候,显然只有3到6,此时只能是-1 当是2位的时候,可以转换成一元一次方程求解 当是3位的时候,可以转换成一元二次方程求解 当是4位的时候,此时最多也只有7000个数,7000^3接近1e12.所以剩下的直接枚举进制数来判断即可. 代码如下: #include <i