ACM 快速幂模板 HDU4365

ACM 快速幂模板 

HDU4365

//快速幂模板:
lint quick(lint base, lint pow)
{
    lint ret=1;
    while(pow)
    {
        if (pow&1) ret=(ret*base)%mod;
        base=(base*base)%mod;
        pow>>=1;
    }
    return ret%mod;//记得最后mod,比如mod==1的情况
}

原题:

题解:http://www.cnblogs.com/bo-tao/archive/2012/08/15/2640380.html

/*
 * Author: NICK WONG
 * Created Time:  2015/8/5 21:27:00
 * File Name: e.cpp
 */
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
#define out(x) cout<<#x<<": "<<x<<endl
const double eps(1e-8);
const int maxn=10100;
const long long maxint=-1u>>1;
const long long maxlong=maxint*maxint;
typedef long long lint;
set<pair<int, int> > s;
int n,m;
lint k;
const long long mod=100000007;

void init()
{
}

void change(int& x, int& y)
{
    if (x>n/2) x=n+1-x;
    if (y>n/2) y=n+1-y;
    if (x>y) swap(x,y);
}

lint quick(lint base, lint pow)
{
    lint ret=1;
    while(pow)
    {
        if (pow&1) ret=(ret*base)%mod;
        base=(base*base)%mod;
        pow>>=1;
    }
    return ret;
}

void work()
{
    lint ans=0;
    s.clear();
    for (int i=1; i<=(n+1)/2; i++)
        ans+=i;
    for (int i=1; i<=m; i++)
    {
        int x,y;
        cin>>x>>y;
        x++; y++;
        change(x,y);
        s.insert(make_pair(x,y));
    }
    ans-=s.size();
    ans=quick(k,ans);
    cout<<ans<<endl;
}

int main()
{
    while(cin>>n>>m>>k)
    {
    init();
    work();
    }
    return 0;
}

E - Palindrome graph
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值