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 ...
随机推荐
- sap 设备cnsapwin不支持页格式*****
SAP SMARTFORMS 打印 CNSAPWIN 不支持页格式 解决办法: 在smartforms里的表格属性虽然定义了要打印的页格式 ZUNIA5 ,但是打印时会提示错误:" CNSA ...
- md5证书在window2012不能访问
之前在window 2008使用makecert的产生的证书,部署到window 2012后,发现只有IE能访问,但是Firefox和chrome都不行.Firefox可以使用about:config ...
- 在SpringMVC的controller控制器中使用Servlet原生的API
只需要在控制器的方法里添加相应的Servlet 参数即可! 支持以下参数: 新建一个controller类,部分代码如下:(省略xml配置文件) @RequestMapping("servl ...
- Windows下WordPress搭建博客过程
搭建环境:Win7 + XAMPP5.5 + wordpress4.5.1 官网下载安装包,解压,拷贝到网站根目录(D:\IT\XAMPP5.5\htdocs\),重命名为blog(随意) 创建数据库 ...
- JavaScript详解
JavaScript可以说是web开发中必备的一种技术.它具有灵活,简单,高效等特点.这次DRP中大量的用到了js,让自己对js有了更深的了解.看完这个以后还回去看了一下牛腩的js视频.把以前没看的看 ...
- Simple python reverse shell
import base64,sys; import socket,struct s=socket.socket(2,socket.SOCK_STREAM) s.connect(('Attack's I ...
- 后台gird表单按钮操作
1.$this->_removeButton('reset');#########################################删除重置这个按钮.2.$this->_ad ...
- 《JS权威指南学习总结--7.10 数组类型》
内容要点: 一.数组类型 判断它是否为数组通常非常有用.在ES5中,可以使用Array.isArray()函数来做这件事情: Array.isArray([]); //=>true Array. ...
- ubuntu下pip install mysql-python 失败的解决方案
ubuntu连接mysql 需要安装mysql-python 出现can not find mysql-config 文件错误 先安装 sudo apt-get install libmysqld-d ...
- mysql去重的最方便的两种方法
参考资料:http://blog.csdn.net/guocuifang655/article/details/3993612 方法一: 在使用mysql时,有时需要查询出某个字段不重复的记录,虽然m ...