2014 ACM/ICPC Asia Regional Xi'an Online 小记

来源:互联网 发布:淘宝花呗账号出售 编辑:程序博客网 时间:2024/05/01 20:55


1006

struct  state{        int a[6] ;        int step ;        state(){} ;        state(int i , int j , int k , int b , int c  , int d , int s){              a[0] = i ;              a[1] = j ;              a[2] = k ;              a[3] = b ;              a[4] = c ;              a[5] = d ;              step  = s ;        }        state L(){              return state(a[3] , a[2] , a[0] , a[1] , a[4] , a[5] , step+1) ;        }        state R(){              return state(a[2] , a[3] , a[1] , a[0] , a[4] , a[5] , step+1) ;        }        state F(){              return state(a[5] , a[4] , a[2] , a[3] , a[0] , a[1] , step+1) ;        }        state B(){              return state(a[4] , a[5] , a[2] , a[3] , a[1] , a[0] , step+1) ;        }        int  value(){             return  100000 * a[0] +                     10000 * a[1] +                     1000 * a[2] +                     100 * a[3] +                     10 * a[4] +                     1 * a[5]  ;        }        friend bool operator == (const state &x , const state &y){             return x.a[0] == y.a[0] &&                    x.a[1] == y.a[1] &&                    x.a[2] == y.a[2] &&                    x.a[3] == y.a[3] &&                    x.a[4] == y.a[4] &&                    x.a[5] == y.a[5] ;        }        friend bool operator < (const state &x , const state &y){               return x.step > y.step ;        }};set<int> st ;int  bfs(state s , state t){     priority_queue<state> q ;     q.push(s) ;     st.insert(s.value()) ;     state g ; int c ;     while( ! q.empty()){            state now = q.top() ; q.pop() ;            if(now == t) return now.step ;            g = now.L() ;            c = g.value() ;            if(st.find(c) == st.end()){                  q.push(g) ;                  st.insert(c) ;            }            g = now.R() ;            c = g.value() ;            if(st.find(c) == st.end()){                  q.push(g) ;                  st.insert(c) ;            }            g = now.F() ;            c = g.value() ;            if(st.find(c) == st.end()){                  q.push(g) ;                  st.insert(c) ;            }            g = now.B() ;            c = g.value() ;            if(st.find(c) == st.end()){                  q.push(g) ;                  st.insert(c) ;            }     }     return -1 ;}int  main(){     state s , t ;     int a[6] , b[6] , i ;     while(cin>>a[0]){          st.clear() ;          for(i = 1 ; i <= 5 ; i++) scanf("%d" , &a[i]) ;          for(i = 0 ; i <= 5 ; i++) scanf("%d" , &b[i]) ;          s = state(a[0] , a[1] , a[2] , a[3] , a[4] , a[5] , 0) ;          t = state(b[0] , b[1] , b[2] , b[3] , b[4] , b[5] , 0) ;          cout<< bfs(s , t) << endl ;     }     return 0 ;}


1008 

const  int  maxn = 100008 ;int  to[maxn] , a[maxn] ;int  gao(int x){     int t = 0 , y = 1 ;     for(; x ; x >>= 1){         if(x & 1){}         else  t += y ;         y <<= 1 ;     }     return t ;}int main(){    int  n , i , t , s  , j ;    while(cin>>n){         s = 0 ;         for(i = 0 ; i <= n ; i++) scanf("%d" , &a[i]) ;         for(i = 0 ; i <= n ; i++) to[i] = -1 ;         t = n ;         for(i = t ; i >= 0 ; i--){              if(to[i] != -1) continue ;              j = gao(i) ;              /*if(to[j] != -1){                  puts("wrong") ;              } */              to[i] = j ;              to[j] = i ;         }         LL sum = 0 ;         for(int i = 0 ; i <= n ; i++)              sum += (LL)(i) ^ (LL)(to[i]) ;         cout<< sum << endl ;         printf("%d" , to[a[0]]) ;         for(int i = 1 ; i <= n ; i++) printf(" %d" , to[a[i]]) ;         puts("") ;    }    return 0;}


1009

typedef long long LL ;const LL  mod = 10000007LL ;int     n ;struct  Mat{        LL  c[12][12] ;        Mat(){             memset(c , 0 , sizeof(c)) ;        }        Mat(int){             memset(c , 0 , sizeof(c)) ;             for(int i = 0 ; i <= n ; i++) c[i][i] = 1LL ;        }        friend Mat operator * (const Mat &a , const Mat &b){            Mat t ;            for(int i = 0 ; i <= n ; i++){                 for(int j = 0 ; j <= n ; j++){                     for(int k = 0 ; k <= n ; k++){                         t.c[i][j] += a.c[i][k] * b.c[k][j] ;                         t.c[i][j] %= mod ;                     }                 }            }            return t ;        }        friend Mat operator ^ (Mat x , int y){            Mat t(1) ;            for(; y ; y >>= 1){                if(y & 1) t = t * x  ;                x = x * x ;            }            return t ;        }};LL   a[18] , b[18] ;int  main(){     int m , i , j ;     while(cin>>n>>m){          for(i = 1 ; i <= n ; i++) cin>>a[i] ;          Mat A ;          A.c[0][0] = 10  , A.c[0][n+1] = 3 ;          for(i = 1 ; i <= n ; i++){              A.c[i][0] = 10 , A.c[i][n+1] = 3 ;              for(j = 1 ; j <= i ; j++) A.c[i][j] = 1 ;          }          A.c[n+1][n+1] = 1 ;          n++ ;          A = A ^ (m-1) ;          b[0] = 233LL ;          for(i = 1 ; i < n ; i++) b[i] = (b[i-1] + a[i]) % mod  ;          b[n] = 1 ;          LL ans = 0LL ;          for(i = 0 ; i <= n ; i++){              ans += A.c[n-1][i] * b[i] ;              ans %= mod ;          }          cout << ans << endl ;     }     return 0  ;}





0 0
原创粉丝点击