Palindrome graph

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1727    Accepted Submission(s): 525

Problem Description
In addition fond of programing, Jack also loves painting. He likes to draw many interesting graphics on the paper.
One day,Jack found a new interesting graph called Palindrome graph. No matter how many times to flip or rotate 90 degrees, the palindrome graph are always unchanged.
Jack took a paper with n*n grid and K kinds of pigments.Some of the grid has been filled with color and can not be modified.Jack want to know:how many ways can he paint a palindrome graph?
 
Input
There are several test cases.
For each test case,there are three integer n m k(0<n<=10000,0<=m<=2000,0<k<=1000000), indicate n*n grid and k kinds of pigments.
Then follow m lines,for each line,there are 2 integer i,j.indicated that grid(i,j) (0<=i,j<n) has been filled with color.
You can suppose that jack have at least one way to paint a palindrome graph.
 
Output
For each case,print a integer in a line,indicate the number of ways jack can paint. The result can be very large, so print the result modulo 100 000 007.
 
Sample Input
3 0 2
4 2 3
1 1
3 1
 
Sample Output
8
3
 
Author
FZU
 
Source
 
 
题目大意:给出了回文图的定义,即前后翻转或者旋转90度不改变图的样子。给你n,m,k分别表示有n*n的格子图,有m个格子已经涂上颜色,现在有k种颜色用来涂满剩余的格子(其实并没有在题中读到这个意思,是看别人博客这么解释的),问有多少涂法。(其实题意感觉不是很清楚)。
 
解题思路:分析n*n的方格,我们只要分析出1/8的方格情况就行了。我们选择分析左上角上方的三角形,我们发现有1+2+3...+(n+1)/2个方格可能需要涂色。但是有m个方格已经涂了颜色,那么我们把所有可以通过转动能转到我们分析的三角形中的已涂色的格子的坐标化成在三角形中的坐标,可以先全化成左上角的大方格中,再化成上方的三角形中。对于涂色方案:k^x。k为给的涂料种数,x为左上角上方的三角形中可以任意涂色的格子个数(只要有部分格子在三角形中,该格子就算是在三角形中了)。
 
#include<bits/stdc++.h>
using namespace std;
const int mod=1e8+7;
typedef __int64 INT;
map<pair<int,int>,int>mp;
int Pow(INT x,int nn){
INT ret=1;
while(nn){
if(nn&1)
ret=ret*x%mod;
x=x*x%mod;
nn>>=1;
}
return ret;
}
int main(){
int n,m,k,x,y;
while(scanf("%d%d%d",&n,&m,&k)!=EOF){
mp.clear();
int pted=0,cnt=0;
while(m--){
scanf("%d%d",&x,&y);
if(x>n-1-x){ //坐标转化成三角形中的对称坐标
x=n-1-x;
}
if(y>n-1-y){
y=n-1-y;
}
if(x>y){
swap(x,y);
}
if(mp[make_pair(x,y)]==0){
mp[make_pair(x,y)]=1;
pted++;//已经涂过色的
}
}
int cc=(n+1)/2;
cnt=(cc+1)*cc/2; //三角形中的总格子数
INT ans=Pow((INT)k,(cnt-pted));
printf("%I64d\n",ans);
}
return 0;
}

  

