SPOJ FANCY - FANCY NUMBERS

题目链接http://www.spoj.com/problems/FANCY/

题目大意:如果一串数字为555,那么我们可以将其写为(5,5,5) (5,55) (55,5) (555)。现在给你一串数字,问它能有几种不同的写出方式。

解题思路:首先应该是无论有几个连续的都算作一种读出方式(题目上只举出了double和triple两种)。那么对于一串连续相同的数字来说,不同读出方式相当于在这些数字之间插入空位将其隔开。

例如22222,插入零个空位C(4,0),一个空位C(4,1),两个C(4,2),三个C(4,3),四个C(4,4)。那么有C(4,0)+C(4,1)+C(4,2)+C(4,3)+C(4,4)=24种。

代码:

 1 char str[35];
 2
 3 void solve(){
 4     int cnt = 0;
 5     ll ans = 1;
 6     char la = ‘#‘;
 7     for(int i = 0; str[i]; i++){
 8         if(la != ‘#‘ && str[i] == la) cnt++;
 9         else if(la != ‘#‘ && str[i] != la){
10             if(cnt) ans *= 1 << cnt;
11             cnt = 0;
12         }
13         la = str[i];
14     }
15     if(cnt > 0) ans *= 1 << cnt;
16     printf("%lld\n", ans);
17 }
18 int main(){
19     int t;
20     scanf("%d", &t);
21     while(t--){
22         scanf("%s", str);
23         solve();
24     }
25 }

题目:

FANCY - FANCY NUMBERS

#math

FANCY NUMBERS

Girls usually give only missed calls to their boyfriends and they want them to call back. These boys are now busy with their engineering subjects and cannot remember all girl friends’ mobile number. Because of this, girls make it easy for them by having fancy mobile numbers. A fancy mobile number may contain many continuous digits in it.

For example 9994442200 is a fancy mobile number because the boy can remember simply as triple nine, triple four, double two and double zero. As they are engineering students they do think different. One of the engineering students can spell the above number as double nine, nine, four, double four, two, two, double zero.

The number 100 has only 2 possibilities as it can be spelt as either one, zero, zero (or) one, double zero

Given a mobile number find the number of possibilities that the number can be remembered.

Input Specification:

The first line consists of an integer t denoting the number of test cases. Each test case consists of a mobile number of length <= 30 digits.

Output Specification:

For each test case output the number of possibilities the number can be remembered.

Input Constraints: 1<=t<=100000

Sample Input:

3
100
12345
11112

Sample Output:

2
1
8

WARNING:  Huge data set! Make your I/O optimizations.

时间: 2025-01-31 04:50:05

SPOJ FANCY - FANCY NUMBERS的相关文章

SPOJ BALNUM Balanced Numbers 状压+数位DP

一开始想了一个用二进制状压的方法,发现空间需要的太大,光光memset都要超时 = = 其实不用每次都memset 也可以用三进制,一开始直接打表出所有的状态转移就好 #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <climits> #include <string> #include <iostream&g

SPOJ BALNUM Balanced Numbers(数位dp)

Balanced Numbers Time Limit:123MS     Memory Limit:1572864KB     64bit IO Format:%lld & %llu Submit Status Practice SPOJ BALNUM Description Balanced numbers have been used by mathematicians for centuries. A positive integer is considered a balanced n

SPOJ BALNUM Balanced Numbers(数位dp,状态压缩)

BALNUM - Balanced Numbers no tags 题目链接 Balanced numbers have been used by mathematicians for centuries. A positive integer is considered a balanced number if: 1)      Every even digit appears an odd number of times in its decimal representation 2)   

spoj RAONE - Ra-One Numbers (数位dp)

RAONE - Ra-One Numbers no tags In the War between good and evil . Ra-One is on the evil side and G-One on the good side. Ra-One is fond of destroying cities and its G-one's duty to protect them.. Ra-One loves to destroy cities whose Zip Code has spec

SPOJ - BALNUM - Balanced Numbers(数位DP)

链接: https://vjudge.net/problem/SPOJ-BALNUM 题意: Balanced numbers have been used by mathematicians for centuries. A positive integer is considered a balanced number if: 1) Every even digit appears an odd number of times in its decimal representation 2)

SPOJ BALNUM Balanced Numbers 平衡数(数位DP,状压)

题意: 平衡树定义为“一个整数的某个数位若是奇数,则该奇数必定出现偶数次:偶数位则必须出现奇数次”,比如 222,数位为偶数2,共出现3次,是奇数次,所以合法.给一个区间[L,R],问有多少个平衡数? 思路: 这题比较好解决,只有前导零问题需要解决.如果枚举到011,那么其前导零(偶数)出现了1次而已,而此数11却是平衡数,所以不允许前导零的出现! 由于dfs时必定会枚举到前导零,否则位数较少的那些统计不到.状态需要3维or2维也行,3维的比较容易处理,用一维表示数位出现次数,另一维表示数位是否

spoj 10606 Balanced Numbers 数位dp

题目链接 一个数称为平衡数, 满足他各个数位里面的数, 奇数出现偶数次, 偶数出现奇数次, 求一个范围内的平衡数个数. 用三进制压缩, 一个数没有出现用0表示, 出现奇数次用1表示, 出现偶数次用2表示, 这样只需要开一个20*60000的数组. 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define pb(x) push_back(x) 4 #define ll long long 5 #define mk(x, y) make_

SPOJ Problem:Beehive Numbers

阅读题..加上等差数列判断.. #include<cstdio> #include<cmath> int n,s; int main(){ while(scanf("%d",&n)&&n!=-1){ n--; if (n%6){printf("N\n");continue;} n/=3; s=int (sqrt(double(n))); if (s*(s+1)==n)printf("Y\n"); e

[思路题] spoj 11354 Amusing numbers

题意: 给k(1<=k<=10^15),问第k 大的只含有数字5和6的数是多少 比如 1就是5 ,3就是55 ,4就是56 思路: 首先我们可以发现,一位数有2个这的数,两位数有4个,三位数有8个.. 那么我们可以通过统计确定出第k大的数是几位的. 通过累和,一位数以下0个,两位数以下2,三位数以下6 n位数以下就是2^n-2 然后给k,从大到下搜索第一个小于k的bit[i],那么就有i位数. 然后就是对于i位数,它是第几个数. 比如说k=70,它就是6位数. 然后 70-bit[6]-1=7