zoukankan      html  css  js  c++  java
  • usaco[2018DEC]

    sliver

    Each of his M cows has two favorite pastures. Some of his cows have a dietary restriction that they should only eat one type of grass consistently --- Farmer John therefore wants to make sure the same type of grass is planted in the two favorite fields of any such cow. Other cows have a very different dietary restriction, requiring them to eat different types of grass. For those cows, Farmer John of course wants to make sure their two favorite fields contain different grass types.  

    T2

    2.23

    T3

     1 /*
     2 ID:Li Zhou
     3 LANG: C++
     4 TASK: test
     5 */
     6 #include<bits/stdc++.h>
     7 using namespace std;
     8 const int dx[5]={0,0,0,1,-1};
     9 const int dy[5]={0,1,-1,0,0};
    10 int n,k,cnt,az;
    11 bool vis[200][11];
    12 char a[200][11];
    13 int b[200][11];
    14 int bfs(int x,int y,int cal){
    15     if(vis[x][y])return 0;
    16     int ans=0;
    17     if(x<=0||x>n||b[x][y]!=cal)return 0;
    18     if(b[x][y]==0)return 0;
    19     if(y<=0||y>10)return 0;
    20     vis[x][y]=1;
    21     for(int i=1;i<=4;i++){
    22     int azx=x+dx[i];
    23     int azy=y+dy[i];
    24     ans+=bfs(azx,azy,cal);
    25     }
    26     return ans+1;
    27 }
    28 void del(int x,int y,int cal){
    29     if(b[x][y]==cal&&x>=0&&x<=n&&y>=0&&y<=10){
    30     b[x][y]=0;
    31     for(int i=1;i<=4;i++){
    32     int azx=x+dx[i];
    33     int azy=y+dy[i];
    34     del(azx,azy,cal);
    35     }
    36     }
    37 }
    38 void work(){
    39     az=1;
    40     while(az){
    41     az=0;
    42     memset(vis,0,sizeof(vis));
    43     for(int h=1;h<=n;h++){
    44       if(az)break;
    45       for(int j=1;j<=10;j++){
    46           if(az)break;
    47           bool t1,t2;
    48           t2=vis[h][j];
    49           t1=b[h][j]==0;
    50       if(t1)continue;
    51       if(t2)continue;
    52       cnt=bfs(h,j,b[h][j]);
    53       if(cnt>=k){
    54           del(h,j,b[h][j]);
    55           az=1;
    56       }}}}
    57         for(int i=1;i<=10;i++){
    58           for(int j=2;j<=n;j++)
    59               if(b[j][i]==0){
    60                 for(int k=j-1;k>=1;k--)
    61                   b[k+1][i]=b[k][i];
    62                   b[1][i]=0;
    63           }
    64           }
    65 }
    66 int main(){
    67     freopen("mooyomooyo.in","r",stdin);
    68     freopen("mooyomooyo.out","w",stdout);
    69     cin>>n>>k;
    70     for(int i=1;i<=n;i++)
    71      for(int j=1;j<=10;j++)
    72      {cin>>a[i][j];b[i][j]=a[i][j]-48;}
    73     for(int i=1;i<=1000;i++){
    74     work();
    75     }
    76     //if(!az)break;
    77     for(int i=1;i<=n;i++){
    78         for(int j=1;j<=10;j++)cout<<b[i][j];
    79         if(i!=n)cout<<endl;    
    80     }
    81     return 0;
    82 }
    戒骄戒躁
  • 相关阅读:
    用PYTHON修改电脑IP地址
    PYTHON os 模块详解
    django 笔记
    PYTHON实战目录
    群晖PLEX设置方法
    jellin docker 群晖设置方法转自先生
    PYTHON ftp 上传方法
    打包驱动EXSI
    我的PYTHON老师ALEX
    安装WHELL
  • 原文地址:https://www.cnblogs.com/lxzl/p/10125522.html
Copyright © 2011-2022 走看看