亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? gooleanswer.cpp

?? 一個google的考試題
?? CPP
字號:
// GooleAnswer.cpp : Defines the entry point for the console application.
//
/*
Problem Statement
????
You are given a String[] grid representing a rectangular grid of letters. You are also given a String find, a word you are to find within the grid. The starting point may be anywhere in the grid. The path may move up, down, left, right, or diagonally from one letter to the next, and may use letters in the grid more than once, but you may not stay on the same cell twice in a row (see example 6 for clarification).
You are to return an int indicating the number of ways find can be found within the grid. If the result is more than 1,000,000,000, return -1.
Definition
????
Class:
WordPath
Method:
countPaths
Parameters:
vector <string>, string
Returns:
int
Method signature:
int countPaths(vector <string> grid, string find)
(be sure your method is public)

Constraints
-
grid will contain between 1 and 50 elements, inclusive.
-
Each element of grid will contain between 1 and 50 uppercase ('A'-'Z') letters, inclusive.
-
Each element of grid will contain the same number of characters.
-
find will contain between 1 and 50 uppercase ('A'-'Z') letters, inclusive.
Examples
0)

????
{"ABC",
 "FED",
 "GHI"}
"ABCDEFGHI"
Returns: 1
There is only one way to trace this path. Each letter is used exactly once.
1)

????
{"ABC",
 "FED",
 "GAI"}
"ABCDEA"
Returns: 2
Once we get to the 'E', we can choose one of two directions for the final 'A'.
2)

????
{"ABC",
 "DEF",
 "GHI"}
"ABCD"
Returns: 0
We can trace a path for "ABC", but there's no way to complete a path to the letter 'D'.
3)

????
{"AA",
 "AA"}
"AAAA"
Returns: 108
We can start from any of the four locations. From each location, we can then move in any of the three possible directions for our second letter, and again for the third and fourth letter. 4 * 3 * 3 * 3 = 108.
4)

????
{"ABABA",
 "BABAB",
 "ABABA",
 "BABAB",
 "ABABA"}
"ABABABBA"
Returns: 56448
There are a lot of ways to trace this path.
5)

????
{"AAAAA",
 "AAAAA",
 "AAAAA",
 "AAAAA",
 "AAAAA"}
"AAAAAAAAAAA"
Returns: -1
There are well over 1,000,000,000 paths that can be traced.
6)

????
{"AB",
 "CD"}
"AA"
Returns: 0
Since we can't stay on the same cell, we can't trace the path at all.

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
*/
#include <string>
#include <vector>
#include <iostream>
#include <stdio.h>
using namespace std; //Required for TopCoder gcc compiler

//****************************************************************
//類名:WordPath
//作者:roc(txqc4@sohu.com)
//日期:2005-12-13
//用途: 本代碼為實現上述競賽題所作。
//注意事項:如欲轉載,請保持本段說明。
//****************************************************************
class WordPath
{
    typedef struct POINTtag{
        int x;
        int y;
        int count;
    }POS;
    typedef vector<POS> VETPOS;
    
public:
    
    int countPaths(vector <string> grid, string find)
    {
        int findStrLen = find.length();
        int gridSize   = grid.size();
        int gridStrLen = grid[0].length();
        
        vector <VETPOS> vec(findStrLen);
        
        int i,j,k;
        
        // 遍歷grid中的每一個字符
        for ( i = 0; i < gridSize; i ++)
        {
            for ( j= 0; j < gridStrLen; j++)
            {
                for ( k=0; k<findStrLen; k++)
                {
                    char ch =  find.at(k);
                    //如果與find中位置k的字符相等,則將相應的grid中的位置坐標保存到相應的向量中去
                    if ( ch == grid[i].at(j) )
                    {
                        POS ps;
                        ps.x =j;
                        ps.y = i;
                        
                        //位置向量0中所有坐標的初始值為1,而其他位置向量中坐標的這個字段總會被指零后才計算
                        ps.count = 1;
                        vec[k].push_back(ps);
                    }
                }
            }
        }
        
        // 如果有find中的字符在grid中不存在則返回0
        for ( k=0; k<findStrLen; k++)
        {
            if ( vec[k].size() == 0 )
                return 0;
        }
                  
        VETPOS midVes;//保存當前位置向量中符合條件點的臨時向量
        
        // 遍歷從位置1開始的位置向量
        for ( i = 1; i < findStrLen ; i ++)
        {
            midVes.clear();
            
            //遍歷當前位置向量中的所有位置坐標
            for ( j=0; j < vec[i].size(); j++)
            {
                POS cur = vec[i][j];
                
                //如果當前點與前個向量vec[i-1]中的點可以移動到達,則保存這個點到臨時變量midVes中去
                if (  pathCount(cur,vec[i-1]))
                {
                    midVes.push_back(cur);
                }
            }
            //清空原來的向量
            vec[i].clear();
            
            //如果midVes中有符合條件的點存在,則將它保存到原來的位置向量中去
            //否則返回0
            if ( midVes.size() >0 )
            {
                vec[i] = midVes;
            }
            else
            {
                return 0;
            }
        }
        
        // 統計保存在最后位置向量中的點的count值
        int count = 0;
        for ( j=0; j < vec[findStrLen-1].size(); j++)
        {
            POS cur = vec[findStrLen-1][j];
            count += cur.count;
            if (count > 1000000000 )
                return -1;
        }
        return count;
    }
    
