hdu4365 Palindrome graph
Palindrome graph
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2118 Accepted Submission(s): 664Problem DescriptionIn 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?InputThere 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.OutputFor
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 Input3 0 24 2 31 13 1Sample Output83
1 #include<iostream>
2 #include<bits/stdc++.h>
3 #define MOD 100000007
4 using namespace std;
5 //map < pair <int ,int > ,int > mp; 既可以用mp来找,也可以用数组。测试表明,map内存开销更小
6 bool a[5050][5050]; //由于内存限制,数组开1/4大小就行
7 int cnt=0;
8 int quick_pow(int k,int x){
9 long long ans=1,base=k;
10 while(x!=0){
11 if(x&1==1){
12 ans=(ans*base)%MOD;
13 }
14 base=(base*base)%MOD;
15 x>>=1;
16 }
17 return (int)ans%MOD;
18 }
19 void change(int x,int y,int n){ //投影到同一区域
20 if(x>n-1-x){
21 x=n-1-x;
22 }
23 if(y>n-1-y){
24 y=n-1-y;
25 }
26 if(x>y){ //翻转操作
27 swap(x,y);
28 }
29 if(a[x][y]==0){
30 cnt++;
31 a[x][y]=1;
32 }
33 }
34 int main(){
35 int n,m,k;
36 while(scanf("%d%d%d",&n,&m,&k)!=EOF){
37 cnt=0;
38 //mp.clear();
39 memset(a,0,sizeof(a));
40 while(m--){
41 int x,y;
42 scanf("%d%d",&x,&y);
43 change(x,y,n);
44 }
45 int sum=0;
46 if(n%2==0){
47 sum=((1+n/2)*(n/2))/2;
48 }else{
49 sum=((1+(n+1)/2)*((n+1)/2))/2;
50 }
51 cout<<quick_pow(k,sum-cnt)<<endl;
52 }
53 return 0;
54 }
hdu4365 Palindrome graph的更多相关文章
- HDU 4365——Palindrome graph——————【规律+快速幂】
Palindrome graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 2012 Multi-University #7
最短路+拆点 A As long as Binbin loves Sangsang 题意:从1走到n,每次都是LOVE,问到n时路径是连续多个"LOVE"的最短距离.秀恩爱不想吐槽. 分析:在普通的最 ...
- 2012 Multi-University Training Contest 7
2012 Multi-University Training Contest 7 A.As long as Binbin loves Sangsang B.Dead or alive C.Dragon ...
- 【LeetCode OJ】Palindrome Partitioning
Problem Link: http://oj.leetcode.com/problems/palindrome-partitioning/ We solve this problem using D ...
- [开发笔记] Graph Databases on developing
TimeWall is a graph databases github It be used to apply mathematic model and social network with gr ...
- PALIN - The Next Palindrome 对称的数
A positive integer is called a palindrome if its representation in the decimal system is the same wh ...
- Introduction to graph theory 图论/脑网络基础
Source: Connected Brain Figure above: Bullmore E, Sporns O. Complex brain networks: graph theoretica ...
- POJ 2125 Destroying the Graph 二分图最小点权覆盖
Destroying The Graph Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8198 Accepted: 2 ...
- [LeetCode] Longest Palindrome 最长回文串
Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...
- [LeetCode] Palindrome Pairs 回文对
Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that t ...
随机推荐
- 分布式测试插件 pytest-xdist 使用详解
使用背景: 大型测试套件:当你的测试套件非常庞大,包含了大量的测试用例时,pytest-xdist可以通过并行执行来加速整体的测试过程.它利用多个进程或计算机的计算资源,可以显著减少测试执行的时间. ...
- ios添加库文件
- CI框架的base_url localhost [::1]等问题
为什么localhost变成了[::1] [::1]是IP6的地址, 与localhost等价 使用base_url后, 加载不了样式 ci框架需要定义base_url, 未定义就会出现返回local ...
- IPv6的基本认识
IPv6 1.IPv6的基本认识 IPv4 位数是 32位,4字节,能够提供的IP地址大约是42亿,但你知道的,如今一个人都不止一个IP地址,看看如今设备的数量及发展速度就知道,所以有了IPv6,IP ...
- salesforce零基础学习(一百三十二)Flow新功能: Custom Error
本篇参考: https://help.salesforce.com/s/articleView?id=sf.flow_ref_elements_custom_error.htm&type=5 ...
- ChatGPT API Transition Guide
ChatGPT API Transition Guide How to get started Written by Joshua J.. Updated over a week ago Prompt ...
- macbook-键盘连击问题002
https://support.apple.com/zh-cn/HT205662 如何清洁 MacBook 或 MacBook Pro 的键盘 如果您的 MacBook(2015 年及更新机型)或 M ...
- 使用CEF(六)— 解读CEF的cmake工程配置
距离笔者的<使用CEF>系列的第一篇文章居然已经过去两年了,在这么长一段时间里,笔者也写了很多其它的文章,再回看<使用CEF(一)- 起步>编写的内容,文笔稚嫩,内容单薄是显而 ...
- 随身wifi 救砖过程记录
7,8块钱买了个随身wifi,准备刷机玩的,后来不知道刷错了boot还是啥,加电后灯都不亮了,前期没备份,于是网上找了各种教程,下面记录下: 变砖后有个底层的9008驱动协议可以刷机,下面的过程都是基 ...
- Redis 6 学习笔记 3 —— 用SpringBoot整合Redis的踩坑,了解事务、乐观锁、悲观锁
SpringBoot整合Redis时踩到的坑 jdk1.8环境,用idea的Spring Initializr创建spring boot项目,版本我选的2.7.6.pom文件添加的依赖如下,仅供参考. ...