A.Babs' Box Boutique
给定n个盒子,每个盒子都有长宽高(任意两个盒子长宽高不完全相同),现在选盒子的任意两面,要求x1 <= x2 && y1 <= y2,问最多能选多少盒子满足这需求。
直接dfs暴搞................
#include #include #include #include #include #include #include
C.Hexagon Perplexagon
题意就不写了:
dfs暴搞,每一层传入三个参数,层数, 每一块需要匹配的前驱点,和最后一块需要匹配的点..........
#include #include #include #include #include #include #include using namespace std;int map[8][8];int ans[8];int save[8];int vis[8];int n,ok;void change(int x,int pos) { int i; for(i=0; i<6; i++) { if(map[x][i] == pos) break; } pos = i; int cnt = 0; for(int i=0; i<6; i++) { save[cnt++] = map[x][pos]; pos ++; if(pos >= 6) pos -= 6; }}int getpre(int pos,int t) { t --; if(t < 0) t = 5; return map[pos][t];}int getsuc(int pos,int t) { t ++; if(t > 5) t = 0; return map[pos][t];}void dfs(int step,int p1,int p2) { if(step == 7) return ; if(ok == 1) return ; for(int i=0; i<7; i++) { if(vis[i] == 1) continue; int j; for(j=0; j<6; j++) { if(map[i][j] == save[step-1]) break; } int tmp1 = getpre(i,j); int tmp2 = getsuc(i,j); if(step == 1) { ans[step] = i; vis[i] = 1; dfs(step + 1,tmp1,tmp2); vis[i] = 0; } if(step > 1 && step < 6) { if(tmp2 == p1 ) { ans[step] = i; vis[i] = 1; dfs(step+1,tmp1,p2); vis[i] = 0; } } if(step == 6) { if(tmp2 == p1 && tmp1 == p2 ) { ans[step] = i; ok = 1; } } if(ok == 1) return ; }}int main() { int T; cin >> T; int casee = 1; while(T --) { for(int i=0; i<7; i++) { for(int j=0; j<6; j++) { scanf("%d",&map[i][j]); } } ok = 0; for(int i=0; i<7; i++) { memset(vis,0,sizeof(vis)); vis[i] = 1; change(i,1); ans[0] = i; dfs(1,0,0); if(ok) break; } printf("Case %d: ",casee++); if(ok == 0) { printf("No solution\n"); continue; } printf("%d",ans[0]); for(int i=1; i<7; i++) { printf(" %d",ans[i]); } puts(""); } return 0;}
D.I've Got Your Back(gammon)
暴搞,每一种排列分别保存它的各个点的情况,并且用map保存每种排列的顺序下标
#include #include #include #include #include #include