hdu 5080 - Colorful Toy(2014 AnShan)几何+polya

Colorful Toy

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 304    Accepted Submission(s): 100


Problem Description
A toy is made up of N vertices and M undirected edges in the 2D plane. As usual, you want to know how many ways there are to color the vertices of the toy. You have totally C colors. And of course, to make things fun, you think that if one color configuration can be rotated to get another, these two configurations should be considered the same. Rotation means 2D in-plane rotation and reflection is not considered as rotation.


For instance, consider coloring the following toy with 2 colors. The coordinates of the vertices are:

1. (0,0)
2. (1,0)
3. (0,1)
4. (-1,0)
5. (0,-1)

The toy has 6 edges: (1,2), (1,3), (2,3), (3,4), (4,5), (5,2).

As a 2D being, this toy has no symmetry. So there are 32 ways to color it. Had the first two edges been removed, there would be only 12 different ways.

You should output the answer modulo 10 9 + 7.
 

Input
The first line contains an integer T (T ≤ 20) denoting the number of the test cases.

Each test case begins with three positive integers N (1 ≤ N ≤ 50), M (0 ≤ M ≤ N (N - 1)/2) and C(1 ≤ C ≤ 100).

Then follow N lines. Each line contains 2 integers in range [-10000,10000] describing a vertex.

Then follow M lines. Each line contains 2 integers in range [1,N] representing an edge. There are neither duplicate edges nor self-loops.
 

Output
For each test case, output one line containing the answer.
 

Sample Input
  
  
2 5 6 2 0 0 1 0 0 1 -1 0 0 -1 1 2 1 3 2 3 3 4 4 5 5 2 5 4 2 0 0 1 0 0 1 -1 0 0 -1 2 3 3 4 4 5 5 2
 

Sample Output
  
  
32 12


题意:平面上有n个点,m条边,用c种颜色染色,如果两种染色方案旋转后重合,则视为同一种染色方案。求染色方案数(n<=50)

思路:枚举两个点之间的中点作为整个图的旋转中心,判断能否旋转90度,或者180度

如果不能旋转,则相当于旋转0度,那么每个点对应自己,这个等价关系对应的置换有N个循环;

如果旋转90度,每四个点一组,对应一个循环,有N/4个循环,同时也可以旋转0,180,270

如果能旋转180,每两个点一组,有N/4个循环

然后根据polya定理,可求得答案

要注意的是,要把分组多出来的点单独处理

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=110;
const int MOD=1e9+7;
int N,M,C;
double x,y;
struct Point
{
    double x,y;
    Point(double xi=0,double yi=0):x(xi),y(yi){}
}p[maxn],p1[maxn];
bool operator==(const Point &a,const Point &b)
{
    return a.x==b.x&&a.y==b.y;
}
struct Line
{
    Point a,b;
}l[maxn*10],l1[maxn*10];
bool operator==(const Line &x,const Line &y)
{
    return x.a==y.a&&x.b==y.b||x.a==y.b&&x.b==y.a;
}
bool find_mid()
{
    bool flag=false;
    for(int i=1;i<=N;i++)
    {
        for(int j=i+1;j<=N;j++)
        {
            x=p[i].x+p[j].x;
            y=p[i].y+p[j].y;
            flag=true;
            for(int k=1;k<=N;k++)
            {
                Point tmp(x-p[k].x,y-p[k].y);
                int q;
                for(q=1;q<=N;q++)
                    if(p[q]==tmp){break;}
                if(q>N){flag=false;break;}
            }
            if(flag)return true;
        }
    }
    return false;
}
Point rotate(Point a)
{
    return Point(a.y+(x-y)/2,(x+y)/2-a.x);
}
bool judge(Point *pfrom,Line *lfrom,Point *pto,Line *lto)
{
    for(int i=1;i<=N;i++)
        pto[i]=rotate(pfrom[i]);
    for(int i=1;i<=M;i++)
    {
        lto[i].a=rotate(lfrom[i].a);
        lto[i].b=rotate(lfrom[i].b);
    }
    bool flag=true;
    for(int i=1;i<=N;i++)
    {
        int j;
        for(j=1;j<=N;j++)
            if(p[j]==pto[i]){break;}
        if(j>N)return false;
    }
    for(int i=1;i<=M;i++)
    {
        int j;
        for(j=1;j<=M;j++)
            if(lto[i]==l[j])break;
        if(j>M)return false;
    }
    return true;
}
LL pow_mul(LL x,int n)
{
    LL res=1;
    while(n)
    {
        if(n&1)res=res*x%MOD;
        x=(x*x)%MOD;
        n>>=1;
    }
    return res;
}
LL rev(int d)
{
    return pow_mul(d,MOD-2)%MOD;
}
void solve(int d)
{
    LL ans=0;
    LL tmp=N;
    N=N-N%d;
    if(d==1)ans=pow_mul(C,N);
    else if(d==2)
        ans=(pow_mul(C,N)+pow_mul(C,N/2)%MOD)%MOD;
    else ans=((pow_mul(C,N)+pow_mul(C,N/4)+pow_mul(C,N/2))%MOD+pow_mul(C,N/4))%MOD;
    ans=ans*rev(d)%MOD;
    if(tmp%d)ans=(ans*C)%MOD;
    cout<<ans<<endl;
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d",&N,&M,&C);
        for(int i=1;i<=N;i++)
            scanf("%lf%lf",&p[i].x,&p[i].y);
        for(int i=1;i<=M;i++)
        {
            int u,v;
            scanf("%d%d",&u,&v);
            l[i].a=p[u];
            l[i].b=p[v];
        }
        int d;
        if(find_mid())
        {
            if(judge(p,l,p1,l1))d=4;
            else if(judge(p1,l1,p1,l1))d=2;
            else d=1;
        }
        else d=1;
        solve(d);
    }
    return 0;
}





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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值