• HDU 4633 Who's Aunt Zhang (2013多校4 1002 polya计数)


    Who's Aunt Zhang

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 19    Accepted Submission(s): 16


    Problem Description
    Aunt Zhang, well known as 张阿姨, is a fan of Rubik’s cube. One day she buys a new one and would like to color it as a gift to send to Teacher Liu, well known as 刘老师. As Aunt Zhang is so ingenuity, she can color all the cube’s points, edges and faces with K different color. Now Aunt Zhang wants to know how many different cubes she can get. Two cubes are considered as the same if and only if one can change to another ONLY by rotating the WHOLE cube. Note that every face of Rubik’s cube is consists of nine small faces. Aunt Zhang can color arbitrary color as she like which means that she doesn’t need to color the nine small faces with same color in a big face. You can assume that Aunt Zhang has 74 different elements to color. (8 points + 12 edges + 9*6=54 small faces)
     
    Input
    The first line of the date is an integer T, which is the number of the text cases.
    Then T cases follow, each case contains one integer K, which is the number of colors. T<=100, K<=100.
     
    Output
    For each case, you should output the number of different cubes.
    Give your answer modulo 10007.
     
    Sample Input
    3 1 2 3
     
    Sample Output
    Case 1: 1 Case 2: 1330 Case 3: 9505
     
    Source
     
    Recommend
    zhuyuanchen520
     

    明显是polya计数的题目。

    但是本题有74个元素,

    总共的变换数数24种。

    数起来很麻烦,数据很大。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

    于是我用代码怒搞之。

    写代码找不动点。。。。共24种变换,24种都可以通过多次右旋和上旋得到。。。

    300多行代码,,,,,终于找到不动点个数了。。。。。。

    附上源代码,。包括找不动点。。

    找出来可以直接用公式写的,就没有优化了

      1 /*
      2  *  Author:kuangbin
      3  *  1002.cpp
      4  */
      5 
      6 #include <stdio.h>
      7 #include <algorithm>
      8 #include <string.h>
      9 #include <iostream>
     10 #include <map>
     11 #include <vector>
     12 #include <queue>
     13 #include <set>
     14 #include <string>
     15 #include <math.h>
     16 using namespace std;
     17 const int MOD = 10007;
     18 long long pow_m(long long a,long long n)
     19 {
     20     long long ret = 1;
     21     long long tmp = a%MOD;
     22     while(n)
     23     {
     24         if(n&1)
     25         {
     26             ret *= tmp;
     27             ret %=MOD;
     28         }
     29         tmp *= tmp;
     30         tmp %=MOD;
     31         n >>= 1;
     32     }
     33     return ret;
     34 }
     35 //求ax = 1( mod m) 的x值,就是逆元(0<a<m)
     36 long long inv(long long a,long long m)
     37 {
     38     if(a == 1)return 1;
     39     return inv(m%a,m)*(m-m/a)%m;
     40 }
     41 
     42 
     43 int b[100];
     44 int c[100];
     45 
     46 void rr()
     47 {
     48     for(int i = 1;i <= 54;i++)
     49         c[i] = b[i];
     50     for(int i = 1;i <= 27;i++)
     51         b[i+9] = c[i];
     52     for(int i = 1;i <= 9;i++)
     53         b[i] = c[27+i];
     54     b[39] = c[37];
     55     b[42] = c[38];
     56     b[45] = c[39];
     57     b[44] = c[42];
     58     b[43] = c[45];
     59     b[40] = c[44];
     60     b[37] = c[43];
     61     b[38] = c[40];
     62     b[41] = c[41];
     63 
     64 
     65     b[54] = c[52];
     66     b[51] = c[53];
     67     b[48] = c[54];
     68     b[47] = c[51];
     69     b[46] = c[48];
     70     b[49] = c[47];
     71     b[52] = c[46];
     72     b[53] = c[49];
     73     b[50] = c[50];
     74 
     75 }
     76 void up()
     77 {
     78     for(int i = 1;i <= 54;i++)
     79         c[i] = b[i];
     80     for(int i = 1;i <= 9;i++)
     81         b[i] = c[45+i];
     82     for(int i = 37;i <= 45;i++)
     83         b[i] = c[i-36];
     84     for(int i = 19;i <= 27;i++)
     85         b[i] = c[64-i];
     86     for(int i = 46;i <= 54;i++)
     87         b[i] = c[73-i];
     88 
     89     b[10] = c[12];
     90     b[13] = c[11];
     91     b[16] = c[10];
     92     b[17] = c[13];
     93     b[18] = c[16];
     94     b[15] = c[17];
     95     b[12] = c[18];
     96     b[11] = c[15];
     97     b[14] = c[14];
     98 
     99     b[28] = c[34];
    100     b[29] = c[31];
    101     b[30] = c[28];
    102     b[33] = c[29];
    103     b[36] = c[30];
    104     b[35] = c[33];
    105     b[34] = c[36];
    106     b[31] = c[35];
    107     b[32] = c[32];
    108 
    109 }
    110 
    111 bool used[1000];
    112 
    113 int calc()
    114 {
    115     memset(used,false,sizeof(used));
    116 
    117     int ret = 0;
    118     for(int i = 1;i <= 54;i++)
    119         if(!used[i])
    120     {
    121         ret++;
    122         int tmp = i;
    123         while(!used[tmp])
    124         {
    125             used[tmp] = true;
    126             tmp = b[tmp];
    127         }
    128     }
    129     return ret;
    130 
    131 }
    132 
    133 
    134 void rr2()
    135 {
    136     for(int i = 1;i <= 12;i++)
    137         c[i] = b[i];
    138     b[1] = c[4];
    139     for(int i = 2;i <= 4;i++)
    140         b[i] = c[i-1];
    141     b[5] = c[8];
    142     for(int i = 6;i <= 8;i++)
    143         b[i] = c[i-1];
    144     b[9] = c[12];
    145     for(int i = 10;i <= 12;i++)
    146         b[i] = c[i-1];
    147 }
    148 void up2()
    149 {
    150         for(int i = 1;i <= 12;i++)
    151         c[i] = b[i];
    152     b[1] = c[3];
    153     b[2] = c[7];
    154     b[3] = c[11];
    155     b[4] = c[8];
    156     b[5] = c[4];
    157     b[6] = c[2];
    158     b[7] = c[10];
    159     b[8] = c[12];
    160     b[9] = c[1];
    161     b[10] = c[6];
    162     b[11] = c[9];
    163     b[12] = c[5];
    164 }
    165 int calc2()
    166 {
    167     memset(used,false,sizeof(used));
    168 
    169     int ret = 0;
    170     for(int i = 1;i <= 12;i++)
    171         if(!used[i])
    172     {
    173         ret++;
    174         int tmp = i;
    175         while(!used[tmp])
    176         {
    177             used[tmp] = true;
    178             tmp = b[tmp];
    179         }
    180     }
    181     return ret;
    182 
    183 }
    184 
    185 void rr3()
    186 {
    187     for(int i = 1;i <= 8;i++)
    188         c[i] = b[i];
    189         b[1] = c[4];
    190     for(int i = 2;i <= 4;i++)
    191         b[i] = c[i-1];
    192     b[5] = c[8];
    193     for(int i = 6;i <= 8;i++)
    194         b[i] = c[i-1];
    195 }
    196 void up3()
    197 {
    198     for(int i = 1;i <= 8;i++)
    199         c[i] = b[i];
    200     b[1]=c[4];
    201     b[5]=c[1];
    202     b[8]=c[5];
    203     b[4]=c[8];
    204     b[2]=c[3];
    205     b[3]=c[7];
    206     b[7]=c[6];
    207     b[6]=c[2];
    208 }
    209 int calc3()
    210 {
    211     memset(used,false,sizeof(used));
    212 
    213     int ret = 0;
    214     for(int i = 1;i <= 8;i++)
    215         if(!used[i])
    216     {
    217         ret++;
    218         int tmp = i;
    219         while(!used[tmp])
    220         {
    221             used[tmp] = true;
    222             tmp = b[tmp];
    223         }
    224     }
    225     return ret;
    226 
    227 }
    228 int num1[40];
    229 int num2[40];
    230 int num3[40];
    231 int num[40];
    232 int main()
    233 {
    234     //freopen("in.txt","r",stdin);
    235     //freopen("out.txt","w",stdout);
    236     int cnt = 0;
    237     for(int i = 0;i < 4;i++)
    238         for(int j = 0;j < 4;j++)
    239     {
    240         for(int x = 1;x <= 54;x++)
    241             b[x] = x;
    242         for(int x = 0;x < i;x++)
    243             up();
    244         for(int x = 0;x < j;x++)
    245             rr();
    246         num1[cnt++]=calc();
    247     }
    248     for(int x = 1;x <= 54;x++)
    249         b[x] = x;
    250     rr();
    251     for(int i = 0;i < 4;i++)
    252     {
    253         num1[cnt++]=calc();
    254         up();
    255     }
    256     for(int x = 1;x <= 54;x++)
    257         b[x] = x;
    258     rr();
    259     rr();
    260     rr();
    261     for(int i = 0;i < 4;i++)
    262     {
    263         num1[cnt++]=calc();
    264         up();
    265     }
    266     cnt = 0;
    267     for(int i = 0;i < 4;i++)
    268         for(int j = 0;j < 4;j++)
    269     {
    270         for(int x = 1;x <= 12;x++)
    271             b[x] = x;
    272         for(int x = 0;x < i;x++)
    273             up2();
    274         for(int x = 0;x < j;x++)
    275             rr2();
    276         num2[cnt++]=calc2();
    277         //printf("%d
    ",calc2());
    278     }
    279 
    280     for(int x = 1;x <= 12;x++)
    281         b[x] = x;
    282     rr2();
    283     for(int i = 0;i < 4;i++)
    284     {
    285         num2[cnt++]=calc2();
    286         up2();
    287     }
    288     for(int x = 1;x <= 12;x++)
    289             b[x] = x;
    290     rr2();
    291     rr2();
    292     rr2();
    293     for(int i = 0;i < 4;i++)
    294     {
    295         num2[cnt++]=calc2();
    296         up2();
    297     }
    298     cnt = 0;
    299     for(int i = 0;i < 4;i++)
    300         for(int j = 0;j < 4;j++)
    301     {
    302         for(int x = 1;x <= 8;x++)
    303             b[x] = x;
    304         for(int x = 0;x < i;x++)
    305             up3();
    306         for(int x = 0;x < j;x++)
    307             rr3();
    308         num3[cnt++]=calc3();
    309         //printf("%d
    ",calc3());
    310     }
    311     for(int x = 1;x <= 8;x++)
    312         b[x] = x;
    313     rr3();
    314     for(int i = 0;i < 4;i++)
    315     {
    316         num3[cnt++]=calc3();
    317         up3();
    318     }
    319     for(int x = 1;x <= 8;x++)
    320         b[x] = x;
    321     rr3();
    322     rr3();
    323     rr3();
    324     for(int i = 0;i < 4;i++)
    325     {
    326         num3[cnt++]=calc3();
    327         up3();
    328     }
    329     for(int i = 0;i < 24;i++)
    330         num[i] = num1[i]+num2[i]+num3[i];
    331     //for(int i = 0;i <24;i++)
    332    //     printf("%d
    ",num[i]);
    333     int T;
    334     scanf("%d",&T);
    335     int n ;
    336     int iCase = 0;
    337     while(T--)
    338     {
    339         iCase++;
    340         scanf("%d",&n);
    341         int ans = 0;
    342 
    343         for(int i = 0;i < 24;i++)
    344         {
    345             ans += pow_m(n,num[i]);
    346             ans %=MOD;
    347         }
    348         ans *= inv(24,MOD);
    349         ans %=MOD;
    350         printf("Case %d: %d
    ",iCase,ans);
    351     }
    352     return 0;
    353 }
  • 相关阅读:
    2017"百度之星"程序设计大赛
    2018省赛赛第一次训练题解和ac代码
    2018天梯赛第一次训练题解和ac代码
    rsa Round #71 (Div. 2 only)
    AtCoder Grand Contest 021
    Hello 2018
    Educational Codeforces Round 36 (Rated for Div. 2)
    Codeforces Round #462 (Div. 2)
    Codeforces Round #467 (Div. 2)
    [Offer收割]编程练习赛48
  • 原文地址:https://www.cnblogs.com/kuangbin/p/3231181.html
Copyright © 2020-2023  润新知