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>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}
long long p, q, t, tqm;
int tmp[15];

long long solve ( long long n ) {
    long long sum = 0;
    while ( n ) {
        sum += ( n / 10 ) * 45;
        sum += tmp[n % 10];
        n /= 10;
    }
    return sum;
}

int main ( ) {
    tmp[0] = 0;
    for ( int i = 1; i <= 9; ++i )
        tmp[i] = i + tmp[i - 1];

    while ( scanf ( "%lld%lld", &p, &q ) == 2 ) {
        if ( p < 0 && q < 0 ) break;
        if ( p > q ) tqm = p, p = q, q = tqm;

        printf ( "%lld\n", solve ( q ) - solve ( p - 1 ) );
    }
    return 0;
}
时间: 2024-10-25 08:50:16

UVA 10994 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

uva 12253 - Simple Encryption(dfs)

题目链接:uva 12253 - Simple Encryption 题目大意:给定K1,求一个12位的K2,使得KK21=K2%1012 解题思路:按位枚举,不且借用用快速幂取模判断结果. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; const ll ite=(1<<20)-1; ll N; /* l

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,

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 n

uva 10014 Simple calculations

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=955 根据递推公式推倒出a1的公式. a1=(n*a0+an+1-2*(n*c1+(n-1)*c2+...+cn))/(n+1); 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm>

Uva 10912 Simple Minded Hashing (计数DP)

4th IIUC Inter-University Programming Contest, 2005 H Simple Minded Hashing Input: standard input Output: standard output Problemsetter: Sohel Hafiz All of you know a bit or two about hashing. It involves mapping an element into a numerical value usi

[数位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&