# [2019.3.21]洛谷P3640 [APIO2013]出题人

#### SSSP:

FloydWarshall:稳定$O(V^3)$

ModifiedDijkstra:正权图跑得贼快,负权图可能会被卡掉

OptimizedBellmanFord:时间按复杂度取决于更新节点的顺序

#### Mystery(染色问题):

RecursiveBacktracking:时间复杂度很大程度上取决于答案的大小

(允许的话甚至可以没有询问,但是本题要求$Q>0$)

code:

#include<bits/stdc++.h>
using namespace std;
int n=101;
int main(){
freopen("1.txt","w",stdout),printf("%d\n",n);
for(int i=1;i<=n;++i)puts("0");
puts("1\n1 1");
return 0;
}


code:

#include<bits/stdc++.h>
using namespace std;
int n=100,T=2222,Q=10,Num,RE,RN;
void print(int x){
if(x!=n-1){
printf("%d ",Num);
for(int i=1;i<=Num;++i)printf("%d 1 ",x?x-1:n-1);//0与n-1之间的边并不会影响复杂度
puts("");
}else{
printf("%d ",Num+RE);
for(int i=1;i<=Num+RE;++i)printf("%d 1 ",x?x-1:n-1);
puts("");
}
}
int main(){
freopen("2.txt","w",stdout);
printf("%d\n",n),T-=1+n+1+(Q<<1),Num=(T>>1)/n,RE=(T>>1)-Num*n;
for(int i=0;i<n;++i)print(i);
printf("%d\n",Q);
while(Q--)printf("%d 0\n",n-1);
return 0;
}


code:

#include<bits/stdc++.h>
using namespace std;
int n=101;
int main(){
freopen("3.txt","w",stdout);
printf("%d\n",n);
for(int i=1;i<=n;++i)puts("0");
puts("1\n0 1");
return 0;
}


$1+(2x+1)+(2\times 3x)+1+2=157$

code:

#include<bits/stdc++.h>
using namespace std;
int n=37,q=5,tt=1;
int main(){
freopen("4.txt","w",stdout);
printf("%d\n",n);
puts("0");
for(int i=1;i<n;++i)i&1?printf("1 %d %d\n",i-1,-tt<<1):(printf("2 %d 0 %d %d\n",i-2,i-1,tt),tt<<=1);
printf("%d\n",q);
for(int i=1;i<=q;++i)printf("%d 0\n",n-1);
return 0;
}


code:

#include<bits/stdc++.h>
using namespace std;
int n=300,T=1016,Q=10,Num,RE,RN;
void print(int x){
if(x!=n-1){
printf("%d ",Num);
for(int i=1;i<=Num;++i)printf("%d 1 ",x?x-1:n-1);
puts("");
}else{
printf("%d ",Num+RE);
for(int i=1;i<=Num+RE;++i)printf("%d 1 ",x?x-1:n-1);
puts("");
}
}
int main(){
freopen("5.txt","w",stdout);
printf("%d\n",n),T-=1+n+1+(Q<<1),Num=(T>>1)/n,RE=(T>>1)-Num*n;
for(int i=0;i<n;++i)print(i);
printf("%d\n",Q);
while(Q--)printf("%d 0\n",n-1);
return 0;
}


code:

#include<bits/stdc++.h>
using namespace std;
int n=33,q=6,tt=1;
int main(){
freopen("6.txt","w",stdout);
printf("%d\n",n);
puts("0");
for(int i=1;i<n;++i)i&1?printf("1 %d %d\n",i-1,-tt<<1):(printf("2 %d 0 %d %d\n",i-2,i-1,tt),tt<<=1);
printf("%d\n",q);
for(int i=1;i<=q;++i)printf("%d 0\n",n-1);
return 0;
}


$2+V(V-1)=3004$,2是输出$V,E$的数量,$V$个点的完全图有$\frac{V(V-1)}{2}$条边,需要用$V(V-1)$个数表示。

code:

#include<bits/stdc++.h>
using namespace std;
int n=71,gr=55,E=1501;
int main(){
freopen("7.txt","w",stdout);
printf("%d %d\n",n,E);
for(int i=0;i<gr;++i)for(int j=i+1;j<gr;++j)printf("%d %d\n",i,j);
for(int i=gr;i<n;++i)printf("%d %d\n",i-1,i);
return 0;
}


code:

#include<bits/stdc++.h>
using namespace std;
int n=999,E=1501;
int main(){
freopen("8.txt","w",stdout);
printf("%d %d\n",n,E);
for(int i=1;i<n;++i)printf("%d %d\n",i-1,i),--E;
for(int i=0;i<n&&E;++i)printf("%d %d\n",i,i+2),--E;
return 0;
}

posted @ 2019-03-21 20:13  xryjr233  阅读(...)  评论(...编辑  收藏