Блог пользователя thanhthuy4u

Автор thanhthuy4u, история, 7 лет назад, По-английски

http://codeforces.me/contest/723/submission/29104913 D. Lakes in Berland.

include

include

include

include

include<string.h>

using namespace std;

define max 100

char a[max][max]; int n,m,dem=0,flag=0; bool visited[max][max]; int dx[] = {0,0,-1,1}; int dy[] = {-1,1,0,0}; int option(int x, int y) { return x>y; } struct POINT { int x,y; }; int DFS(POINT src) { dem=0; stacks; visited[src.x][src.y]=true; s.push(src); while(!s.empty()) { POINT w; src=s.top(); s.pop(); for(int i=0;i<4;i++) { int x,y; x=src.x+dx[i]; y=src.y+dy[i]; if(visited[x][y]==false&&a[x][y]=='.'&&x>=0&&x<n&&y>=0&&y<m) { if(flag==1) { a[x][y]='*'; } visited[x][y]=true; w.x=x;w.y=y; s.push(w); dem++; } } } return dem; }

int main() { //freopen("input.txt","rt",stdin); int k,d=0,oo[max],ooo[max],dd,ans=0,kq=0;; POINT p; POINT o[max]; cin>>n>>m>>k; for(int i=0;i<n;i++) for(int j=0;j<m;j++) visited[i][j]=false; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { cin>>a[i][j]; } } for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(visited[i][j]==false&&a[i][j]=='.'&&(i==0||i==n-1||j==0||j==m-1)) { p.x=i;p.y=j; DFS(p); } } } for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(a[i][j]=='.'&&visited[i][j]==false) { p.x=i;p.y=j; DFS(p); oo[d]=dem+1; ooo[d]=dem+1; o[d++]=p; } } } flag=1; dd=d; sort(ooo,ooo+max,option); for(int i=0;i<n;i++) for(int j=0;j<m;j++) visited[i][j]=false; for(int i=dd-1;i>=0;i--) { for(int j=0;j<d;j++) { if(oo[j]==ooo[i]) { a[o[j].x][o[j].y]='*'; kq++; kq+=DFS(o[j]); ans++; oo[i]=0; break; } } if(d-k==ans) { cout<<kq<<"\n"; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { cout<<a[i][j]; } cout<<"\n"; } break; } } return 0; }

  • Проголосовать: нравится
  • -17
  • Проголосовать: не нравится

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

If you really want help you have to write your code clean and readable.

I'm sure now one will waste his/her time to read this mess!

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    it's fine, you can just click the submission link if you really wanted to help.

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Here's a bug in your code, you choose to sort ooo till max element while you should only sort till the dth-element.

so replace sort(ooo,ooo+max,option);

with sort(ooo,ooo+d,option);

and that should fix your first bug, though there are more bugs and you will reach WA on test 3. Let me know if you need more help debugging, I do recommend that you try debugging on your own as it is an important process to go through.

I also recommend better naming if you want to get help from others. I took more than the usual time to debug this as it is really difficult to understand your program with such naming.