• SPOJ FANCY


    题目链接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
    ", 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


    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.

  • 相关阅读:
    离线安装SilverLight
    Singleton模式
    首次进入
    实现多层菜单(=_=!)(很傻又很土的办法)
    【转】Java中Split函数的用法技巧
    【转】来电显示
    DatePickerDialog
    Unable to resolve target 'android9'
    退出activity的另一种写法
    滚轮控件的定义和使用
  • 原文地址:https://www.cnblogs.com/bolderic/p/7400218.html
Copyright © 2020-2023  润新知