UVA10994 Simple Addition【前缀和】

Lets define a simple recursive function F(n), where

????Lets define another function S(p, q),

????In this problem you have to Calculate S(p, q) on given value of p and q.
Input
The input file contains several lines of inputs. Each line contains two non negative integers p and q (p ≤ q) separated by a single space. p and q will fit in 32 bit signed integer. In put is terminated by a line which contains two negative integers. This line should not be processed.
Output
For each set of input print a single line of the value of S(p, q).
Sample Input
1 10
10 20
30 40
-1 -1
Sample Output
46
48
52

问题链接UVA10994 Simple Addition
问题简述:(略)
问题分析
????数学计算问题,构造一个计算前缀和的函数实现。需要根据组合数学知识来推导公式。函数F(n)计算n的最右边非0数字。S(0,9)=45。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++程序如下:

/* UVA10994 Simple Addition */

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

LL sum(LL n)
{
    LL ans = 0, x;
    while(n) {
        x = n % 10;
        n /= 10;
        ans += ((1 + x) * x) / 2 + n * 45;
    }
    return ans;
}

int main()
{
    LL a, b;
    while(~scanf("%lld%lld", &a, &b) && a >= 0)
        printf("%lld\n", sum(b) - sum(a - 1));

    return 0;
}

原文地址:https://www.cnblogs.com/tigerisland45/p/10469915.html

时间: 2024-08-26 14:03:40

UVA10994 Simple Addition【前缀和】的相关文章

HDU 2451 Simple Addition Expression(组合数学)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2451 Problem Description A luxury yacht with 100 passengers on board is sailing on the sea in the twilight. The yacht is ablaze with lights and there comes out laughers and singing from the hall where an

HDU 2451 Simple Addition Expression

Simple Addition Expression Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1508    Accepted Submission(s): 576 Problem Description A luxury yacht with 100 passengers on board is sailing on the s

【HDOJ】2451 Simple Addition Expression

递推,但是要注意细节.题目的意思,就是求s(x) = i+(i+1)+(i+2),i<n.该表达中计算过程中CA恒为0(包括中间值)的情况.根据所求可推得.1-10: 31-100: 3*41-1000: 3*4*41-10000: 3*4*4*41-10^n: 3*4^(n-1).并且需要注意,一旦发现某一位大于3,则应立即跳出累加的循环.比如,f(133) = 24,f(143) = 24.同时,单独讨论个位的情况.28行的break处理该种情况. 1 #include <cstdio&g

HDU2451:Simple Addition Expression

Problem Description A luxury yacht with 100 passengers on board is sailing on the sea in the twilight. The yacht is ablaze with lights and there comes out laughers and singing from the hall where an evening party is in full swing. People are singing,

[数位dp] hdu 2451 Simple Addition Expression

题意:给N,求小于N的数中,三个连续的数相加不进位的数有多少个. 思路:和上题类似,就是不是个位的话,可以放0,1,2,3,个位的话只能放0,1,2. 然后就是边界考虑一下,不能超过当前位. 然后就是边界的判断,不是等于len而是等于当前位. 代码: #include"cstdlib" #include"cstdio" #include"cstring" #include"cmath" #include"queue&

HDU 2451 Simple Addition Expression(找规律,考验智商)

题目 最近比赛的题目好多签到题都是找规律的考验智商的题目啊,,,我怎么越来越笨了,,,, 通过列举,可以发现规律: 从左往右按位扫这个数: 当数的长度大于1时: 当首位大于3时,答案就是4*4*4*……*4*3(即pow(4,后面的长度-1)*3): 否则,则是 首位的数字*4*4*4*……*4*3: 当数的长度为1时,并且之前的(即其他的)都没有进位,则直接判断一下ans要加多少个: #include<stdio.h> #include<string.h> #include<

UVA 10994 Simple Addition

感觉这个一定要记下来涨教训啊.一开始找规律找错了.判断超麻烦还各种WA.浪费N个小时啊..人家几行就A了.太弱, #include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <stack> #include <queue> #include <cctype

HDU2451 Simple Addition expression(数位dp/找规律)

题意 对于一个非负整数 i, 当 \(i + (i+1) + (i+2)\) 计算过程中不产生进位时,称i满足条件, 求 小于n的 i 的个数. 传送门 思路 数位dp. Code #include <bits/stdc++.h> using namespace std; typedef long long ll; ll dp[20][5], n; int a[20], top; ll dfs(int pos, int sta, bool limit) { if(pos==-1) return

【CV知识学习】神经网络梯度与归一化问题总结+highway network、ResNet的思考

这是一篇水货写的笔记,希望路过的大牛可以指出其中的错误,带蒟蒻飞啊~ 一.    梯度消失/梯度爆炸的问题 首先来说说梯度消失问题产生的原因吧,虽然是已经被各大牛说烂的东西.不如先看一个简单的网络结构, 可以看到,如果输出层的值仅是输入层的值与权值矩阵W的线性组合,那么最终网络最终的输出会变成输入数据的线性组合.这样很明显没有办法模拟出非线性的情况.记得神经网络是可以拟合任意函数的.好了,既然需要非线性函数,那干脆加上非线性变换就好了.一般会使用sigmoid函数,得到,这个函数会把数据压缩到开