锘??xml version="1.0" encoding="utf-8" standalone="yes"?>自拍偷自拍亚洲精品第1页,亚洲精品电影在线,亚洲AV第一页国产精品http://m.tkk7.com/spirit/zh-cnTue, 13 May 2025 17:26:48 GMTTue, 13 May 2025 17:26:48 GMT60Google Code Jam - WordPathhttp://m.tkk7.com/spirit/archive/2005/12/19/24645.htmlSpiritSpiritMon, 19 Dec 2005 08:36:00 GMThttp://m.tkk7.com/spirit/archive/2005/12/19/24645.htmlhttp://m.tkk7.com/spirit/comments/24645.htmlhttp://m.tkk7.com/spirit/archive/2005/12/19/24645.html#Feedback0http://m.tkk7.com/spirit/comments/commentRss/24645.htmlhttp://m.tkk7.com/spirit/services/trackbacks/24645.html - Implementation
public class WordPath {    
    
public int countPaths(String[] grid, String find) {
        
int length = grid.length + 2;      
        
        
//convert "grid" from String to char matrix
        char[][] charGrid = new char[length][length];
        
for (int i = 0; i < length; i++) {
            
for (int j = 0; j < length; j++) {
                
if (i == 0 || i == length - 1 || j == 0 || j == length - 1)
                    charGrid[i][j] 
= '0';
                
else
                    charGrid[i][j] 
= grid[i - 1].charAt(j - 1);
            }
        }
        
        
//convert "find" from String to char array
        char[] charFind = new char[find.length()];
        
for (int k = 0; k < find.length(); k++)
            charFind[k] 
= find.charAt(k);

        
//use three dimensions "degree" to hold the in-degree of the vertex of graph
        int[][][] degree = new int[length][length][find.length()];        

        
// k=0
        for (int i = 0; i < length; i++)
            
for (int j = 0; j < length; j++) {
                degree[i][j][
0= ((charGrid[i][j] == charFind[0]) ? 1 : 0);
            }
        
        
// fill the degree 
        for (int k = 1; k < find.length(); k++) {
            
for (int i = 0; i < length; i++)
                
for (int j = 0; j < length; j++) {
                    
if (charGrid[i][j] != charFind[k])
                        degree[i][j][k] 
= 0;
                    
else {
                        degree[i][j][k] 
= degree[i - 1][j - 1][k - 1+ degree[i - 1][j][k - 1]
                                
+ degree[i - 1][j + 1][k - 1+ degree[i + 1][j - 1][k - 1]
                                
+ degree[i + 1][j][k - 1+ degree[i + 1][j + 1][k - 1]
                                
+ degree[i][j - 1][k - 1+ degree[i][j + 1][k - 1];

                    }

                }
        }
        
        
//calculate the sum
        int sum = 0;
        
for (int i = 0; i < length; i++)
            
for (int j = 0; j < length; j++) {
                sum 
+= degree[i][j][find.length() - 1];
                
if (sum > 1000000000) {
                    
return -1;
                }
            }
        
return sum;
    }
}

- TestCase
public class WordPathTest extends TestCase {
    
public void testCountPaths() {
        WordPath wordPath 
= new WordPath();
        assertEquals(
2, wordPath.countPaths(new String[] { "ABC""FED""GAI" }, "ABCDEA"));
        assertEquals(
0, wordPath.countPaths(new String[] { "ABC""DEF""GHI" }, "ABCD"));
        assertEquals(
108, wordPath.countPaths(new String[] { "AA""AA" }, "AAAA"));
        assertEquals(
56448, wordPath.countPaths(new String[] { "ABABA""BABAB""ABABA""BABAB""ABABA" },
                
"ABABABBA"));
        assertEquals(
-1, wordPath.countPaths(new String[] { "AAAAA""AAAAA""AAAAA""AAAAA""AAAAA" },
                
"AAAAAAAAAAA"));
        assertEquals(
0, wordPath.countPaths(new String[] { "AB""CD" }, "AA"));
    }
}

This testcase finished after 0.015 seconds on my pc.

http://forum.javaeye.com/viewtopic.php?p=106316#106316


Spirit 2005-12-19 16:36 鍙戣〃璇勮
]]>
Google Code Jam - SkipStones鐨勪竴縐嶉掑綊綆楁硶http://m.tkk7.com/spirit/archive/2005/12/15/24018.htmlSpiritSpiritThu, 15 Dec 2005 05:29:00 GMThttp://m.tkk7.com/spirit/archive/2005/12/15/24018.htmlhttp://m.tkk7.com/spirit/comments/24018.htmlhttp://m.tkk7.com/spirit/archive/2005/12/15/24018.html#Feedback1http://m.tkk7.com/spirit/comments/commentRss/24018.htmlhttp://m.tkk7.com/spirit/services/trackbacks/24018.htmlpublic class SkipStones {
    
private String water = "X";

    
public int maxDistance(String water) {
        
this.water = water;
        
int max = 0;
        
int sum = 0;
        
for (int initial = 1; initial < water.length() + 1; initial++) {
            sum 
= bounce(0, initial);
            max 
= (sum > max ? sum : max);
        }
        
return max;
    }

    
private int bounce(int startDistance, int bounceDistance) {
        
if (bounceDistance == 0)
            
return startDistance;

        
if ((startDistance + bounceDistance) > water.length())
            
return -1;

        
if (water.charAt(startDistance + bounceDistance - 1== 'X')
            
return startDistance;

        
return bounce(startDistance + bounceDistance, bounceDistance / 2);
    }

    
public static void main(String[] args) {
        SkipStones skipStones 
= new SkipStones();
        System.out.println(skipStones.maxDistance(args[
0]));
    }
}



Spirit 2005-12-15 13:29 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 日本红怡院亚洲红怡院最新 | 中文字幕精品亚洲无线码一区 | 青娱乐在线视频免费观看| 日韩精品成人无码专区免费 | 成人免费看片又大又黄| 亚洲国产成人99精品激情在线| 国内精品免费麻豆网站91麻豆| 亚洲精品日韩中文字幕久久久| 久久精品人成免费| 亚洲AV无码国产精品色| 无码少妇一区二区浪潮免费| 亚洲成人激情小说| 四虎1515hm免费国产| 春意影院午夜爽爽爽免费| 亚洲精品无码专区久久久| 999任你躁在线精品免费不卡| 亚洲另类图片另类电影| 成年午夜视频免费观看视频| 亚洲AV日韩综合一区| www.亚洲精品| 久久久久久久久久国产精品免费 | 国产AV无码专区亚洲AVJULIA| 一级毛片免费播放| 亚洲av乱码一区二区三区| 国产成人3p视频免费观看| 国产免费久久久久久无码| 国产亚洲成av片在线观看| 日本免费网站视频www区| 亚洲妇女无套内射精| 久久精品亚洲乱码伦伦中文| 99热这里只有精品免费播放| 亚洲丁香婷婷综合久久| 亚洲婷婷国产精品电影人久久| 成人电影在线免费观看| 亚洲AV无码乱码麻豆精品国产| www亚洲精品少妇裸乳一区二区 | 亚洲色欲色欲综合网站| 在线视频免费观看高清| 国产va免费观看| 亚洲人成网站日本片| 免费国产高清视频|