HDOJ 1316

点击打开链接

首先打表,然后就是比较了,比较恶心了一点,注意用compare比较 8  12会有 8>12,注意一下比较函数

测试数据:

input:

83 346930886
77 214636915
93 424238335
86 149760492
49 189641421
62 350490027

ouput :

32
31
31
30
32
32

代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
int   s[501][110];
char  str1[110] , str2[110];
char  tem[501][110] = {'0'};
void Plus()
{
    int i , j , k , count;
    memset(s,0,sizeof(s));
    s[1][0] = 1;
    s[2][0] = 2;
    for(i = 3;i <= 501;i++)
    {
        for(j = 0;j <= 105;j++)
        {
            s[i][j] += s[i-1][j]+s[i-2][j];
            if(s[i][j] >= 10)
            {
                s[i][j+1] += s[i][j]/10;
                s[i][j] %= 10;
            }
        }
    }
    for(i = 1;i <= 500;i++)
    {
        j = 105;
        while(j--)
        {
            if(s[i][j] != 0)
            {
                break;
            }
        }
        for(k = 0;j >= 0;j--,k++)
        {
            char ch = s[i][j] + 48;
            tem[i][k] = ch;
        }
    }
}
void cmp()
{
   int i , j , count , mark;
   int l1 , l2;
   l1 = strlen(str1);
   l2 = strlen(str2);
   for(i = 1;i <= 500;i++)
   {
       int len = strlen(tem[i]);
       if(l1 < len|| (l1 == len && strcmp(str1,tem[i])<=0))//这里判断左边界限
       {
               mark = i;
               break;
       }
   }
   count = mark;
   for(i = mark;i <= 500;i++)
   {
       int len = strlen(tem[i]);
       if(l2 < len||(l2 == len && strcmp(str2,tem[i])<0))//这里判断右边界限
       {
           mark = i;
           break;
       }
   }
   cout<<mark-count<<endl;
}
int main()
{
    int i , j;
    Plus();
    while(1)
    {
        cin>>str1>>str2;
        if(strcmp(str1,"0") == 0 && strcmp(str2,"0") == 0)
            break;
        else
        {
            cmp();
        }
    }
    return 0;
}
时间: 2024-09-15 17:01:37

HDOJ 1316的相关文章

把1316这个数表示成两个数的和,其中一个为13的倍数,另一个是11的倍数,求这两个数。

算法分析: 1316,显然1300是13的倍数,但16不是11的倍数,可以想到从1300上任意减去N个13的倍数其结果仍然是13的倍数,那么只要16加上这个减去的N个13的倍数其和是11的倍数,这两个数就解出来了,答案可能不只一个,但是我们只求一对解就可以了. 仔细观察不难发现:(16+13*3)+(1300-13*3)=1316,但是我们需要用代码实现: 复制代码 代码如下: <?php $n=1316; $i=0;//减去的第N个13,进行初始化为0 $y=16+13*$i;//1316分出

最大匹配-HDOJ 2458 Kindergarten

HDOJ 2458 Kindergarten Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some girls and boys know each other. Now the teachers want to pick some kids 

最大匹配-HDOJ 1068

HDOJ 1068 Girls and Boys . Problem Description the second year of the university somebody started a study on the romantic relations between the students. The relation "romantically involved" is defined between one girl and one boy. For the study

hdoj 1007 两点之间最短距离的二分之一 提交之后超时了 求c语言解法 感激不敬

问题描述 hdoj 1007 两点之间最短距离的二分之一 提交之后超时了 求c语言解法 感激不敬 #include"stdio.h" #include"math.h" int main() { int n,i,j; double s; while(scanf("%d",&n)&&n) { double a[100000][5]={0}; for(i=0;i<n;i++) for(j=0;j<2;j++) sca

HDOJ/HDU 1161 Eddy&amp;#39;s mistakes(大写字母转换成小写字母)

Problem Description Eddy usually writes articles ,but he likes mixing the English letter uses, for example "computer science" is written frequently "coMpUtEr scIeNce" by him, this mistakes lets Eddy's English teacher be extremely disco

HDOJ 2057 A + B Again

Problem Description There must be many A + B problems in our HDOJ , now a new one is coming. Give you two hexadecimal integers , your task is to calculate the sum of them,and print it in hexadecimal too. Easy ? AC it ! Input The input contains severa

HDOJ 2033 人见人爱A+B

Problem Description HDOJ上面已经有10来道A+B的题目了,相信这些题目曾经是大家的最爱,希望今天的这个A+B能给大家带来好运,也希望这个题目能唤起大家对ACM曾经的热爱. 这个题目的A和B不是简单的整数,而是两个时间,A和B 都是由3个整数组成,分别表示时分秒,比如,假设A为34 45 56,就表示A所表示的时间是34小时 45分钟 56秒. Input 输入数据有多行组成,首先是一个整数N,表示测试实例的个数,然后是N行数据,每行有6个整数AH,AM,AS,BH,BM,

HDOJ 1001Sum Problem

Problem Description Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge). In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + - + n. Input The input will consist of a series of integers n, one integer per line. Output For each ca

赛为智能中期净利1316万元同比增长30%

网易财经7月29日讯 赛为智能周四晚间发布了2010年半年报.2010年上半年,赛为智能现营业收入7810.35万元,比上年同期增长19.78%:营业利润1602.26万元, 同比增长26.04%:净利润1316.09万元,同比增长30.01%:基本每股收益0.14元,比上年同期下降17.65%. 赛为智能表示,按照地区分布来看,公司营业收入主要集中于以广州.深圳为核心的华南地区.华南地区是中国经济较发达地区之一,经济实力较强,对智能化系统的技术要求较高.质量要求较严,华南地区的智能化系统工程对