HDU 4365 Palindrome graph(几何变换+快速幂)
来源:互联网 发布:red hat linux 6.0 编辑:程序博客网 时间:2024/05/22 02:15
HDU 4365
题意:给你一个n*n的画,然后每个格子图上任意k种颜色之一,要求通过翻转旋转后与原图保持一致,且原图已有m个格子有颜色。求有多少种涂法?
思路:
可以发现,我们所求的画是个高度轴对称和中心对称的图形,我们沿两根对称轴与两根中心对称轴把图案切成八份,那么决定其涂色方案只需考虑其中一份即可,若其中一份有x个格子那么答案即是k^x。
然而还有一个条件,即已经有m个格子涂上了颜色,那么我们将m个格子映射至之前选择的八分之一区域内,表明该格子颜色已固定,假设有y个格子颜色已固定,那么答案即是k^(x-y)。
求答案的过程中记得使用快速幂。。以及注意mod = 1e8+7,不是1e9+7..
code:
/** @author Novicer* language : C++/C*/#include<iostream>#include<sstream>#include<fstream>#include<vector>#include<list>#include<deque>#include<queue>#include<stack>#include<map>#include<set>#include<bitset>#include<algorithm>#include<cstdio>#include<cstdlib>#include<cstring>#include<cctype>#include<cmath>#include<ctime>#include<iomanip>#define INF 2147483647#define cls(x) memset(x,0,sizeof(x))#define rise(i,a,b) for(int i = a ; i <= b ; i++)using namespace std;const double eps(1e-8);typedef long long lint;const int maxm = 10000 + 5;const lint mod = 1e8 + 7;lint n,m,k;map<lint , int> mp;lint ans;lint fast_pow(lint n , lint k){lint res = 1;while(k > 0){if(k&1) res = (res * n) % mod;k >>= 1;n = (n * n) % mod;}return res;}void change(int &x , int &y){while(1){if(x >= 0 && y >= 0 && x <= y && x <= n/2 && y <= n/2) break;if(x > n/2 && y > n/2){x = n - x + 1;y = n - y + 1;}if(x <= n/2 && y > n/2){y = n - y + 1;}if(x > n/2 && y <= n/2){x = n - x + 1;}if(x > y) swap(x,y);}}void solve(){mp.clear();if(n&1){ans = (n/2 + 2) * (n/2 + 1) / 2;}else ans = (n/2) * (n/2 + 1) / 2;for(int i = 1 ; i <= m ; i++){int x , y;scanf("%d%d",&x,&y);x++;y++;change(x,y);if(!mp[x + 10000*y]){mp[x + 10000*y] = 1;ans --;}}ans = fast_pow(k, ans) % mod;cout << ans << endl;}int main(){while(cin >> n >> m >> k){solve();}return 0;}
0 0
- HDU 4365 Palindrome graph(几何变换+快速幂)
- HDU 4365 - Palindrome graph
- HDU 4365 - Palindrome graph
- hdu 4365 Palindrome graph
- HDU 4365Palindrome graph(找规律 快速幂取模)
- HDU 4365 Palindrome graph 模拟题
- HDU 5507 Graph(dp + 矩阵快速幂)
- HDU 5607 graph(概率DP+矩阵快速幂)
- HDU 5607graph(矩阵快速幂)
- hdu 1700 (计算几何 向量的坐标变换)
- HDU 4998 Rotate (二维图形几何变换)
- HDU 4998 Rotate (几何变换——旋转)
- HDU 6061 快速数论变换
- HDU 5829 快速数论变换
- 几何变换(二维、三维)
- OpenGL图形变换——几何变换(世界变换)
- 几何变换
- 几何变换
- error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
- 给出现el表达式异常,但自我检查没有发现任何问题的朋友的忠告
- 职责链模式
- 【asp】Jmail组件发邮件
- iOS在照片上添加水印
- HDU 4365 Palindrome graph(几何变换+快速幂)
- hdu 5311 Hidden String(水)
- The Accomodation of Students
- 读书笔记-《 我的成功可以复制》二
- Maximal Square
- 模板-高斯消元(hihocoder 1195)
- spring mvc框架中创建验证码
- 最大和
- redis分析-SDS