ZUFE OJ 2289 God Wang II
Description
这个世界太无聊了,于是God Wang想出了新的运算符号$,对于两个数x,y来说x$y的值等于x和y各个位置上的数字乘积之和,没有的位按0来算
比如说123$321=1*3+2*2+3*1=10,105$51=1*0+0*5+5*1=5。于是God Wang又有了新的问题,
他定义了函数F(L,R)=(((((L$(L+1))$(L+2))$(L+3)....)$R),他想要知道F(L,R)的值,现在请你来告诉他吧。
Input
输入第一行为一个正整数T(T<=1000)
接下来T行,每行两个整数L,R (0<=L<R<=2^31-1)
Output
输出T行,每行一个整数表示输出的答案
Sample Input
Sample Output
暴力跑,遇到是0了就退出循环,因为之后一定都是0。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; int L,R;
int X[];
int Y[];
int xx,yy; int F(int x,int y)
{
memset(X,,sizeof(X));
memset(Y,,sizeof(Y));
xx=;
yy=;
int ans=;
while(x)
{
X[xx]=x%;
x=x/;
xx++;
}
while(y)
{
Y[yy]=y%;
y=y/;
yy++;
}
for(int i=; i<max(xx,yy); i++)
ans=ans+X[i]*Y[i];
return ans;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&L,&R);
int A=L;
for(int i=L+; i<=R; i++)
{
A=F(A,i);
if(A==) break;
}
printf("%d\n",A);
}
return ;
}
ZUFE OJ 2289 God Wang II的更多相关文章
- ZUFE OJ 2288 God Wang I
Description God Wang 是ZUFE的神犇,有一天他想到一种神奇的变换,并且将它命名为GodW变换 对于一个数字n,该变换后的值GodW(n)为,先令X=n 第一步,如果X为个位数,G ...
- 【LeetCode OJ】Path Sum II
Problem Link: http://oj.leetcode.com/problems/path-sum-ii/ The basic idea here is same to that of Pa ...
- 【LeetCode OJ】Word Ladder II
Problem Link: http://oj.leetcode.com/problems/word-ladder-ii/ Basically, this problem is same to Wor ...
- 【LeetCode OJ】Palindrome Partitioning II
Problem Link: http://oj.leetcode.com/problems/palindrome-partitioning-ii/ We solve this problem by u ...
- 【LEETCODE OJ】Single Number II
Problem link: http://oj.leetcode.com/problems/single-number-ii/ The problem seems like the Single Nu ...
- 【LeetCode OJ】Word Break II
Problem link: http://oj.leetcode.com/problems/word-break-ii/ This problem is some extension of the w ...
- ZUFE OJ 2301 GW I (3)
Description GW 是ZUFE的神犇,有一天他想到一种神奇的变换,并且将它命名为GW变换 对于一个数字n,该变换后的值GW(n)为,先令X=n 第一步,如果X为个位数,GW(n)=X,否则执 ...
- LeetCode OJ——Pascal's Triangle II
http://oj.leetcode.com/problems/pascals-triangle-ii/ 杨辉三角2,比杨辉三角要求的空间上限制Could you optimize your algo ...
- [LeetCode OJ] Linked List Cycle II—Given a linked list, return the node where the cycle begins. If there is no cycle, return null.
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode ...
随机推荐
- java-jvisualvm远程监控tomcat
一.修改要访问的远程主机(Linux)相关文件,本文档只介绍了java-jvisualvm的JMX方式: 1.打开$CATALINA_HOME/bin/startup.sh, 找到倒数第二行(也就是e ...
- Apache .htaccess语法之RewriteRule
[说明]定义重写的规则[语法]RewriteRule Pattern rewritePattern [flags] # 开启 rewrite 功能 Options +FollowSymlinks Re ...
- 下载PhpStorm并进行激活
1.首先登陆PhpStorm官网http://www.jetbrains.com/phpstorm/ 点击附图中的download now 按钮 2.第二步根据os x \wind\ linux进行下 ...
- 使用PIE对IE进行CSS3兼容介绍和经验总结
国外团队开发的兼容插件,去年做项目时才发现,非常强大 主角:PIE.js , PIE.htc 两种方法可以实现 官方网站:http://css3pie.com/ 演示地址:http://css3pie ...
- VB VBA VBS有什么区别?
VB和VBA本就是同宗的姐妹,只不过姐姐VB的功夫要比妹妹VBA历害些.不过姐姐只会单打独斗是女强人:妹妹却只会傍大款(例如Office).姐姐有生育能力,是真正的女人:妹妹却不会生崽(生成.EXE) ...
- JavaScript忍者秘籍——函数(上)
概要:本篇博客主要介绍了JavaScript的函数. 1.第一型对象 JavaScript的函数可以像对象一样引用,因此我们说函数是第一型对象.除了可以像其他对象类型一样使用外,函数还有一个特殊的功能 ...
- java default使用
我们都知道在Java语言的接口中只能定义方法名,而不能包含方法的具体实现代码.接口中定义的方法必须在接口的非抽象子类中实现.下面就是关于接口的一个例子: public interface Simple ...
- Hadoop故障排除:jps 报process information unavailable
4883 -- process information unavailable 解决办法: 进入tmp目录, cd /tmp 删除该目录下 名称为hsperfdata_{username}的文件夹 然 ...
- input美化上传按钮美化
今天工作需求碰到 样式改变上传按钮 效果: <a href="javascript:;" class="a-upload"> <input t ...
- What is Flux?
Pluralsight - React and Flux for Angular Developers 1. An architectural concept. It a idea. 2. Not a ...