17青岛现场赛polya计数
转自https://www.cnblogs.com/Just--Do--It/p/7806923.html
1 #include <bits/stdc++.h> 2 using namespace std; 3 #define LL long long 4 #define LLL __int128 5 const int maxn = 1010; 6 int tr[4][30] = { 7 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29}, 8 {6, 3, 0, 7, 4, 1, 8, 5, 2, 15, 12, 9, 16, 13, 10, 17, 14, 11, 27, 28, 29, 18, 19, 20, 21, 22, 23, 24, 25, 26}, 9 {15, 16, 17, 12, 13, 14, 9, 10, 11, 6, 7, 8, 3, 4, 5, 0, 1, 2, 26, 25, 24, 23, 22, 21, 20, 19, 18, 29, 28, 27}, 10 {0, 1, 17, 3, 4, 14, 6, 7, 11, 9, 10, 8, 12, 13, 5, 15, 16, 2, 18, 19, 24, 23, 22, 21, 20, 25, 26, 27, 28, 29} 11 }; 12 int temp[30]; 13 int ans[maxn * 100][30]; 14 int cnt; 15 int vis[30]; 16 int C[maxn]; 17 void dfs(int cur){ 18 for(int k = 1; k <= 3; k++){ 19 for(int i = 0; i < 30; i++){ 20 temp[i] = ans[cur][tr[k][i]]; 21 } 22 int flag = 1; 23 for(int i = 0; i <= cnt; i++){ 24 int vis = 1; 25 for(int j = 0; j < 30; j++){ 26 if(ans[i][j] != temp[j]) vis = 0; 27 if(!vis) break; 28 } 29 if(vis){ 30 flag = 0; 31 break; 32 } 33 } 34 if(flag){ 35 cnt++; 36 for(int i = 0; i < 30; i++){ 37 ans[cnt][i] = temp[i]; 38 } 39 dfs(cnt); 40 } 41 } 42 } 43 void init(){ 44 cnt = 0; 45 for(int i = 0; i < 30; i++) ans[0][i] = tr[0][i]; 46 dfs(0); 47 for(int i = 0; i <= cnt; i++){ 48 int cir = 0; 49 memset(vis, 0, sizeof(vis)); 50 for(int j = 0; j < 30; j++){ 51 if(!vis[j]){ 52 vis[j] = 1; 53 int u = ans[i][j]; 54 while(!vis[u]){ 55 vis[u] = 1; 56 u = ans[i][u]; 57 } 58 cir++; 59 } 60 } 61 C[cir]++; 62 } 63 //cout<<cnt + 1<<endl; 64 //for(int i = 0; i < 32; i++) if(C[i]) printf("C[%d] = %d ", i, C[i]); 65 } 66 LLL quickpow(LLL a, LLL b, LLL mod){ 67 LLL temp = a % mod, res = 1; 68 while(b){ 69 if(b & 1) res = res * temp % mod; 70 b >>= 1; 71 temp = temp * temp % mod; 72 } 73 return res; 74 } 75 int main(){ 76 init(); 77 LL c, p; 78 int t; 79 scanf("%d", &t); 80 while(t--){ 81 scanf("%lld %lld", &c, &p); 82 LLL tot = cnt + 1; 83 LLL sum = 0; 84 LLL mod = p * tot; 85 for(int i = 0; i < 32; i++){ 86 if(C[i]){ 87 sum = sum + quickpow(c, i, mod) * C[i] % mod; 88 sum %= mod; 89 } 90 } 91 printf("%lld ", (LL)(sum / tot)); 92 } 93 }
DIY Cube
1 #include <bits/stdc++.h> 2 using namespace std; 3 #define LL long long 4 const int maxn = 1010; 5 int tr[4][8] = { 6 {0, 1, 2, 3, 4, 5, 6, 7}, 7 {4, 5, 0, 1, 6, 7, 2, 3}, 8 {2, 0, 3, 1, 6, 4, 7, 5}, 9 {1, 5, 3, 7, 0, 4, 2, 6} 10 }; 11 int temp[10]; 12 int ans[maxn * 100][10]; 13 int cnt; 14 int vis[10]; 15 int C[maxn]; 16 void dfs(int cur){ 17 for(int k = 1; k <= 3; k++){ 18 for(int i = 0; i < 8; i++){ 19 temp[i] = ans[cur][tr[k][i]]; 20 } 21 int flag = 1; 22 for(int i = 0; i <= cnt; i++){ 23 int vis = 1; 24 for(int j = 0; j < 8; j++){ 25 if(ans[i][j] != temp[j]) vis = 0; 26 if(!vis) break; 27 } 28 if(vis){ 29 flag = 0; 30 break; 31 } 32 } 33 if(flag){ 34 cnt++; 35 for(int i = 0; i < 8; i++){ 36 ans[cnt][i] = temp[i]; 37 } 38 dfs(cnt); 39 } 40 } 41 } 42 int main(){ 43 cnt = 0; 44 for(int i = 0; i < 8; i++) ans[0][i] = tr[0][i]; 45 dfs(0); 46 for(int i = 0; i <= cnt; i++){ 47 int cir = 0; 48 memset(vis, 0, sizeof(vis)); 49 for(int j = 0; j < 8; j++){ 50 if(!vis[j]){ 51 vis[j] = 1; 52 int u = ans[i][j]; 53 while(!vis[u]){ 54 vis[u] = 1; 55 u = ans[i][u]; 56 } 57 cir++; 58 } 59 } 60 C[cir]++; 61 } 62 for(int i = 0; i < 10; i++) if(C[i]) printf("C[%d] = %d ", i, C[i]); 63 cout<<cnt + 1<<endl; 64 }
1 /************************************************************************* 2 > File Name: Main.java 3 > Author: yijiull 4 > Mail: 1147161372@qq.com 5 > Created Time: 2017年11月08日 星期三 22时35分25秒 6 ************************************************************************/ 7 import java.math.*; 8 import java.util.*; 9 import java.io.*; 10 public class Main{ 11 public static void main(String argsp[]){ 12 Scanner cin = new Scanner(System.in); 13 int t = cin.nextInt(); 14 BigInteger m = new BigInteger("1000000000000000"); 15 for(int k = 1; k <= t; k++){ 16 BigInteger c = cin.nextBigInteger(); 17 BigInteger ans = BigInteger.ZERO; 18 ans = ans.add(c.pow(2).multiply(BigInteger.valueOf(6))); 19 ans = ans.add(c.pow(4).multiply(BigInteger.valueOf(17))); 20 ans = ans.add(c.pow(8)); 21 ans = ans.divide(BigInteger.valueOf(24)); 22 System.out.print("Case " + k + ": "); 23 if(ans.compareTo(m) > 0){ 24 ans = ans.mod(m); 25 for(int i = ans.toString().length(); i < 15; i++){ 26 System.out.print(0); 27 } 28 } 29 System.out.println(ans); 30 31 } 32 } 33 }