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. 一文了解Validator库

    1. 引言 github.com/go-playground/validator 是一个 Go 语言的库,用于对结构体字段进行验证.它提供了一种简单而灵活的方式来定义验证规则,并在验证过程中检查结构体 ...

  2. 「luogu - P4313」文理分科 Mincut

    link. Pretty nice practice for the min-cut trick. Starting out we eliminate the constraint that if f ...

  3. Python爬虫-IP隐藏技术与代理爬取

    在进行爬虫程序开发和运行时,常常会遇到目标网站的反爬虫机制,最常见的就是IP封禁,这时需要使用IP隐藏技术和代理爬取. 一.IP隐藏技术 IP隐藏技术,即伪装IP地址,使得爬虫请求的IP地址不被目标网 ...

  4. ORACLE DBLink创建

    在写测试脚本时,经常需要跨库取数据,SQL本身不支持跨库查找.Oracle提供DBLink链接,支持跨库操作. 1.创建DBLink Create public database link Next_ ...

  5. MySQL——MySQL面试题

    文章目录 数据库基础知识 为什么要使用数据库 什么是SQL? 什么是MySQL? 数据库三大范式是什么 mysql有关权限的表都有哪几个 MySQL的binlog有有几种录入格式?分别有什么区别? 数 ...

  6. 2020 5 17 codeforces

    cf还没结束,就开始写总结了.cf确实是个好东西,能够直接暴露出弱点和增加刷题量.以后还是要多打打的.这次我发现自己的码力还是不行.一个二分都要调好久.唉T1sb题,就是入门用的.题目看不懂...写了 ...

  7. 以效率为导向:用ChatGPT和HttpRunner实现敏捷自动化测试(二)

    1.前言 在上一篇文章: 利用ChatGPT提升测试工作效率--测试工程师的新利器(一)中,我们提到了如何通过chatGPT生成单接口测试用例,然后再让chatGPT去根据测试用例去生成接口自动化脚本 ...

  8. 基于落点打分的井字棋智能下棋算法(C语言实现)

    本文设计了一种基于落地打分的井字棋下棋算法,能够实现电脑不败,所以如果玩家会玩的话,一般是平局. 算法核心 电脑根据对落子位置的打分,选择分数最高的位置,若不同落点分数相同则随机选择位置(随机选择就不 ...

  9. JNI编程之java层和native层的数组数据的交互

    一.前言 JNI中的数组类型分为基本类型数组和引用类型数组,他们的处理方式是不一样的.基本类型数组中的元素都是jni基本数据类型,可以直接访问:但是引用类型的数组中的元素是一个类的实例,不能直接访问, ...

  10. 17.1 隐藏执行CMD命令

    本章内容涉及使用Socket API和CMD命令行工具实现本地CMD命令执行.无管道正向CMD和无管道反向CMD三种功能.执行本地CMD实现使用CreateProcess函数创建一个新的CMD进程,并 ...