CCF 201604-4 Games

Source: Internet
Author: User
Tags ming

/*Breadth First search left and right two directions node{x,y,step} to go back to step, not to check the left and right sides meet the conditions on the team. Save the dangerous time with a structure time[i][j]{beg,time} beg=end=0 is safe, noting that the nodes that are already in the queue do not queue again to save time .*/#include<iostream>#include<algorithm>#include<queue>#include<cstdio>using namespacestd;#defineMAXN 101structnode{intx; inty; intstep;};structtnode{intBeg; intend;}; Tnode T[MAXN][MAXN];BOOLBEEN[MAXN][MAXN];intdir[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};intBFsintNintm) {Queue<node>Q;    Node temp; Temp.x=1; TEMP.Y=1; Temp.step=0;    Q.push (temp);  while(!Q.empty ()) {Node T=Q.front (); intnow = t.step,x=t.x,y=T.y; Been[x][y]=false; //cout<<x<< ' <<y<<endl;Q.pop (); if(t.x==n&&t.y==m)returnNow ;  for(intI=0;i<4; i++)        {            if(x+dir[i][0]>0&&y+dir[i][1]>0&&x+dir[i][0]<=n&&y+dir[i][1]<=m) {if(!been[x+dir[i][0]][y+dir[i][1]])                if(! (t[x+dir[i][0]][y+dir[i][1]].beg<=now+1&&t[x+dir[i][0]][y+dir[i][1]].end>=now+1)                    || (t[x+dir[i][0]][y+dir[i][1]].beg==0&&t[x+dir[i][0]][y+dir[i][1]].end==0) {node new_node; New_node.x= x+dir[i][0]; New_node.y= y+dir[i][1]; New_node.step= now+1; BEEN[NEW_NODE.X][NEW_NODE.Y]=true;                Q.push (New_node); }            }        }    }    return 1;}intMain () {intn,m,t,r,c,a,b; scanf ("%d%d%d",&n,&m,&t);  while(t--) {scanf ("%d%d%d%d",&r,&c,&a,&b); T[r][c].beg=A; T[r][c].end=b; }    intAns =BFS (n,m); cout<<ans<<Endl; return 0;}

Question number: 201604-4
Question Name: Game
Time limit: 1.0s
Memory Limit: 256.0MB
Problem Description: Problem description Xiao Ming is playing a computer game, the game is on a nxm square chart, the role of Xiao Ming began to stand in the first row of the first column, the goal is to go to the nth row m column.
There are some squares on the grid is always safe, some in a period of time is dangerous, if the role of xiaoming control to a square when the square is dangerous, then Xiaoming lost the game, if Xiao Ming's role reached the nth row of M column, then xiaoming clearance. The first and nth rows of column m are always safe.
Each unit of time, Xiaoming's role must be up and down about four directions adjacent to one of the squares in one cell.
After many attempts, Xiao Ming mastered the safety and dangerous rules of the grid chart: Every square of dangerous time must be continuous. And, Xiaoming also mastered each square in which time is dangerous.
Now, Xiao Ming want to know, his fastest after a few time units can reach the nth row of the cross-section M. Input format the first line of input contains three integers n, m, T, separated by a space, indicating the number of rows N, the number of columns m, and the number of dangerous squares in the grid chart.
Next T line, 4 integers per line R, C, a, B, indicates that the squares in column C of row R are dangerous between the time of the first and the second, including A and B. At the beginning of the game, the moment is 0. The input data guarantees that r and C are not 1 at the same time, and C is not m when R is N. A square is dangerous only for a period of time (or it does not appear that two lines have the same r and C). Output format output An integer, which indicates that xiaoming can pass through several time units quickly. Input data to ensure that Xiao Ming will be able to pass. Sample Input 3 3 3
2 1 1 1
1 3 2 10
2 2 2 10 Sample Output 6 example shows the 2nd row 1th column Time 1 is dangerous, so the first step must go to row 1th 2nd column.
The second step can go to the 1th row 1th column, the third step to the 2nd row 1th column, followed by the 3rd Line 1th column, 3rd row 2nd column reached the 3rd row 3rd column. Evaluation use case size and conventions the first 30% evaluation cases meet: 0 < N, m≤10,0≤t < 99.
All evaluation cases Meet: 0 < N, m≤100,0≤t < 9999,1≤r≤n,1≤c≤m,0≤a≤b≤100.

CCF 201604-4 Games

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.