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 ...
随机推荐
- ssh配置导致Ansible并发失败
Ansible并发失败原因, fork=100. 执行playbook时候没有并发 vim /usr/lib/python2.7/site-packages/ansible/runner/conne ...
- HDU 4998 Rotate (计算几何)
HDU 4998 Rotate (计算几何) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=4998 Description Noting is more ...
- Shell学习笔记 ——第二天
1.显示日期 date | cal cal 2010 cal 2 2010 2.改变文件拥有者 chown 3.改变文件权限 chmod 4.显示当前目录 pwd 5.查看文件尾部内容,并 ...
- 当今Web应用的主要技术
WWW是World Wide Web的简称,缩写为W3C,称为万维网,也简称为Web.目前Internet已经普及到整个社会,其中Web应用已经称为Internet上最受欢迎的应用之一,正是由于它的出 ...
- DIV+CSS 让同一行的图片和文字对齐
在div+css布局中,如果一行(或一个DIV)内容中有图片和文字的话,图片和文字往往会一个在上一个在下,这是一个新手都会遇到问题,我的解决方法有三: 1.添加CSS属性:vertical-align ...
- checkbox:全选与反全选
$(document).ready(function () { //全选checkbox $("#selectAll").click(function () { var check ...
- 我喜欢的两个js类实现方式
闭包实现 变量是不会变的:) var myApplication = function(){ var name = 'Yuri'; var age = '34'; var status = 'sing ...
- Space Shooter
项目:https://pan.baidu.com/s/1jIDe2H4 using UnityEngine; using System.Collections; namespace VoidGame ...
- C#动态编程
class Program { static void Main(string[] args) { Test(); } public static void Test() { //声明代码的部分 Co ...
- 【转】关于spring集合对象的补充
<span style="font-size:18px;">关于spring集合对象的补充 spring2.0中对集合对象有了改进,新增了一个<util>标 ...