bool Dance(int d){ if (R[0] == 0){ for (int i = 0;i < d;i++) g[(ans[i]-1)/9] = (ans[i]-1)%9 + '1'; for (int i = 0;i < N*N;i++) printf("%c",g[i]); printf("\n"); return true; } int c = R[0]; for (int i = R[0] ;i != 0;i = R[i]) if (S[i] < S[c]) c = i; remove(c); for (int i = D[c];i != c;i = D[i]){ ans[d] = Row[i]; for (int j = R[i];j != i;j = R[j]) remove(Col[j]); if (Dance(d+1)) return true; for (int j = L[i];j != i;j = L[j]) resume(Col[j]); } resume(c); return false; }
int main() { int i,j,num; while(scanf("%d%d",&n,&m)!=EOF) { for(i=0; i<=m; ++i) { S[i]=0; D[i]=U[i]=i; L[i+1]=i; R[i]=i+1; } R[m]=0; L[0]=m; size=m+1; for(i=1; i<=n; ++i) { H[i]=-1; scanf("%d",&num); while(num--)scanf("%d",&j),Link(i,j); } if(!Dance(0))puts("NO"); } return 0; }
std::pair<bool, std::vector<int>> DancingLink(int n, int m, int s[MAX][MAX]) { BuildLink(s, n, m); DumpGraph(s, n, m); bool dance = Dance(1, s, n, m); std::vector<int> vec; std::transform(chose, chose + n + 1, std::back_inserter(vec), [](const int &v) { return v; }); return std::make_pair(dance, vec); }
static bool Dance(int x, int s[MAX][MAX], int n, int m) { //头节点一行的所有元素都被删除 //只剩0节点 if (leftlink[0] == 0) { return true; } //已经被子集覆盖 //不再重复操作 if (cover[collink[x]]) { return Dance(x + 1, s, n, m); } Remove(index(0, x, m)); DumpGraph(s, n, m); //遍历所有包含x的子集 for (int p = downlink[index(0, x, m)]; p != index(0, x, m); p = downlink[p]) { //选择子集rowlink[p] chose[rowlink[p]] = 1; //删除包含子集rowlink[p]所有元素的子集 for (int q = rightlink[p]; q != p; q = rightlink[q]) Remove(index(0, collink[q], m)); DumpGraph(s, n, m); //下一个元素x+1 if (Dance(x + 1, s, n, m)) return true; //排除子集rowlink[p] chose[rowlink[p]] = 0; //恢复链表 for (int q = leftlink[p]; q != p; q = leftlink[q]) Resume(index(0, collink[q], m)); DumpGraph(s, n, m); } Resume(index(0, x, m)); DumpGraph(s, n, m); return false; }
int Dance(int k) { int i,j,min,c; if(k+h()>Limit) return 0; if(R[head]==head)return 1; for(i=R[head],c=0,min=M;i!=head;i=R[i]){ if(S[i]<min) min=S[i],c=i; } for(i=D[c];i!=c;i=D[i]){ Remove(i); for(j=R[i];j!=i;j=R[j]) Remove(j); if(Dance(k+1)) return 1; for(j=L[i];j!=i;j=L[j]) Resume(j); Resume(i); } return 0; }
int Solve(double rr) { int i,j; for(i=0;i<=n;i++){ S[i]=0;U[i]=D[i]=i; R[i]=i+1;L[i+1]=i; }R[n]=0; size=n+1; memset(H,-1,sizeof(H)); for(i=0;i<m;i++){ for(j=0;j<n;j++){ if(Dis2(radar[i],city[j])<=rr) Link(H[i],j+1); } } for(i=1;i<=n;i++){ if(S[i]==0) return 0; } return Dance(0); }
bool Dance(int k) { int i,j,tmp,c; if(!R[0]) { printf("%d",k); for(i=0; i<k; ++i)printf(" %d",X[Q[i]]); puts(""); return 1; } for(tmp=N,i=R[0]; i; i=R[i]) if(S[i]<tmp)tmp=S[c=i]; remove(c); for(i=D[c]; i!=c; i=D[i]) { Q[k]=i; for(j=R[i]; j!=i; j=R[j])remove(C[j]); if(Dance(k+1))return 1; for(j=L[i]; j!=i; j=L[j])resume(C[j]);//在这里我遵循的原则是先删除的后还原,后删除的先还原。 } resume(c); return 0; }
void Scene::setbg_3(){ QString load; if(difficulty==4) load=":/pics/pics/bg_oni.png"; else if(difficulty==3) load=":/pics/pics/bg_hard.png"; else if(difficulty==2) load=":/pics/pics/bg_normal.png"; else load=":/pics/pics/bg_easy.png"; QImage bg; bg.load(load); bg = bg.scaled(770,400); this->setBackgroundBrush(bg); text1->setText(title[s]); text1->setPos(488,9); addItem(text1); Map.setSongPlay(title[s]); track = new QMediaPlayer(this); track->setMedia(QUrl::fromLocalFile(QDir::toNativeSeparators(Map.trackPath))); VOL=(Map.map["SONGVOL"]-Map.map["SEVOL"])>0?(Map.map["SONGVOL"]-Map.map["SEVOL"]+50):70; track->setVolume(VOL); BPM=Map.map["BPM"]; Map.getMap(title[s],Map.star[difficulty-1]); Map.convert(setRandom); if(setRandom==true){ QPixmap ran; ran.load(":/pics/pics/optionicon_random.png"); randomTag = new QGraphicsPixmapItem; randomTag->setPos(199,83); randomTag->setPixmap(ran); addItem(randomTag); } if(setAuto==true){ QPixmap au; au.load(":/pics/pics/optionicon_auto.png"); autoTag = new QGraphicsPixmapItem; autoTag->setPos(394,72); autoTag->setPixmap(au); addItem(autoTag); } if(set30secMode==true){ QPixmap ctd; ctd.load(":/pics/pics/optionicon_demo.png"); countdownTag = new QGraphicsPixmapItem; countdownTag->setPos(294,72); countdownTag->setPixmap(ctd); addItem(countdownTag); countdown = new QTimer(this); QObject::connect(countdown , SIGNAL(timeout()) , this , SLOT(secondsLeft())); } songMap=Map.songMap; foreach (QString i, songMap) { qDebug()<<i<<endl; } RD = new QTimer(this); LD = new QTimer(this); RK = new QTimer(this); LK = new QTimer(this); rdp = new QGraphicsPixmapItem;ldp = new QGraphicsPixmapItem; rkp = new QGraphicsPixmapItem;lkp = new QGraphicsPixmapItem; QPixmap res; res.load(":/pics/pics/rd.png"); rdp->setPixmap(res);rdp->setPos(147,123); res.load(":/pics/pics/ld.png"); ldp->setPixmap(res);ldp->setPos(106,123); res.load(":/pics/pics/rk.png"); rkp->setPixmap(res);rkp->setPos(147,124); res.load(":/pics/pics/lk.png"); lkp->setPixmap(res);lkp->setPos(105,124); for(int i=0;i<4;i++){ add[i]=false; } QObject::connect(this , SIGNAL(PlayRdong()) , this , SLOT(playRdong())); QObject::connect(this , SIGNAL(PlayLdong()) , this , SLOT(playLdong())); QObject::connect(this , SIGNAL(PlayRka()) , this , SLOT(playRka())); QObject::connect(this , SIGNAL(PlayLka()) , this , SLOT(playLka())); QObject::connect(RD , SIGNAL(timeout()) , this , SLOT(playRdong())); QObject::connect(LD , SIGNAL(timeout()) , this , SLOT(playLdong())); QObject::connect(RK , SIGNAL(timeout()) , this , SLOT(playRka())); QObject::connect(LK , SIGNAL(timeout()) , this , SLOT(playLka())); AniTimer1 = new QTimer(this); QObject::connect(AniTimer1 , SIGNAL(timeout()) , this , SLOT(moveJudgement())); QObject::connect(AniTimer1 , SIGNAL(timeout()) , this , SLOT(FlySoul())); QObject::connect(AniTimer1 , SIGNAL(timeout()) , this , SLOT(MidSoul())); QObject::connect(AniTimer1 , SIGNAL(timeout()) , this , SLOT(WalkSoul())); QObject::connect(this , SIGNAL(Great()) , this , SLOT(GenGreat())); QObject::connect(this , SIGNAL(Good()) , this , SLOT(GenGood())); QObject::connect(this , SIGNAL(Miss()) , this , SLOT(GenMiss())); QObject::connect(this , SIGNAL(Combo()) , this , SLOT(ShowCombo())); QObject::connect(this , SIGNAL(Score()) , this , SLOT(ShowScore())); QObject::connect(this , SIGNAL(Jump()) , this , SLOT(donJump())); QObject::connect(this , SIGNAL(SoulF()) , this , SLOT(GenFlySoul())); QObject::connect(this , SIGNAL(SoulM()) , this , SLOT(GenMidSoul())); QObject::connect(this , SIGNAL(SoulW()) , this , SLOT(GenWalkSoul())); ex1.load(":/pics/pics/explosion_s4.png"); AniTimer2 = new QTimer(this); QObject::connect(AniTimer2 , SIGNAL(timeout()) , this , SLOT(RemoveExplode())); QObject::connect(this , SIGNAL(Explode()) , this , SLOT(GenExplode())); AniTimer3 = new QTimer(this); QObject::connect(AniTimer3 , SIGNAL(timeout()) , this , SLOT(Jumper())); jumper = new QGraphicsPixmapItem; jumper->setPos(0,0); addItem(jumper); AniTimer4 = new QTimer(this); QObject::connect(AniTimer4 , SIGNAL(timeout()) , this , SLOT(Dance())); loadDancerPic(); createDanceItem(); great=0;good=0;miss=0; combo=0;maxcombo=0;soul=0,score=0; secLeft=30;jumpPicNum=1; msec=60000/BPM/4+2; test=60000/BPM/16; waitfor=109*test/2+Map.map["OFFSET"]*1000; for(int i=0;i<10;i++){ numberPic[i].load(":/pics/pics/number_"+QString::number(i)+".png"); } for(int i=0;i<10;i++){ ctdnumberPic[i].load(":/pics/pics/number_"+QString::number(i)+".png"); } for(int i=0;i<10;i++){ scorenumberPic[i].load(":/pics/pics/scorenumber_"+QString::number(i)+".png"); } for(int i=50;i<1000;i+=100){ QSound *so; QString c; c=QString::number(i); so = new QSound(":/sound/sound/voice_"+c+"combo.wav"); comTrack.push_back(so); if(i==50)i+=50; } for(int i=0;i<3;i++){ jumpPic[i].load(":/pics/pics/playerchar_normal"+QString::number(i+1)+".png"); jumpPic[i] = jumpPic[i].scaled(jumpPic[i].width()*1.48,jumpPic[i].height()*1.48); } //Etimer = new QElapsedTimer; //Etimer->start(); timer = new QTimer(this); QObject::connect(timer , SIGNAL(timeout()) , this , SLOT(stopWait())); timer1 = new QTimer(this); timer2 = new QTimer(this); timer3 = new QTimer(this); cout<<"msec: "<<msec<<endl; cout<<"waitfor: "<<waitfor<<endl; QObject::connect(timer2 , SIGNAL(timeout()) , this , SLOT(Generate())); if(setAuto==false) QObject::connect(timer1 , SIGNAL(timeout()) , this , SLOT(Move())); else QObject::connect(timer1 , SIGNAL(timeout()) , this , SLOT(Auto())); QObject::connect(timer3 , SIGNAL(timeout()) , this , SLOT(startWave())); if(waitfor<0){ track->play(); timer->start(-waitfor); waitfor=0; } else timer->start(0); }