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 ...
随机推荐
- [python] 第一个爬虫, 爬妹子写真集图片
效果图 版本以及需要用到的第三方库 python 2.7 bs4 (安装命令: pip install bs4) - 代码 #!/usr/bin/env python #coding:UTF-8 #脚 ...
- [SDR] SDR 教程实战 —— 利用 GNU Radio + HackRF 手把手深入了解蓝牙协议栈(从电磁波 -> 01数据流 -> 蓝牙数据包)
目录 0.前言 1.体验 2.代码解析 2.1 目录结构 2.2 main.py 2.3 grc gnu radio 流程图 2.4 如何从 01 数据流中解析出 BLE 广播包 2.4.1 物理层 ...
- 使用MySQL存储过程提高数据库效率和可维护性
MySQL 存储过程是一种强大的数据库功能,它允许你在数据库中存储和执行一组SQL语句,类似于编程中的函数.存储过程可以大幅提高数据库的性能.安全性和可维护性.本文将详细介绍MySQL存储过程的使用. ...
- Vue 脚手架编程
1.1 初始化脚手架 1.1.1 说明 Vue 脚手架是 Vue 官方提供的标准化开发工具(开发平台) 最新的版本是 4.x 文档 1.1.2 具体步骤 第一步(仅第一次执行):全局安装 @vue/c ...
- 「にちじょう記録」MTIDnWtMOA
Mistakes That I Don't Want to Make Once Again. // Caution // 差分 / 前缀和后注意询问区间端点有变化-- 不要考虑了右边界就不考虑左边界 ...
- 彻底弄懂ip掩码中的网络地址、广播地址、主机地址
本文为博主原创,转载请注明出处: 概念理解: IP掩码(或子网掩码)用于确定一个IP地址的网络部分和主机部分.它是一个32位的二进制数字,与IP地址做逻辑与运算,将IP地址划分为网络地址和主机地址两部 ...
- RatingBar android 自定义 评级 星星
资源下载地址 <!-- xml 中的使用 --> <RatingBar android:id="@+id/ratingBar" android:layout_wi ...
- 维修道路(repair)
维修道路(repair) 时间限制: 1 Sec 内存限制: 128 MB 题目描述 由于在十多年前道路改建时的突出贡献, Bob 被任命为维修道路的承包商, 他可以任意 选择两条路径去修理. Bo ...
- Nginx惊群现象的两种解决办法
惊群现象: 惊群现象是指由多个worker进程监听同一个Socket事件时,当事件发生时,相关的所有进程被惊醒,但最终只能有一个进程对该事件进行处理,其他进程会重新休眠,从而导致系统资源的浪费和系统性 ...
- 关于AI时代的程序架构的变化
以ChatGPT为代表的AI出现,表示着AI的零点时刻已经突破.现在AI的使用已经不用再多说了,实际上是已经侵入到各行各业.所有人都在疯狂寻找本行业AI的使用场景,这样的盛景只在互联网刚出现的时候能感 ...