poj 1286
2015-07-07 11:21
148 查看
题目描述:
波利亚计数.有旋转和对称.旋转是gcd,对称画图自己看.之后就是3^x然后再除以2n题解:
rt重点:
波利亚计数.也可以枚举之后数环的个数代码:
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <ctype.h> #include <limits.h> #include <cstdlib> #include <algorithm> #include <vector> #include <queue> #include <map> #include <stack> #include <set> #include <bitset> #define CLR(a) memset(a, 0, sizeof(a)) #define REP(i, a, b) for(ll i = a;i < b;i++) #define REP_D(i, a, b) for(ll i = a;i <= b;i++) typedef long long ll; using namespace std; const ll maxn = 30 + 10; ll p[maxn]; ll n; ll gcd(ll a, ll b) { if(b==0) return a; return gcd(b, a%b); } void getP() { ll key = 24; p[0] = 1; for(ll i = 1;i < key;i++) { p[i] = p[i-1]*3; } } void solve() { ll ans = 0; ans += p ; for(ll i = 1;i < n;i++) { ll t = gcd(i, n); ans += p[t]; } if(n%2==0) { ans += (n/2)*(p[n/2]) + (n/2)*(p[n/2+1]); } else { ans += (n)*(p[n/2+1]); } ans /= 2*n; printf("%I64d\n", ans); } int main() { //freopen("7Gin.txt", "r", stdin); //freopen("7Gout.txt", "w", stdout); getP(); while(scanf("%I64d", &n) != EOF) { if(n==-1) break; if(n==0) printf("0\n"); else solve(); } return 0; }
相关文章推荐
- 使用Dom4j解析XML
- iOS 8 AutoLayout 及SizeClass(二) 使用详解
- 35、Linux中shell数据重定向(输入重定向与输出重定向)
- 浏览器为已登录的input自动填充黄色背景
- JsonMappingException
- springmvc接收和处理json数据
- Spring学习(12)--- @Autowired与@Resource 对比
- iOS 编程 计算字符串文字宽度
- windowsXP+python2.7+openCV3.0环境搭建
- PCB焊盘、过孔、走线、去耦技术
- 查看Oracle日志情况
- 《C语言及程序设计》实践参考——间隔选职工
- Android Sensor Test
- 大约cocos2d-X 3.x使用引擎版本自带的物理引擎Physics
- 牛角尖之js:点击复制
- 设置渐变的背景色
- Javascript编写2048小游戏
- js对象操作
- Arduino的串口
- Java annotation简介1