Palindrome graph

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

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
 题意:求出一个回文图的种类。给出了回文图的定义,即前后翻转或者旋转90度不改变图的样子。给你n,m,k分别表示有n*n的格子图,有m个格子已经涂上颜色,现在有k种颜色用来涂满剩余的格子,问有多少涂法。
解题思路:关键在于怎么将已经涂了色的点投影到同一个区域的。(因为图可以旋转翻转,我们发现是1/8的区域)。然后统计有多少个点已经上了色。剩下的点就是可以用k种颜色涂的了。由组合数学可做即求k的n次幂取1e+7的模
AC代码:
 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的更多相关文章

  1. HDU 4365——Palindrome graph——————【规律+快速幂】

    Palindrome graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. 2012 Multi-University #7

    最短路+拆点 A As long as Binbin loves Sangsang 题意:从1走到n,每次都是LOVE,问到n时路径是连续多个"LOVE"的最短距离.秀恩爱不想吐槽. 分析:在普通的最 ...

  3. 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 ...

  4. 【LeetCode OJ】Palindrome Partitioning

    Problem Link: http://oj.leetcode.com/problems/palindrome-partitioning/ We solve this problem using D ...

  5. [开发笔记] Graph Databases on developing

    TimeWall is a graph databases github It be used to apply mathematic model and social network with gr ...

  6. PALIN - The Next Palindrome 对称的数

    A positive integer is called a palindrome if its representation in the decimal system is the same wh ...

  7. Introduction to graph theory 图论/脑网络基础

    Source: Connected Brain Figure above: Bullmore E, Sporns O. Complex brain networks: graph theoretica ...

  8. POJ 2125 Destroying the Graph 二分图最小点权覆盖

    Destroying The Graph Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8198   Accepted: 2 ...

  9. [LeetCode] Longest Palindrome 最长回文串

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

  10. [LeetCode] Palindrome Pairs 回文对

    Given a list of unique words. Find all pairs of distinct indices (i, j) in the given list, so that t ...

随机推荐

  1. 简单聊一聊SpringBoot的约定优于配置

    Spring Boot的约定优于配置 对于今天聊的SpringBoot的约定优于配置,我打算从三个方面去展开: 1.什么是约定优于配置 1> 约定优于配置是一种软件设计的范式,其核心思想:使用一 ...

  2. 2.12 PE结构:实现PE字节注入

    本章笔者将介绍一种通过Metasploit生成ShellCode并将其注入到特定PE文件内的Shell注入技术.该技术能够劫持原始PE文件的入口地址,在PE程序运行之前执行ShellCode反弹,执行 ...

  3. 20个最佳实践提升Terraform工作流程|Part 1

    Terraform 是管理基础设施及代码(IaC)最常用的工具之一,它能使我们安全且可预测地对基础设施应用更改.刚开始上手 Terraform 可能会感觉有些不容易,但很快就能对该工具有基本的了解,随 ...

  4. 小札 Combinatorics 2

    对于 Newton Expansion,式子本身的证明其实无甚可翻新的花样,但是题还是很有意思的.比如 codeforces - 1332E Height All the Same 这个. 首先给出几 ...

  5. 解决WordPress修改固定链接结构后出现“404 Not Found”的情况

    解决办法 在宝塔面板找到部署的站点设置 点击进入配置文件,复制下方这段代码粘贴进入配置文件,操作完这步,去刷新下我们的网站,再打开文章链接就可以正常打开.访问了. location / { try_f ...

  6. 03-11gR2单机通过RMAN恢复到RAC(未验证)

    1.在单机上做一个完全备份,并将备份集拷贝到RAC的第一个节点上. 2.强行启动到nomount 3.恢复spfile 4.创建pfile,修改pfile,重建spfile #####修改contro ...

  7. 使用Github Copilot完成代码编写

    上篇文章,我们使用VSCode创建了T.Global解决方案和两个类库工程,接下来我们使用Github Copilot完成代码编写 先说以下业务需求: 提供一个公共的本地化组件,支持对数字.货币.时间 ...

  8. 虹科干货 | 打破传统!金融界黑科技—虹科Redis企业版数据库

    金融行业数字化转型浪潮来袭,客户需求也正加速向在线金融服务转移.金融机构想要实现现代化改造技术堆栈,为客户提供实时交互.欺诈检测等一系列个性化创新服务,就必须重视遗留系统和传统数据库架构"老 ...

  9. YbtOJ 数位DP G.幸运666

    日常写点奇奇怪怪的乱搞做法 awa 这题跟前面几道数位 DP 的区别在于让求第 \(n\) 小的数. 虽然我不会求也不想学这个,但我们可以 binary search! 问题就转换为求 \([1,mi ...

  10. JS深入之内存详解,数据结构,存储方式

    理解了本文,就知道深拷贝和浅拷贝的底层,了解赋值的底层原理. 可以结合另一篇文章一起食用:深拷贝与浅拷贝的区别,实现深拷贝的方法介绍. 以下是正文: 栈数据结构 栈的结构就是后进先出(LIFO),如果 ...