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 ...
随机推荐
- vim 撤销 恢复 快捷键
u 撤销上一步的操作 Ctrl+r 恢复上一步被撤销的操作
- 为 ngui TweenPosition 添加 pingpongone
//---------------------------------------------- // NGUI: Next-Gen UI kit // Copyright © 2011-2015 T ...
- 李明杰的视频和李明杰的博客是学习OC的基础
http://www.cocoachina.com/bbs/read.php?tid=196664
- LoadRunner日志(归档记录,以便自己查阅)
1.当设置迭代次数大于1时,回放从第二次迭代开始发生错误 这种现象多是由于在"Run-time Setting"的"Browse Emulation"的设置中, ...
- 一个初学者的辛酸路程-FTP-9
前言 今天,我要描述一个FTP的故事 主要内容 嗯,今天主要以阶梯性的形式来做一个FTP项目. 第一步: 我要实现这么一个功能,一个FTP客户端,1个FTP服务端,2端建立连接以后可以进行通讯. 服务 ...
- 移动端ios电话号码
<meta name="format-detection" content="telephone=no"> <meta http-equiv= ...
- matlab imshow()函数显示白色图像问题
在MATLAB中,我们常使用imshow()函数来显示图像,而此时的图像矩阵可能经过了某种运算.在MATLAB中,为了保证精度,经过了运算的图像矩阵I其数据类型会从uint8型变成double型.如果 ...
- windows 7 & protobuf 3.0 & python 3.5
置顶: 在Python中使用protocol buffers参考指南 http://blog.csdn.net/losophy/article/details/17006573 其实看这篇文章就可以把 ...
- qt rcc 使用
做项目的时候, 最初把图片放到 qrc里面, 使用编译生成的qrc_cpp. 但是编译超慢, 还经常提示"编译器空间不足". 网上很多人说是 中文路径的问题. 可是总是感觉编译器空 ...
- win2008服务器,fastCGI完美设置教程
在WIN2008的IIS7上使用FASTCGI调用PHP-CGI.EXE,默认只有4个进程,这样对于大流量的网站为说,进程数不足带来的进程排队现象十分严重,解决方案如下.32位系统 http://ww ...