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)…
Description God Wang 是ZUFE的神犇,有一天他想到一种神奇的变换,并且将它命名为GodW变换 对于一个数字n,该变换后的值GodW(n)为,先令X=n 第一步,如果X为个位数,GodW(n)=X,否则执行第二步; 第二步,X的奇数位置的数字之和为a,偶数位置的和为b, X=a*b, 执行第一步; 现在我们有T个询问,对于每个询问输入三个整数数l,r,x 对于每个询问请输出在[l,r]这个闭区间里的数经过该变换后为x的数有多少个 Input 第一行是一个T,表示有T组询问(T…
Problem Link: http://oj.leetcode.com/problems/path-sum-ii/ The basic idea here is same to that of Path Sum. However, since the problem is asking for all possible root-to-leaf paths, so we should use BFS but not DFS. The python code is as follows. # D…
Problem Link: http://oj.leetcode.com/problems/word-ladder-ii/ Basically, this problem is same to Word Ladder I, which uses a double-direction BFS. However, the difference is that we need to keep track of all paths during the double-direction BFS in o…
Problem Link: http://oj.leetcode.com/problems/palindrome-partitioning-ii/ We solve this problem by using Dynamic Programming. Optimal Sub-structure Assume a string S has the palindrome minimum cuts n, and S = W1 + W2 + ... + Wn where Wi is a palindro…
Problem link: http://oj.leetcode.com/problems/single-number-ii/ The problem seems like the Single Number. Suppose we have following (3m+1) numbers in the array A: x0, x1, x1, x1, ..., xm, xm, xm We are asked to find out the value of x0. However we ca…
Problem link: http://oj.leetcode.com/problems/word-break-ii/ This problem is some extension of the word break problem, so the solution is based on the discussion in Word Break. We also use DP to solve the problem. In this solution, A[i] is not a bool…
Description GW 是ZUFE的神犇,有一天他想到一种神奇的变换,并且将它命名为GW变换 对于一个数字n,该变换后的值GW(n)为,先令X=n 第一步,如果X为个位数,GW(n)=X,否则执行第二步; 第二步,X的奇数位置的数字之和为a,偶数位置的和为b, X=a*b, 执行第一步; 现在我们有T个询问,对于每个询问输入三个整数数l,r,x 对于每个询问请输出在[l,r]这个闭区间里的数经过该变换后为x的数有多少个 Input 第一行是一个T,表示有T组询问(T<=1000) 接下来T…
http://oj.leetcode.com/problems/pascals-triangle-ii/ 杨辉三角2,比杨辉三角要求的空间上限制Could you optimize your algorithm to use only O(k) extra space?其实计算当前行,也只用到前一行了.再前面的没有用. class Solution { public: vector<int> getRow(int rowIndex) { // IMPORTANT: Please reset a…
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *detectCycle(ListNode *head) { ListNode *p1, *p2; //p1和p2从链表的第一个节点出发,p1每次移动一…