首页 > 其他分享 >Tyrue的博客

Tyrue的博客

时间:2022-11-30 08:33:44浏览次数:33  
标签:ch Tyrue int 博客 while include

欢迎来到Tyrue的博客

Luogu_Blog

// #Tyrue#
#include<map>
#include<cstdio>
#include<string>
#include<iostream>
using namespace std;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
        x=x*10+ch-'0',ch=getchar();
    return x*f;
}
const int N=6e3+10;
struct Node{
    int l,r,u,d,ro,c;
}node[N];
int T,n,m,cnt;
int row[N],ans[N],lcnt[N];
void init(){    
    for(int i=0;i<=m;i++){
        node[i].u=i;
        node[i].d=i;
        node[i].l=i-1;
        node[i].r=i+1;
    }
    node[0].l=m;
    node[m].r=0;
    cnt=m;
    return ;
}
void add(int x,int y){
    // node[++cnt]=((Node){0,0,node[x].u,y,x,y});
    node[++cnt].ro=x;
    node[cnt].c=y;
    node[cnt].u=node[y].u;
    node[cnt].d=y;
    node[node[cnt].u].d=cnt;
    node[y].u=cnt;
    if(!row[x]){
        node[cnt].l=cnt;
        node[cnt].r=cnt;
        row[x]=cnt;
    }else{
        node[cnt].l=node[row[x]].l;
        node[cnt].r=row[x];
        node[node[cnt].l].r=cnt;
        node[node[cnt].r].l=cnt;
    }
    lcnt[y]++;
    return ;
}
void remove(int x){
    for(int i=node[x].d;i!=x;i=node[i].d){
        for(int j=node[i].r;j!=i;j=node[j].r){
            node[node[j].d].u=node[j].u;
            node[node[j].u].d=node[j].d;
            lcnt[node[j].c]--;
        }
    }
    node[node[x].l].r=node[x].r;
    node[node[x].r].l=node[x].l;
}
void resume(int x){
    node[node[x].l].r=x;
    node[node[x].r].l=x;
    for(int i=node[x].d;i!=x;i=node[i].d){
        for(int j=node[i].r;j!=i;j=node[j].r){
            node[node[j].d].u=j;
            node[node[j].u].d=j;
            lcnt[node[j].c]++;
        }
    }
}
bool dance(int dep){
    if(node[0].r==0){
        // for(int i=1;i<dep;i++){
        //     printf("%d ",ans[i]);
        // }
        // puts("");
        for(int i=1;i<dep-1;i++){
            printf("%d ",ans[i]);
        }
        printf("%d\n",ans[dep-1]);
        return 1;
    }
    int C=node[0].r;
    for(int i=node[0].r;i;i=node[i].r){
        if(lcnt[i]<lcnt[C]){
            C=i;
        }
    }
    remove(C);
    for(int i=node[C].d;i!=C;i=node[i].d){
        ans[dep]=node[i].ro;
        for(int j=node[i].r;j!=i;j=node[j].r){
            remove(node[j].c);
        }
        if(dance(dep+1)){
            return 1;
        }
        for(int j=node[i].r;j!=i;j=node[j].r){
            resume(node[j].c);
        }
    }
    resume(C);
    return 0;
}
int main(){
    // T=read();
    n=read(),m=read();
    init();
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            int x=read();
            if(x){
                add(i,j);
            }
        }
    }
    if(!dance(1)){
        puts("No Solution!");
    }
    return 0;
}

标签:ch,Tyrue,int,博客,while,include
From: https://www.cnblogs.com/Tyrue-blog/p/16937338.html

相关文章

  • 美化博客园
    1、准备博客园主题使用SimpleMemory官方主题帮助文档:简介-Document(bndong.github.io)代码会上传至github上:ChaunceyKong/SimpleMemory(github.com)2、效果主页:......
  • 博客园
    css代码@importurl(https://cdn.jsdelivr.net/npm/[email protected]/css/font-awesome.min.css);@mediaonlyscreenand(max-width:1365px){.github-corner{display:......
  • 仅以此博客记录一下我的程序员生涯
    从事程序员工作十余年,也没有职业规则,也没有遇到过带队机会,以致于人近中年也只能做一些基础的码农工作,而且还是通过学历造假得来的,不想再这么苟活下去了,所以决定开博客......
  • 2013年度IT博客大赛跻身10强
    2013年12月26日,由51CTO独家举办的2013年度IT博客大赛圆满落幕,荣幸跻身10强[​​http://fellow.51cto.com/art/201312/425528.htm​​],首先感谢各位评委和众多网友的大力支持......
  • 博客项目学习技术点
    1.标准返回类实现packagecom.han.entity;@JsonInclude(JsonInclude.Include.NON_NULL)publicclassResponseResult<T>implementsSerializable{privateInteg......
  • (5条消息) map干掉两个for循环案例,空间复杂度优化_学习微站的博客-CSDN博客_map空间复
    map干掉两个for循环,​​空间复杂度​​优化//分组遍历if(CollectionUtils.isNotEmpty(dictGroupList)){dictGroupList.forEach(dicGroup->......
  • 记一次博客园随笔被爬经历
    上篇随笔发布后,一天内,十几个爬虫网站爬取了我的随笔,有些网站非但没有注明来源,反而将自己标为博文的原创者,并更改了图像水印,这篇被爬的随笔虽浏览量不大,但好歹是自己一字一......
  • 基于.NetCore开发博客项目 StarBlog - (20) 图片显示优化
    前言我的服务器带宽比较高,博客部署在上面访问的时候几乎没感觉有加载延迟,就没做图片这块的优化,不过最近有小伙伴说博客的图片加载比较慢,那就来把图片优化完善一下吧~目前......
  • 基于halo搭建博客,替换joe2.0卜算子为51LA
    网站底部统计访客效果改造前改造后简介【卜算子】“卜蒜子”与百度统计谷歌分析等有区别:“卜蒜子”可直接将访问次数显示在您在网页上(也可不显示);对于已经上线一段时间的网......
  • 使用open live write发布博客园的博客
    官方教程的FAQ:http://www.cnblogs.com/zsy/p/5859928.html包含了几个工具可以都看看-------------------------------------------------------------------------------......