2013
11-05

# Dramatic Multiplications

Hassan, helping with his younger brother’s homework, found out that when you multiply 102564 by 4, its right-most digit moves to the left, and the other digits move one position to the right; i.e. 4 * 102564 = 410256. We call a number that has this property when multiplied by n, an n-dramatic number. For instance, 102564 and 128205 are both 4-dramatic. Given two one-digit numbers n and k, the goal is to find the smallest n-dramatic number that its rightmost digit is k.

On the first line of the input, there is an integer t, which is the number of cases that follow. Each test case, is on a line by itself, and contains two integers n and k, where 1 <= n <= 9, and 1 <= k <= 9.

For each test case, output a single integer on a line by itself, which is the smallest n-dramatic number that its rightmost digit is k. If no such number exists, output 0 instead.

2
4 5
2 1

128205
0

//* @author  [email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */
import java.io.IOException;
import java.util.StringTokenizer;
public class Main{
public static void main(String[] args) throws IOException{
int[] number=new int[100];
StringTokenizer token;
for(int j=0;j< count;j++){
boolean shouldPrint=false;
n=Integer.parseInt(token.nextToken());
k=Integer.parseInt(token.nextToken());
if(n>k){
System.out.println(0);
continue;
}
number[99]=k;
carry=0;
lastIndex=99;
for(int i=99;i>=0;i--){
carry=(number[i]*n+carry)/10;
if(carry!=0){

continue;
}
shouldPrint=true;
lastIndex=i;
break;
}

}
if(number[lastIndex]==0) shouldPrint=false;
if(!shouldPrint)System.out.println(0);
else{
for(int i=lastIndex;i<=99;i++)	System.out.print(number[i]);
System.out.println();
}
}
}
}

1. 第一题是不是可以这样想，生了n孩子的家庭等价于n个家庭各生了一个1个孩子，这样最后男女的比例还是1:1

2. for(int i=1; i<=m; i++){
for(int j=1; j<=n; j++){
dp = dp [j-1] + 1;
if(s1.charAt(i-1) == s3.charAt(i+j-1))
dp = dp[i-1] + 1;
if(s2.charAt(j-1) == s3.charAt(i+j-1))
dp = Math.max(dp [j - 1] + 1, dp );
}
}
这里的代码似乎有点问题？ dp(i)(j) = dp(i)(j-1) + 1;这个例子System.out.println(ils.isInterleave("aa","dbbca", "aadbbcb"));返回的应该是false

3. [email protected]