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. 泛型List<T>转存为XML文档

    经常会有这情况,在程序处理结果为泛型List<T>,但为了能把这些集合输出XML文档.Insus.NET就因此问题,演示一个范例.在程序中,创建一个类: List<T>的集合手 ...

  2. javascript 实现类似百度联想输入,自动补全功能

    js  实现类似百度联想输入,自动补全功能 方案一: search是搜索框id="search" //点击页面隐藏自动补全提示框 document.onclick = functi ...

  3. 51nod1244 莫比乌斯函数之和(杜教筛)

    题面 传送门 题解 我--我忘记把预处理的块的大小调成\(n^{\frac{2}{3}}\)了--(仰天) 首先\(\mu*1=e\) 然后杜教筛就行了 //minamoto #include< ...

  4. django 学习之DRF (一)

    Django框架基础DRF-01 前后端分离介绍 1.前后端不分离图解 2.前后端分离图解     3.为什么要学习DRF    DRF可以帮助我们开发者快速的开发⼀个依托于Django的前后后端分离 ...

  5. [比赛|考试]nowcoder NOIP提高组组第二场

    160/300pts,rank16(100,30,30) 在自身找毛病,首先做题感觉还不不够认真,比如T3那个我一开始审出来了,然后tmd忘了...gg...T1AC没啥好赞美的,T2T3暴力没拿全啊 ...

  6. php屏蔽错误消息

    定义和用法: error_reporting() 设置 PHP 的报错级别并返回当前级别. 函数语法: error_reporting(report_level) 如果参数 level 未指定,当前报 ...

  7. 在服务器上使用 gradle 打包 android 源码

    安装 android-tools mkdir ~/android && cd ~/android   wget https://dl.google.com/android/reposi ...

  8. tomcat使用不同的jdk版本 liunx 装两个jdk

    原作者文章 https://blog.csdn.net/qq_34626097/article/details/83385219 看了原作者学会的!上面链接 因为公司的服务器里面是jdk1.7和tom ...

  9. Codeforce-A-Two distinct points(暴力)

    output standard output You are given two segments [l1;r1][l1;r1] and [l2;r2][l2;r2] on the xx-axis. ...

  10. P1111 修复公路(并查集)

    题目背景 AA地区在地震过后,连接所有村庄的公路都造成了损坏而无法通车.政府派人修复这些公路. 题目描述 给出A地区的村庄数NN,和公路数MM,公路是双向的.并告诉你每条公路的连着哪两个村庄,并告诉你 ...