如果发现广告等破坏行为,请尽量将条目恢复到较早的版本而不是把相应内容直接删除,谢谢合作。
URAL/1015
来自"NOCOW"
< URAL
[编辑] 不预处理所有状态的做法
#include <iostream> using namespace std; //表示每个面相邻的按顺时针顺序的面 int d[7][4] = {{0, 0, 0, 0}, {3, 4, 5, 6}, {6, 5, 4, 3}, {6, 2, 4, 1}, {1, 3, 2, 5}, {1, 4, 2, 6}, {5, 2, 3, 1}}; int a[7], tot; int h[1000000]; int q[1000000], nt[100000], s1[100000]; void calc(int n) { bool b[7] = {0}; int i, j, k, s, t, ss; for(i = 1 ; i <= 6 ; i++) { cin >> a[i]; if(a[i] == 1) k = i; } s = 0; for(i = 0 ; i <= 3 ; i++) s = s * 10 + a[d[k][i]], b[a[d[k][i]]] = true; t = s; for(i = 1 ; i <= 3 ; i++) { s = s % 10 * 1000 + s / 10; if(t > s) t = s; } for(i = 2 ; i <= 6 ; i++) if(b[i]) j = j * 10 + i; else k = i; j = 100000 + t * 10 + k; if(h[j] == 0) h[j] = n, tot++; else nt[q[j]] = n; q[j] = n; s1[n] = j; } void work() { int n; cin >> n; for(int i = 1 ; i <= n ; i++) calc(i); cout << tot << endl; for(int i = 1 ; i <= n ; i++) if(s1[i] != -1) { cout << i; for(int j = nt[h[s1[i]]] ; j != 0 ; j = nt[j]) { s1[j] = -1; cout << ' ' << j; } cout << endl; } } int main() { work(); return 0; }
[编辑] 先预处理出所有状态,看哪些状态是相同的,再读入数据,用链表存答案,再输出.
program cao; type node=record v,next:longint; end; var f:array[1..6,1..6,1..6,1..6,1..6,1..6] of longint; head,order,tail:array[0..720] of longint; t:array[0..200000] of node; a,b,c,d,e,g,h,i,j,k,l,n,m,p,q,total,a1,a2,a3,a4,a5,a6:longint; st:set of 0..6; procedure init; begin total:=0; for a1:=1 to 6 do for a2:=1 to 6 do for a3:=1 to 6 do for a4:=1 to 6 do for a5:=1 to 6 do for a6:=1 to 6 do begin st:=[a1]+[a2]+[a3]+[a4]+[a5]+[a6]; if (st=[1..6])and(f[a1,a2,a3,a4,a5,a6]=0) then begin inc(total); f[a1,a2,a3,a4,a5,a6]:=total; f[a1,a2,a4,a5,a6,a3]:=total; f[a1,a2,a5,a6,a3,a4]:=total; f[a1,a2,a6,a3,a4,a5]:=total; f[a2,a1,a3,a6,a5,a4]:=total; f[a2,a1,a4,a3,a6,a5]:=total; f[a2,a1,a5,a4,a3,a6]:=total; f[a2,a1,a6,a5,a4,a3]:=total; f[a3,a5,a2,a4,a1,a6]:=total; f[a3,a5,a6,a2,a4,a1]:=total; f[a3,a5,a1,a6,a2,a4]:=total; f[a3,a5,a4,a1,a6,a2]:=total; f[a5,a3,a1,a4,a2,a6]:=total; f[a5,a3,a6,a1,a4,a2]:=total; f[a5,a3,a2,a6,a1,a4]:=total; f[a5,a3,a4,a2,a6,a1]:=total; f[a4,a6,a3,a2,a5,a1]:=total; f[a4,a6,a1,a3,a2,a5]:=total; f[a4,a6,a5,a1,a3,a2]:=total; f[a4,a6,a2,a5,a1,a3]:=total; f[a6,a4,a5,a2,a3,a1]:=total; f[a6,a4,a1,a5,a2,a3]:=total; f[a6,a4,a3,a1,a5,a2]:=total; f[a6,a4,a2,a3,a1,a5]:=total; end; end; end; procedure main; begin p:=0; read(n); for i:=1 to n do begin read(a1,a2,a3,a4,a5,a6); inc(total); t[total].v:=i; if head[f[a1,a2,a3,a4,a5,a6]]=0 then begin head[f[a1,a2,a3,a4,a5,a6]]:=total; tail[f[a1,a2,a3,a4,a5,a6]]:=total; inc(p); order[p]:=total; end else begin t[tail[f[a1,a2,a3,a4,a5,a6]]].next:=total; tail[f[a1,a2,a3,a4,a5,a6]]:=total; end; end; writeln(p); for i:=1 to p do begin j:=order[i]; while j<>0 do begin write(t[j].v,‘ ‘); j:=t[j].next; end; writeln; end; end; begin init; main; end.