HDU 4365——Palindrome graph——————【规律+快速幂】的更多相关文章

  1. HDU.1575 Tr A ( 矩阵快速幂)

    HDU.1575 Tr A ( 矩阵快速幂) 点我挑战题目 题意分析 直接求矩阵A^K的结果,然后计算正对角线,即左上到右下对角线的和,结果模9973后输出即可. 由于此题矩阵直接给出的,题目比较裸. ...

  2. hdu 3117 Fibonacci Numbers 矩阵快速幂+公式

    斐波那契数列后四位可以用快速幂取模(模10000)算出.前四位要用公式推 HDU 3117 Fibonacci Numbers(矩阵快速幂+公式) f(n)=(((1+√5)/2)^n+((1-√5) ...

  3. HDU 5793 A Boring Question (找规律 : 快速幂+逆元)

    A Boring Question 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5793 Description Input The first l ...

  4. hdu 5187 zhx's contest [ 找规律 + 快速幂 + 快速乘法 || Java ]

    传送门 zhx's contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  5. HDU 5607 graph 矩阵快速幂 + 快速幂

    这道题得到了学长的助攻,其实就是一个马尔科夫链,算出一步转移矩阵进行矩阵快速幂就行了,无奈手残 这是我第一回写矩阵快速幂,写的各种毛病,等到调完了已经8点44了,交了一发,返回PE,(发现是少了换行) ...

  6. HDU 2842 (递推+矩阵快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2842 题目大意:棒子上套环.第i个环能拿下的条件是:第i-1个环在棒子上,前i-2个环不在棒子上.每个 ...

  7. HDU - 1005 Number Sequence 矩阵快速幂

    HDU - 1005 Number Sequence Problem Description A number sequence is defined as follows:f(1) = 1, f(2 ...

  8. hdu 2604 Queuing(矩阵快速幂乘法)

    Problem Description Queues and Priority Queues are data structures which are known to most computer ...

  9. ACM-ICPC 2018 焦作赛区网络预赛 G. Give Candies (打表找规律+快速幂)

    题目链接:https://nanti.jisuanke.com/t/31716 题目大意:有n个孩子和n个糖果,现在让n个孩子排成一列,一个一个发糖果,每个孩子随机挑选x个糖果给他,x>=1,直 ...

随机推荐

  1. MySQL - ODBC安装错误问题!

    MySQL的ODBC安装时候可能会出错,主要原因是缺少VC支持库,需要2010版本的VC支持库!!X86和X64分别对应MySQL对应的ODBC,不能安装一个两个都搞定,如果需要安装两个ODBC驱动, ...

  2. Category 分类

    1.Category 1)分类/类别(category): 允许以模块的方式向现有类定义添加新的方法(默认不能添加实例变量).用以扩展自己或他人以前实现的类,使它适合自己的需要. 分类的名称括在类名之 ...

  3. java基础之流程控制语句

    一.     分支 1.      三元运算符 ?: 注意:三元运算符虽然简洁但是语法乱,而且必须要有接受者或者直接打印 1.     if else语句 另一种不带括号的写法: if(条件) 语句1 ...

  4. Java与其它语言的比较

    Java与C/C++相比.Java语言是一种完全的面对对象语言,虽然他的底层(运行时库)是用C语言开发 的,可是并不依赖于C.因为Java的运行是在运行时库的支持下运行的,所以运行的效率比起可以更接近 ...

  5. bzoj3328: PYXFIB(单位根反演+矩阵快速幂)

    题面 传送门 题解 我们设\(A=\begin{bmatrix}1 & 1 \\ 1 & 0\end{bmatrix}\),那么\(A^n\)的左上角就是\(F\)的第\(n\)项 所 ...

  6. Python列表知识补充

    1.import this  Python之禅,圣经. >>> import this The Zen of Python, by Tim Peters Beautiful is b ...

  7. DP【洛谷P4290】 [HAOI2008]玩具取名

    P4290 [HAOI2008]玩具取名 某人有一套玩具,并想法给玩具命名.首先他选择WING四个字母中的任意一个字母作为玩具的基本名字.然后他会根据自己的喜好,将名字中任意一个字母用"WI ...

  8. CF581B Luxurious Houses 模拟

    The capital of Berland has n multifloor buildings. The architect who built up the capital was very c ...

  9. [USACO08OPEN]农场周围的道路Roads Around The Farm BZOJ 1621 DFS

    Farmer John's cows have taken an interest in exploring the territory around the farm. Initially, all ...

  10. 查看和导入证书(.cer / .pfx)

    作为文件形式存在的证书一般有这几种格式: 1.带有私钥的证书 由Public Key Cryptography Standards #12,PKCS#12标准定义,包含了公钥和私钥的二进制格式的证书形 ...