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数据库

    本篇内容介绍的是如何在控制台下使用MySQL数据库.首先需要安装MySQL数据库应用程序,然后找到MySql的Command Line Client进入之后你会看到,此处需要正确输入密码,否则会直接退 ...

  2. 使用pycharm创建自己的第一个django项目

    PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具,比如调试.语法高亮.Project管理.代码跳转.智能提示.自动完成.单元测试.版本控制. ...

  3. UITableView 编辑模式(增加-删除-移动---自定义左滑 title) xib cell

    参考:  http://www.open-open.com/lib/view/open1430008922468.html - (void)viewDidLoad { [super viewDidLo ...

  4. 分析mybatis和jdbc的作用,已经原理

    从jdbc的操作数据库来看:主要分为几步: 1 注冊载入JDBC驱动程序: 2 得到连接对象 Connection 3 创建 Statement对象 4 运行sql语句 5 处理结果 6 关闭资源释放 ...

  5. beego 连接postgres

    package main import ( "fmt" "github.com/astaxie/beego/orm" "mybee/models&qu ...

  6. webpack基础理解以及使用搭建

    1.webpack 是一个前端资源加载/打包工具,前端的常用资源都可以作为一个模板导出,我们在代码中直接引用即可,最后把我们的代码打包整合起来. 前端资源,包括(js,css,图片,模块)等. 下面是 ...

  7. appium环境配置和一个例子

    最近觉得appium挺火的,看了一些资料,本来想使用npm在线安装,遇见各种问题,先简单说一下: 在cmd窗口中使用命令:npm install -g appium安装,报无python的error, ...

  8. 小聊outline和border

    border与outline: border属性: border-width.border-style.border-color 其中border-style可以为none或hidden outlin ...

  9. Spring Security获取已登录的用户信息的两种方法

    第一种是直接从session中手动拿: @RequestMapping(value = "/user", method = RequestMethod.GET)public Res ...

  10. Es6中Map对象和Set对象的介绍及应用

    map和set的方法,工作中有使用到,所以学习一下: Map 对象 Map 对象保存键值对.任何值(对象或者原始值) 都可以作为一个键或一个值. var myMap = new Map(); myMa ...