POJ
1979 red and black
Platform failed, compiler error, I do not know why T - T.
#include<iostream> #include<string.h> #define MAX 21 using namespace std; int w,h; //Column row int map[MAX][MAX]; bool book[MAX][MAX]={false}; int next[4][2]={{0,1},{1,0},{0,-1},{-1,0}}; int gx,gy; int sum=1; void dfs(int x,int y) { for(int i=0;i<4;i++) { int ax = x + next[i][0]; int ay = y + next[i][1]; if(ax>=0&&ax<=w&&ay>=0&&ay<=h&&map[ax][ay]=='.'&&book[ax][ay]!=true) { sum++; book[ax][ay]=true; dfs(ax,ay); } } return; } int main() { int i,j; cin>>h>>w; while(cin>>h>>w&&w||h) { memset(map,0,sizeof(map)); memset(book,false,sizeof(book)); for(i=0;i<h;i++) { for(j=0;j<w;j++) { cin>>map[i][j]; if(map[i][j]=='@') { gx=i; gy=j; } } } dfs(gx,gy); cout<<sum<<endl; sum=1; } return 0; }
<string.h>
Empty array menmset(b,0,sizeof(b));
We also saw the shortest path today.
Storage map
#define MAXN 60 #define INF 999999 int e[MAXN][MAXN]; int V,E; void prepare() { //Initialization of Adjacency Matrix for(int i=0;i<MAXN;i++) for(int j=0;j<MAXN;j++) if(i==j) e[i][j]=0; else e[i][j]=INF; //input int a,b,c; cin >> V >> E; for(int i=0;i<E;i++) { cin >> a >> b >> c; e[a][b]=c; //The weights from a to b are c } }
I haven't fully understood the algorithm yet, so I won't write it first.
Last.
Last Saturday, I joined ccpc, but it was getting harder and harder for me to do ummmm without any achievement, but I couldn't keep up with the speed at which he became harder and harder. I didn't have any English questions this time, and I didn't play any role. Basically, I sat down for five hours. I really wanted to help me think about a question, but I couldn't understand the real questions. There is no communication with teammates, ummmm does not know what to say, there is nothing to say strange embarrassment, watching others hot, a number of balloons ah ah ah ah, say every time is such a real name paddling really embarrassing. Always feel that there are teammates can depend on how they do, but in fact they still have to work hard. I feel guilty too. I don't try my best to learn. I always feel that I can't finish learning too much. Alas, I don't know how to learn. It's still half a month to watch the provincial competition. Ang, today there is also a flag without typing code. Ha-ha-ha, I have set up too many flags, and the little red flag has not been pulled out everywhere. That's it. I hope fifteen days will be better and better. ^ ^