hdu dfs 물 문제

12518 단어 수색 하 다.
hdu 1181 、 1241 、 1312 、 4707
오 랜 만 에 문 제 를 풀 었 는데 겨울방학 에 집에 인터넷 이 없어 서 정말 불쾌 하 다.이틀 동안 DFS 주 제 를 풀기 로 결정 하여 인터넷 에서 몇 개의 물 문 제 를 찾 아 보 았 다.
1181:
변형 수업
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 11647    Accepted Submission(s): 4322
Problem Description
어....................................................................................... 
해 리 는 이미 그 가 할 수 있 는 모든 주문 을 하나의 표 로 만 들 었 다. 그 는 너 에 게 선생님 의 숙제 를 완성 할 수 있 는 지 계산 해 달라 고 하고 B (ball) 를 M (Mouse) 으로 만 들 었 다. 만약 에 그 가 완성 하지 못 하면 그 는 Hermione 에 게 가르침 을 청 하고 열심히 공부 하 는 이 치 를 들 어야 한 다 는 것 을 알 고 있다.
 
Input
테스트 데이터 가 여러 그룹 입 니 다.각 조 에는 여러 줄 이 있 고, 줄 마다 한 단어 가 있 으 며, 소문 자 만 포함 되 어 있 으 며, 해리 가 할 수 있 는 모든 주문 이다. 숫자 0 은 한 조 의 입력 이 끝 났 음 을 나타 낸다.
 
Output
해리 가 그의 숙제 를 완성 할 수 있다 면 "Yes."를 출력 하고 그렇지 않 으 면 "No."를 출력 합 니 다. (마침 표를 무시 하지 마 세 요)
 
Sample Input
 
   
so soon river goes them got moon begin big 0
 

Sample Output
 
   
Yes.
Hint
Hint
Harry 可以念这个咒语:"big-got-them".
 

