Count the Tetris

2024-03-16 23:38
文章标签 count tetris

本文主要是介绍Count the Tetris,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Count the Tetris

题解

这是一道很经典的Burnside的题目。

我们很容易发现对于一个长度为n的环,需要一个置换中的不动点满足它的所有循环中的点颜色相同,那么在旋转i次的置换中,循环共有\left(n,i \right )个。由于后面的循环都是重复的我们只需计算\left(n,i \right )这段的染色方案即可。

看到题目限制,如果直接统计的话肯定会T,所以需要用矩阵乘法来进行统计。

考虑n特别大的范围,还需要欧拉函数对其进行优化,枚举置换的循环节个数i,与其等价的置换群共有\varphi\left(\frac{n}{i} \right )个,需要再将其乘上去,而我们只需要枚举n的因数来进行计算。

源码

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
#define MAXN 40010
typedef long long LL;
//#define int LL
typedef pair<int,int> pii;
const int mo=9973;
#define gc() getchar()
template<typename _T>
void read(_T &x){_T f=1;x=0;char s=gc();while(s>'9'||s<'0'){if(s=='-')f=-1;s=gc();}while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=gc();}x*=f;
}
template<typename _T>
_T Fabs(_T x){return x<0?-x:x;}
int prime[MAXN],cntp,n,m,k;
bool oula[MAXN];
struct Matrix{int c[15][15];//Matrix(){memset(c,0,sizeof(0));}/*Martix operator * (const Martix &b)const{Martix res;for(int i=0;i<m;i++)for(int k=0;k<m;k++)if(c[i][k])for(int j=0;j<m;j++)(res.c[i][j]+=c[i][k]*b.c[k][j]%mo)%mo;return res;}*/
}mat;
Matrix mult(Matrix ta,Matrix tb){Matrix tc;memset(tc.c,0,sizeof(tc.c));for(int i=0;i<m;i++)for(int k=0;k<m;k++)if(ta.c[i][k])for(int j=0;j<m;j++)(tc.c[i][j]+=ta.c[i][k]*tb.c[k][j])%=mo;return tc;
}
Matrix Matpow(Matrix a,int s){Matrix t;memset(t.c,0,sizeof(t.c));for(int i=0;i<m;i++)t.c[i][i]=1;while(s){if(s&1)t=mult(t,a);a=mult(a,a);s>>=1;}return t;
}
int qkpow(int a,int s){int t=1;a%=mo;while(s){if(s&1)t=t*a%mo;a=a*a%mo;s>>=1;}return t;
}
void init(){for(int i=2;i<=4e4;i++){if(oula[i])continue;prime[cntp++]=i;for(int j=i*i;j<=4e4;j+=i)oula[j]=1;}
}
int euler(int cur){int ans=cur,x=cur;for(int i=0;i<cntp&&prime[i]*prime[i]<=cur;i++)if(x%prime[i]==0){ans=ans/prime[i]*(prime[i]-1);while(x%prime[i]==0)x/=prime[i];}if(x>1)ans=ans/x*(x-1);return ans%mo;
}
int cal(int len){int res=0;Matrix t=Matpow(mat,len);for(int i=0;i<m;i++)(res+=t.c[i][i])%=mo;return res;
}
int Polya(){int ans=0;for(int i=1;i*i<=n;i++){if(n%i)continue;if(i*i==n)(ans+=cal(i)*euler(i))%=mo;else (ans+=cal(i)*euler(n/i)+cal(n/i)*euler(i))%=mo;//printf("%d:%d\n",i,ans);}return ans*qkpow(n,mo-2)%mo;
}
signed main(){int T;read(T);init();while(T--){read(n);read(m);read(k);for(int i=0;i<m;i++)for(int j=0;j<m;j++)mat.c[i][j]=1;for(int i=1;i<=k;i++){int u,v;read(u);read(v);mat.c[u-1][v-1]=mat.c[v-1][u-1]=0;}printf("%d\n",Polya());}return 0;
}

 

这篇关于Count the Tetris的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/817118

相关文章

leetcode#38. Count and Say

The count-and-say sequence is the sequence of integers with the first five terms as following: 1. 12. 113. 214. 12115. 111221 1 is read off as “one 1” or 11. 11 is read off

《Learning To Count Everything》CVPR2021

摘要 论文提出了一种新的方法来解决视觉计数问题,即在给定类别中仅有少量标注实例的情况下,对任何类别的对象进行计数。将计数问题视为一个少样本回归任务,并提出了一种新颖的方法,该方法通过查询图像和查询图像中的少量示例对象来预测图像中所有感兴趣对象的存在密度图。此外,还提出了一种新颖的适应策略,使网络能够在测试时仅使用新类别中的少量示例对象来适应任何新的视觉类别。为了支持这一任务,作者还引入了一个包含

class _ContiguousArrayStorage deallocated with non-zero retain count

Xcode报错 : Object 0x11c614000 of class _ContiguousArrayStorage deallocated with non-zero retain count 2. This object's deinit, or something called from it, may have created a strong reference to self w

LeetCode - 38. Count and Say

38. Count and Say  Problem's Link  ---------------------------------------------------------------------------- Mean:  题目意思太晦涩。 1 读出来 就是“1个1” 所以记为“11” 11 读出来 就是“2个1” 所以记为“21” 21 读出来 就是“1个

【FZU】2105 Digits Count 线段树

传送门:【FZU】2105 Digits Count 题目分析:与、或、异或三种操作都是每一位相互独立的,所以可以将线段树建四棵,分别对应一位,and和or操作相当于覆盖操作,xor操作相当于反转操作,就和普通的线段树方法类似,设立两个lazy标记即可。查询的时候求得每一位的1的个数*权重(1,2,4,8),全部累加就是答案。 代码如下: #include <cst

CodeForces 451D Count Good Substrings

题意: 一个只包含a和b的字符串  问  它有几个长度为偶数和长度为奇数的“压缩回文串”  压缩的概念是  相邻的相同字符压缩成一个字符 思路: 串经过压缩一定满足如下形式 ……ababab……  那么这样只要两端的字符相同则中间一定是回文的  因此对于一个a它作为左端点形成的回文串个数就等于它右边的a的个数  那么长度是奇数还是偶数呢  可以这么判断  如果a在奇数位置上和它匹配的a也在奇

Count Palindrome in String

string 有多少palindrome substring。exp: 'aba' 返回4 , 'abba' 返回6 public class CountPalindrome {public int countPalindrome(String str){if(str == null || str.length() == 0) return 0;int count = 0;for(int

用 count(*)哪个存储引擎会更快?

InnoDB 引擎执行 count 函数的时候,需要通过遍历的方式来统计记录个数,而 MyISAM 引擎执行 count 函数只需要 0(1 )复杂度,这是因为每张 MyISAM 的数据表都有一个 meta 信息有存储了row_count值,由表级锁保证一致性,所以直接读取row_count 值就是 count 函数的执行结果 而 InnoDB 存储引擎是支持事务的,同一个时刻的多个查询,由

c++ unordered_set的count方法

在 C++ 的 std::unordered_set 中,count 方法用于返回集合中与指定值相等的元素的数量。由于 unordered_set 的特性是只允许唯一元素,因此对于任何给定元素,count 方法的返回值只能是 0 或 1。 语法 size_t count(const Key& key) const; key: 要查找的元素。返回值: 如果集合中存在这个元素,返回 1;如果不

Leetcode 3272. Find the Count of Good Integers

Leetcode 3272. Find the Count of Good Integers 1. 解题思路2. 代码实现 题目链接:3272. Find the Count of Good Integers 1. 解题思路 这一题我思路上是比较暴力的,就是典型地分步骤执行: 找出所有的可能构成回文的长度为n的字符组合对于任意字符组合,判断其是否可以构成一个被k整除的回文序列考察这个字符组