首页 > 其他分享 >Codeforces Round #839 F

Codeforces Round #839 F

时间:2023-01-14 20:00:30浏览次数:59  
标签:std cnt int 839 Codeforces Copy Round

F. Copy of a Copy of a Copy

题链
我们发现这个操作是将中间不一样周围四个一样的
形如
1 0
101 010
1 0
变成全部都一样的 显然这样变之后是不可还原的 就是说这样的方格只会减少
而且题目说了 肯定有一个答案
那我们就直接对这样的格子计数 然后排序
之后就输出即可

int n,m,k;
struct node{
    int cnt;
    std::vector<std::vector<int>>g;
    int pos;
    bool operator < (const node W)const{
        return cnt > W.cnt ;
    }
};
std::vector<node>a;
void solve(){
    cin>>n>>m>>k;
    std::vector<std::vector<int>> v;
    v.resize(n);
    for(int i=0;i<n;i++)v[i].resize(m);
    for(int i=0;i<k+1;i++){
        for(int j=0;j<n;j++)for(int r=0;r<m;r++){
                char c;cin>>c;
                v[j][r]=c-'0';
            }
        int cnt=0;
        for(int x=1;x<n-1;x++)for(int y=1;y<m-1;y++){
                if(v[x][y] + v[x - 1][y] == 1 && v[x][y] + v[x + 1][y] == 1 && v[x][y] + v[x][y - 1] == 1 &&
                   v[x][y] + v[x][y + 1] == 1)cnt++;
            }
        a.push_back({cnt,v,i});
    }
    sort(all(a));
    cout<<a[0].pos+1<<endl;
    std::vector<string>ans;
    for(int i=1;i<k+1;i++){
        for(int x=1;x<n-1;x++)for(int y=1;y<m-1;y++)
                if(a[i].g[x][y]!=a[i-1].g[x][y])
                    ans.push_back("1 "+to_string(x+1)+" "+to_string(y+1));
        ans.push_back("2 "+to_string(a[i].pos+1));
    }
    cout<<ans.size()<<endl;
    for(auto s:ans)cout<<s<<endl;
}

标签:std,cnt,int,839,Codeforces,Copy,Round
From: https://www.cnblogs.com/ycllz/p/17052441.html

相关文章