    int pathCount(POS &ps, VETPOS& pre)
    {
        //初始為0
        ps.count = 0;
        int i;
        
        //遍歷pre中的每個位置坐標
        for ( i=0; i < pre.size(); i++)
        {
            //計算cur與pre[i]的縱橫坐標差的絕對值
            int xAbs = ps.x - pre[i].x;
            int yAbs = ps.y - pre[i].y;
            
            xAbs = xAbs<0?-xAbs:xAbs;
            yAbs = yAbs<0?-yAbs:yAbs;
           
            //判斷是否可以移動到達
            if (( xAbs == 1 && yAbs < 2 ) ||
                ( yAbs == 1 && xAbs < 2 ) )
            {
                ps.count += pre[i].count;//統計通過ps點的可能路徑數。
            }
        }
        
        return ps.count;
    }
};


//以下為測試代碼
void Load(vector <string> &grid, string &find)
{
    string array[]={"ABC",
        "FED",
        "GHI"};
    
    for (int i=0; i < sizeof(array)/sizeof(string); i++)
    {
        grid.push_back(array[i]);
        cout<<array[i]<<endl;
    }
    find = "ABCDEFGHI";
    cout <<find<<endl;
}

void Load1(vector <string> &grid, string &find)
{
    string array[]={"ABC",
 "FED",
 "GAI"};
    
    for (int i=0; i < sizeof(array)/sizeof(string); i++)
    {
        grid.push_back(array[i]);
        cout<<array[i]<<endl;
    }
    find = "ABCDEA";
    cout <<find<<endl;
}
void Load2(vector <string> &grid, string &find)
{
    string array[]={"ABABA",
 "BABAB",
 "ABABA",
 "BABAB",
 "ABABA"};
    
    for (int i=0; i < sizeof(array)/sizeof(string); i++)
    {
        grid.push_back(array[i]);
        cout<<array[i]<<endl;
    }
    find = "ABABABBA";
    cout <<find<<endl;
}
void Load3(vector <string> &grid, string &find)
{
    string array[]={"AA",
 "AA"};
    
    for (int i=0; i < sizeof(array)/sizeof(string); i++)
    {
        grid.push_back(array[i]);
        cout<<array[i]<<endl;
    }
    find = "AAAA";
    cout <<find<<endl;
}


