HDU-4365 Palindrome graph

首先将没有特殊点的所有的情况都计算出来,再将给定的点都计算到左上角的标记点,最后查看有多少个点已经被覆盖了,减去该部分,最后用快速幂输出结果,注意这里要用long long。

代码如下:

#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<algorithm>

#include<cmath>

#include<queue>

#include<set>

#include<map>

#include<cstring>

#include<vector>

#include<string>

#define MOD 100000007

#define LL long long

using namespace std;



int N, M, K;



struct Node

{

    int x, y;

    bool operator < (Node temp) const

    {

        if (x != temp.x) return x < temp.x;

        else return y < temp.y;

    }

    bool operator == (Node temp) const

    {

        return x == temp.x && y == temp.y;

    }

}seq[2005];



int Cal(int x)

{

    if (x <= 0) return 0;

    if (x & 1) {

        return (x + 1) / 2 + Cal(x - 2);

    }

    else {

        return x / 2 + Cal(x - 2);    

    }

}



void init(int &x, int &y)

{

    if (x > N/2) {

        x = N - x + 1;

    }

    if (y > N/2) {

        y = N - y + 1;

    }

    if (x > y) {

        int t = x;

        x = y, y = t;

    }

}



int _pow(LL a, int b)

{

    LL ret = 1;

    while (b) {

        if (b & 1) {

            ret *= a;

            ret %= MOD;

        }

        a *= a;

        a %= MOD;

        b >>= 1;

    }

    return ret;

}



int main()

{ 

    int ret;

    while (scanf("%d %d %d", &N, &M, &K) == 3) {

        ret = Cal(N);

        for (int i = 1; i <= M; ++i) {

            scanf("%d %d", &seq[i].x, &seq[i].y);

            seq[i].x += 1, seq[i].y += 1;

            init(seq[i].x, seq[i].y);

        }

        sort(seq+1, seq+M+1);

        ret -= unique(seq+1, seq+M+1) - (seq+1);

        printf("%d\n", _pow(K, ret));

    }

    return 0;

}

你可能感兴趣的:(Graph)