poj1286 Necklace of Beads—— Polya定理
题目:http://poj.org/problem?id=1286
真·Polya定理模板题;
写完以后感觉理解更深刻了呢。
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
int n;
ll ans;
ll pw(ll a,int b)
{
ll ret=;
for(;b;b>>=,a*=a)
if(b&)ret*=a;
return ret;
}
int gcd(int a,int b){return (a%b==)?b:gcd(b,a%b);}
ll rot(int n)
{
ll ret=;
for(int i=;i<n;i++)
ret+=pw(,gcd(i,n));
return ret;
}
ll d(int n)
{
if(n%)return (ll)n*pw(,(n-)/+);
return (ll)n/*(pw(,n/)+(ll)pw(,(n-)/+));
}
int main()
{
while()
{
scanf("%d",&n);
if(!n)
{
printf("0\n"); continue;//!
}
if(n==-)return ;
ans=(rot(n)+d(n))/(*n);
printf("%lld\n",ans);
}
}
poj1286 Necklace of Beads—— Polya定理的更多相关文章
- POJ1286 Necklace of Beads(Polya定理)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9359 Accepted: 3862 Description Beads ...
- Necklace of Beads(polya定理)
http://poj.org/problem?id=1286 题意:求用3种颜色给n个珠子涂色的方案数.polya定理模板题. #include <stdio.h> #include &l ...
- 【数论】【Polya定理】poj1286 Necklace of Beads
Polya定理:设G={π1,π2,π3........πn}是X={a1,a2,a3.......an}上一个置换群,用m中颜色对X中的元素进行涂色,那么不同的涂色方案数为:1/|G|*(mC(π1 ...
- poj 1286 Necklace of Beads (polya(旋转+翻转)+模板)
Description Beads of red, blue or green colors are connected together into a circular necklace of ...
- Necklace of Beads(polya计数)
Necklace of Beads Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7451 Accepted: 3102 ...
- hdu 1817 Necklace of Beads (polya)
Necklace of Beads Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- poj1286 Necklace of Beads【裸polya】
非常裸的polya,只是我看polya看了非常久 吉大ACM模板里面也有 #include <cstdio> #include <cmath> #include <ios ...
- POJ1286 Necklace of Beads
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8263 Accepted: 3452 Description Beads ...
- POJ2154 Color【 polya定理+欧拉函数优化】(三个例题)
由于这是第一天去实现polya题,所以由易到难,先来个铺垫题(假设读者是看过课件的,不然可能会对有些“显然”的地方会看不懂): 一:POJ1286 Necklace of Beads :有三种颜色,问 ...
随机推荐
- win7右键菜单不见解决办法
直接 开始 运行: cmd /k reg add "HKEY_CLASSES_ROOT\Directory\Background\shellex\ContextMenuHandlers\Ne ...
- mysql常用命令用法
Mysql帮助文档地址:http://dev.mysql.com/doc/ 1.创建数据库: create database database_name; 2.选择数据库: use database_ ...
- Python之爬虫-段子网
Python之爬虫-段子网 https://ishuo.cn #!/usr/bin/env python # -*- coding:utf-8 -*- import re import request ...
- 集训第四周(高效算法设计)D题 (区间覆盖问题)
原题 UVA10020 :http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19688 经典的贪心问题,区间上贪心当然是右区间越 ...
- poj 3253 Fence Repair (优先队列,哈弗曼)
题目链接:http://poj.org/problem?id=3253 题意:给出n块木板的长度L1,L2...Ln,求在一块总长为这个木板和的大木板中如何切割出这n块木板花费最少,花费就是将木板切割 ...
- 使用C++调用pytorch模型(Linux)
前言 模型转换思路通常为: Pytorch -> ONNX -> TensorRT Pytorch -> ONNX -> TVM Pytorch -> 转换工具 -> ...
- javaWeb学习之 Filter过滤器----https://www.cnblogs.com/xdp-gacl/p/3948353.html
https://www.cnblogs.com/xdp-gacl/p/3948353.html
- 九度oj 题目1182:统计单词
题目1182:统计单词 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4780 解决:1764 题目描述: 编一个程序,读入用户输入的,以“.”结尾的一行文字,统计一共有多少个单词,并分别 ...
- 全文搜索(A-4)-推荐系统架构
推荐系统向用户推荐物品有三种情况. 推荐和用户已表示喜欢的物品相似的物品. 推荐和用户有相似偏好的用户喜欢的物品. 推荐包含用户偏好特征的物品.
- hihoCoder#1042 跑马圈地
原题地址 经网友jokeren提醒,后面给出的代码虽然可以AC原题,但存在bug,主要是在矩形覆盖情况的判断上处理的不够完全. 看似挺复杂的,但是仔细分析一下可以化简: 首先,不用枚举周长,因为更长的 ...