void Load4(vector <string> &grid, string &find)
{
    string array[]={"AAAAA",
 "AAAAA",
 "AAAAA",
 "AAAAA",
 "AAAAA"};
    
    for (int i=0; i < sizeof(array)/sizeof(string); i++)
    {
        grid.push_back(array[i]);
        cout<<array[i]<<endl;
    }
    find ="AAAAAAAAAAA";
    cout <<find<<endl;
}
int main(int argc, char* argv[])
{
    WordPath word;
    vector <string> grid;
    string find;

    void(*LoadFn[])(vector <string> &grid, string &find)={
    Load,Load1,Load2,Load3,Load4};
    
    for ( int i = 0; i < sizeof(LoadFn)/sizeof(LoadFn[0]); i ++)
    {
        grid.clear();
        LoadFn[i](grid,  find);
        cout<<word.countPaths(grid,  find)<<endl;

    }

	return 0;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久精品国产亚洲aⅴ | 91毛片在线观看| 国产午夜精品一区二区| 国产精品一区在线观看你懂的| 久久精品无码一区二区三区| 国产成人av影院| 亚洲欧美视频在线观看视频| 欧美在线高清视频| 蜜桃视频在线一区| 国产午夜精品福利| av一区二区三区四区| 亚洲制服丝袜一区| 日韩一级欧美一级| 不卡影院免费观看| 性做久久久久久久免费看| 欧美v日韩v国产v| 91丝袜国产在线播放| 日产精品久久久久久久性色| 久久久午夜电影| 色婷婷亚洲精品| 奇米影视7777精品一区二区| 国产精品视频在线看| 欧美日本一区二区在线观看| 国产在线看一区| 亚洲精品免费在线观看| 欧美va亚洲va香蕉在线| 97se狠狠狠综合亚洲狠狠| 日韩av在线播放中文字幕| 日本一区二区动态图| 欧美精选一区二区| 成人黄色大片在线观看| 日本v片在线高清不卡在线观看| 久久这里只有精品6| 在线观看日韩av先锋影音电影院| 韩国一区二区视频| 午夜精品福利视频网站| 国产欧美日韩精品在线| 欧美精品久久天天躁| 99精品在线免费| 激情图片小说一区| 亚洲综合一区二区三区| 中日韩av电影| 精品国产乱码久久久久久免费| 日本久久电影网| 岛国一区二区三区| 美腿丝袜在线亚洲一区| 亚洲午夜精品久久久久久久久| 国产午夜三级一区二区三| 日韩三级伦理片妻子的秘密按摩| 91福利在线播放| 波波电影院一区二区三区| 久88久久88久久久| 丝袜美腿亚洲一区二区图片| 亚洲精品日韩综合观看成人91| 国产欧美日韩激情| 久久久久久亚洲综合影院红桃 | 欧美久久久一区| 色综合一个色综合| 波多野结衣在线一区| 国产一区二区三区免费播放| 日本成人中文字幕| 五月天激情综合网| 丝袜a∨在线一区二区三区不卡| 亚洲少妇30p| 综合色中文字幕| 亚洲欧美一区二区视频| 欧美极品aⅴ影院| 国产欧美一区二区精品婷婷| 久久日韩粉嫩一区二区三区| 2014亚洲片线观看视频免费| 日韩精品一区二区三区视频在线观看| 欧美精品自拍偷拍| 欧美一区二区精美| 精品国产一区二区三区久久久蜜月 | 2024国产精品视频| 日韩欧美一区在线| 日韩女优电影在线观看| 日韩午夜av电影| 日韩精品一区在线观看| 精品成人免费观看| 国产调教视频一区| 欧美激情一区三区| 国产精品欧美一级免费| 1区2区3区欧美| 一区二区免费在线| 亚洲午夜免费福利视频| 午夜视频一区二区| 蜜臀av性久久久久蜜臀aⅴ四虎| 蜜桃一区二区三区在线| 国产在线视频不卡二| 成人网在线免费视频| 91丨porny丨在线| 欧美日韩精品一区二区天天拍小说| 在线观看www91| 7777精品伊人久久久大香线蕉| 欧美一二三区精品| 国产亚洲成aⅴ人片在线观看| 国产精品欧美久久久久一区二区| 一区二区三区四区乱视频| 五月天欧美精品| 国产麻豆一精品一av一免费| 91美女视频网站| 欧美精品日韩精品| 久久久久久久久久久久久夜| 中文字幕一区二区三区视频| 亚洲国产一区二区在线播放| 久久er99精品| 99精品久久99久久久久| 欧美一区日本一区韩国一区| 国产日韩欧美不卡| 亚洲自拍偷拍网站| 国产在线不卡一区| 欧美在线综合视频| 欧美va亚洲va| 一区二区三区毛片| 国内精品写真在线观看| 91在线国产福利| 日韩欧美国产精品一区| 亚洲欧洲在线观看av| 五月天中文字幕一区二区| 丰满少妇久久久久久久| 欧美久久久久免费| 亚洲欧洲日韩av| 久久成人羞羞网站| 欧美影视一区在线| 久久久久久日产精品| 日韩精品亚洲专区| 色综合久久久久综合| 国产日韩av一区二区| 日韩成人免费在线| 91色.com| 国产精品国产三级国产普通话99| 久久国产综合精品| 欧美日韩和欧美的一区二区| 国产精品久久久久7777按摩| 久久精品99国产精品| 欧美日韩一区国产| 亚洲美女视频在线| 国产精品一区在线观看你懂的| 91精品国产高清一区二区三区蜜臀| 国产精品久久三| 国产一区二区福利| 欧美刺激脚交jootjob| 亚洲一区在线免费观看| 成人av在线资源网| 久久影院视频免费| 久色婷婷小香蕉久久| 欧美日本在线视频| 亚洲成a人片在线不卡一二三区| 春色校园综合激情亚洲| 国产亚洲一区二区三区四区| 七七婷婷婷婷精品国产| 欧美精品成人一区二区三区四区| 亚洲精品日产精品乱码不卡| 99久久综合狠狠综合久久| 国产午夜精品美女毛片视频| 国产一区 二区 三区一级| 欧美一区二区久久| 免费成人结看片| 欧美精品三级在线观看| 天堂成人国产精品一区| 欧美高清视频不卡网| 肉色丝袜一区二区| 日韩一级完整毛片| 久久精品国产一区二区三 | 亚洲成精国产精品女| 欧美午夜精品免费| 亚洲一区二区3| 91黄色免费观看| 亚洲aⅴ怡春院| 3d成人动漫网站| 老司机免费视频一区二区| 日韩精品一区二区三区蜜臀| 国产一区二区调教| 国产日韩欧美制服另类| 波多野结衣在线一区| 亚洲伦在线观看| 欧美性videosxxxxx| 亚洲bdsm女犯bdsm网站| 日韩一区二区三区视频在线| 国产在线播放一区三区四| 国产免费久久精品| 色综合久久综合中文综合网| 亚洲韩国一区二区三区| 91 com成人网| 国产乱子伦视频一区二区三区| 亚洲国产成人在线| 欧美性受xxxx| 久久福利视频一区二区| 日本一区二区三区国色天香 | 91精品国产综合久久久蜜臀粉嫩 | 天天影视涩香欲综合网| 欧美成人a∨高清免费观看| 国产原创一区二区| 亚洲欧美偷拍卡通变态| 777欧美精品| 高清国产午夜精品久久久久久| 亚洲视频免费观看| 欧美一区二区视频观看视频| 国产一区二区福利视频|