uva 10994 - Simple Addition
//组合数学
//计算sum{i从右往左数的第一个非0数字,p<=i<=q}。
#include <cstdio>
typedef long long ll; ll sum(ll n)
{
ll ans = , x;
while(n)
{
x = n % ;
n /= ;
ans += (( + x) * x) / + n * ; //当个位在循环的时候,高位的朋友你在干嘛?
}
return ans;
} int main()
{
ll a, b;
while(scanf("%lld%lld", &a, &b), a >= )
{
printf("%lld\n", sum(b) - sum(a - ));
}
return ;
}
题目大意:给出l和r,求∑(l≤i≤r)F(i), F(i)函数题目中有。
解题思路:由两边向中间缩进,然后l和r之间的数可以按照1~9划分(只会有这几种情况)。
#include <stdio.h>
#define ll long long
ll ans; ll f(ll x) {
if (x == ) return ;
else if (x % )
return x % ;
else
return f(x / );
} void solve(ll l, ll r) {
if (r - l < ) {
for (int i = l; i <= r; i++)
ans += f(i);
return;
} while (l % ) {
ans += f(l);
l++;
} while (r % ) {
ans += f(r);
r--;
}
ans += * (r - l) / ;
solve(l / , r / );
} int main () {
ll l, r;
while (scanf("%lld%lld", &l, &r), l >= || r >= ) {
ans = ;
solve(l, r);
printf("%lld\n", ans);
}
return ;
}
其實只要看題目推敲一下,大概可以知道其實就是各個數字最低階不是0的數字的總和。
可將題目要加的拆成各個位數來做,每一個位數都要考慮%10和/10的情況要加多少,將這些值全部加起來即可得解。
P.S. 雖然p,q可以在32bits整數下存放,但可沒說總和也可以喔!
#include<iostream>
#include<cstdio>
using namespace std; int main(){
long long p, q;
long long sum; while( scanf( "%lld%lld", &p, &q ) != EOF && !( p < && q < )){
sum = ; while( p || q ){
sum += (q%+p%)*((q%)-(p%)+)/;
sum += (q/-p/)*; if( p% && (p/ || q/) ) p += ;
p /= ;
q /= ;
} printf( "%lld\n", sum );
}
return ;
}
uva 10994 - Simple Addition的更多相关文章
- uva 10994 - Simple Addition(规律)
题目链接:uva 10994 - Simple Addition 题目大意:给出l和r,求∑(l≤i≤r)F(i), F(i)函数题目中有. 解题思路:由两边向中间缩进,然后l和r之间的数可以按照1~ ...
- 10994 - Simple Addition(规律)
Problem E Simple Addition Input: Standard Input Output: Standard Output Let’s define a simple recurs ...
- 组合数学第一发 hdu 2451 Simple Addition Expression
hdu 2451 Simple Addition Expression Problem Description A luxury yacht with 100 passengers on board ...
- uva 12253 - Simple Encryption(dfs)
题目链接:uva 12253 - Simple Encryption 题目大意:给定K1.求一个12位的K2,使得KK21=K2%1012 解题思路:按位枚举,不且借用用高速幂取模推断结果. #inc ...
- HDU 2451 Simple Addition Expression(组合数学)
主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2451 Problem Description A luxury yacht with 100 pass ...
- HDU2451:Simple Addition Expression
Problem Description A luxury yacht with 100 passengers on board is sailing on the sea in the twiligh ...
- UVA - 10014 - Simple calculations (经典的数学推导题!!)
UVA - 10014 Simple calculations Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & ...
- 【计数】Simple Addition Expression
[来源] 2008年哈尔滨区域赛 [题目链接]: http://acm.hdu.edu.cn/showproblem.php?pid=2451 [参考博客]: HDU 2451 Simple Addi ...
- uva 10014 Simple calculations
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
随机推荐
- 新写PHP HTTP断点续传类文件代码
一个支持断点续传的PHP文件下载类文件,调用方法简单,类代码简洁,可记忆上次的下载的节点,实现累积下载,类名称download,类代码如下: function download($path,$file ...
- NSSet和NSMutableSet 确保数据的唯一性--备
NSSet和NSMutableSet是无序的, 但是它保证数据的唯一性.当插入相同的数据时,不会有任何效果.从内部实现来说是hash表,所以可以常数时间内查找一个数据. 1.NSSet的使用 [NSS ...
- SparkStreaming 源码分析
SparkStreaming 分析 (基于1.5版本源码) SparkStreaming 介绍 SparkStreaming是一个流式批处理框架,它的核心执行引擎是Spark,适合处理实时数据与历史数 ...
- 转:ASCII码表_全_完整版
ASCII码表 ASCII值 控制字符 ASCII值 控制字符 ASCII值 控制字符 ASCII值 控制字符 0 NUL 32 (space) 64 @ 96 . 1 SOH 33 ! 65 A 9 ...
- 转:DSP学习经验
转载:http://www.cnblogs.com/MrYang/archive/2010/12/21/1913035.html
- Cisco C2900XL
http://docstore.mik.ua/univercd/cc/td/doc/product/lan/c2900xl/c2900sa4/sa4cr/macintr.htm#xtocid10160 ...
- 模糊语意变数、规则和模糊运算--AForge.NET框架的使用(二)
原文:模糊语意变数.规则和模糊运算--AForge.NET框架的使用(二) 语意变数(Linguistic Variable) 语意变数存储了数个语意量(标签),每个语意量包含一个识别名和模糊集合.在 ...
- ActionBar兼容性的实现方式的要点
1.对于APILevel <11 的版本兼容ActionBar <1> Activity 继承ActionBarActivity <2> 获取ActionBar的方法:g ...
- Java基础加强学习笔记(二)
一.反射的基础Class类 1.如何得到各个字节码对应的实例对象 (1)类名.class,例如 System.class (2)对象.getClass(),例如 new Data().getClass ...
- 【转】如何在 Android 程序中禁止屏幕旋转和重启Activity
原文网址:http://www.cnblogs.com/bluestorm/p/3665890.html 禁止屏幕随手机旋转变化 有时候我们希望让一个程序的界面始终保持在一个方向,不随手机方向旋转而变 ...