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 ...
随机推荐
- [算法]线段树(IntervalTree)
转载请注明出处:http://www.cnblogs.com/StartoverX/p/4617963.html 线段树是一颗二叉搜索树,线段树将一个区间划分成一些单元区间,每一个区间对应线段树的一个 ...
- 大小写转换,split分割
一.大小写转换 1.定义和用法 toUpperCase() 方法用于把字符串转换为大写. toLowerCase() 方法用于把字符串转换为小写. 用法: stringObject.toUppe ...
- 无递归 A星寻路算法
整理硬盘的时候,发现我早些年写的A星寻路算法.特放上来,待有缘人拿去,无递归噢,性能那是杠杠的. 码上伺候 public class Node { public int X { get; set; } ...
- CSS5.4 安装问题集
由于手痒,将5.2 卸载了,装了5.4 出现如下错误:install failed to install com.ti.ccstudio.debugserver.win32 corrctly. ... ...
- Linux准备——安装Ubuntu系统
今天对于我这个试图向安装Linux方向走的童鞋来说是个值得纪念的日子——我成功的安装上了Ubuntu操作系统. 整个的过程并不复杂,主要是看了网上Linux社区的一个安装教程.开始,我还在XP下安装, ...
- Invalid file system control data detected
今天在做mkdir操作时报错:Invalid file system control data detected.检查用户和权限没问题,再检查磁盘空间也没问题.最后在网上找到如下信息: [proble ...
- 理解JavaScript中的事件处理 阻止冒泡event.stopPropagation();
原文地址:http://www.cnblogs.com/binyong/articles/1750263.html 这篇文章对于了解Javascript的事件处理机制非常好,将它全文转载于此,以备不时 ...
- HDU_2053
Problem Description There are many lamps in a line. All of them are off at first. A series of operat ...
- zookeeper[4] 安装windows zookeeper,及问题处理
安装步骤: 1.在如下路径下载zookeeper-3.4.7.tar.gz http://mirrors.cnnic.cn/apache/zookeeper/stable/ 2.解压zookeeper ...
- squid 代理服务器安装配置
ubuntu16.04 安装squid代理服务器配置 本文参考 http://www.cnblogs.com/newflypig/archive/2012/09/28/2862000.html 1,删 ...