#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
vector in;
string s;
int vis[100000];
int flag,cnt;
char begain,_end;
void dfs(int cur)
{
    if(flag||cur>=cnt)
        return ;
    for(int i=0;i>s)//             我之前是这样写的,但是会超时,不知道为什么......while(1)
    {                           //                                              {  
    begain='b',_end='m';        //                                                  cin>>s;
    flag=0,cnt=0;               //                                                    ...
    in.clear();                 //                                                    ...
    while(s!="0")               //                                                    ...
    {                           //
        in.push_back(s);        //
        vis[cnt++]=0;          //
        cin>>s;               //
    }                         //
    dfs(0);                      //
    cout<

1241:
Oil Deposits
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9570    Accepted Submission(s): 5612
Problem Description
The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It then analyzes each plot separately, using sensing equipment to determine whether or not the plot contains oil. A plot containing oil is called a pocket. If two pockets are adjacent, then they are part of the same oil deposit. Oil deposits can be quite large and may contain numerous pockets. Your job is to determine how many different oil deposits are contained in a grid. 
 
Input
The input file contains one or more grids. Each grid begins with a line containing m and n, the number of rows and columns in the grid, separated by a single space. If m = 0 it signals the end of the input; otherwise 1 <= m <= 100 and 1 <= n <= 100. Following this are m lines of n characters each (not counting the end-of-line characters). Each character corresponds to one plot, and is either `*', representing the absence of oil, or `@', representing an oil pocket.
 
Output
For each grid, output the number of distinct oil deposits. Two different pockets are part of the same oil deposit if they are adjacent horizontally, vertically, or diagonally. An oil deposit will not contain more than 100 pockets.
 
Sample Input
 
   
1 1 * 3 5 *@*@* **@** *@*@* 1 8 @@****@* 5 5 ****@ *@@*@ *@**@ @@@*@ @@**@ 0 0
 

Sample Output
 
   
0 1 2 2
 

#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
char a[110][110];
int vis[110][110];
int m,n;
void dfs(int i,int j)
{
    if(i>=m||i<0||j>=n||j<0||a[i][j]=='*'||vis[i][j])
        return ;
    vis[i][j]=1;
    dfs(i-1,j-1);dfs(i-1,j);dfs(i-1,j+1);
    dfs(i,j-1);             dfs(i,j+1);
    dfs(i+1,j-1);dfs(i+1,j);dfs(i+1,j+1);
}
int main()
{
    while(scanf("%d%d",&m,&n)&&m)
    {
        for(int i=0;i

1312:
Red and Black
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7822    Accepted Submission(s): 4908
Problem Description
There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on black tiles.
Write a program to count the number of black tiles which he can reach by repeating the moves described above. 
 
Input
The input consists of multiple data sets. A data set starts with a line containing two positive integers W and H; W and H are the numbers of tiles in the x- and y- directions, respectively. W and H are not more than 20.
There are H more lines in the data set, each of which includes W characters. Each character represents the color of a tile as follows.
'.' - a black tile 
'#' - a red tile 
'@' - a man on a black tile(appears exactly once in a data set) 
 
Output
For each data set, your program should output a line which contains the number of tiles he can reach from the initial tile (including itself). 
 
Sample Input
 
   
6 9 ....#. .....# ...... ...... ...... ...... ...... #@...# .#..#. 11 9 .#......... .#.#######. .#.#.....#. .#.#.###.#. .#.#..@#.#. .#.#####.#. .#.......#. .#########. ........... 11 6 ..#..#..#.. ..#..#..#.. ..#..#..### ..#..#..#@. ..#..#..#.. ..#..#..#.. 7 7 ..#.#.. ..#.#.. ###.### ...@... ###.### ..#.#.. ..#.#.. 0 0
 

Sample Output
 
   
45 59 6 13
 
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int w,h;
char a[25][25];
int cnt;
int vis[25][25];
void dfs(int i,int j)
{
    if(i<0||i>=w||j<0||j>=h||a[i][j]=='#'||vis[i][j])
        return ;
    cnt++;
    vis[i][j]=1;
                dfs(i-1,j);
    dfs(i,j-1);            dfs(i,j+1);
                dfs(i+1,j);
}
int main()
{
    while(scanf("%d%d",&h,&w)&&(w||h))
    {
        memset(vis,0,sizeof(vis));
        for(int i=0;i

4707:
Pet
Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 920    Accepted Submission(s): 462
Problem Description
One day, Lin Ji wake up in the morning and found that his pethamster escaped. He searched in the room but didn’t find the hamster. He tried to use some cheese to trap the hamster. He put the cheese trap in his room and waited for three days. Nothing but cockroaches was caught. He got the map of the school and foundthat there is no cyclic path and every location in the school can be reached from his room. The trap’s manual mention that the pet will always come back if it still in somewhere nearer than distance D. Your task is to help Lin Ji to find out how many possible locations the hamster may found given the map of the school. Assume that the hamster is still hiding in somewhere in the school and distance between each adjacent locations is always one distance unit.
 
Input
The input contains multiple test cases. Thefirst line is a positive integer T (0
 
Output
For each test case, outputin a single line the number of possible locations in the school the hamster may be found.
 
Sample Input
 
    
1 10 2 0 1 0 2 0 3 1 4 1 5 2 6 3 7 4 8 6 9
 

Sample Output
 
    
2
 

#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define maxn 100000+10
int n,d;
vectorm[maxn];
int vis[maxn];
int cnt;
void dfs(int num,int e)
{
    if(e>d)return ;
    vis[num]=1;
    cnt++;
    int len=m[num].size();
    for(int i=0;i
M5 Atom을 UIFlow에 기록한 후 WiFi를 통해 UIFlow에 연결된 모드로 돌아가는 방법
django filters TypeError __init__() got an unexpected keyword argument 'lookup_type'

좋은 웹페이지 즐겨찾기