UVALive 6283 Great Deceiver 思考题
来源:互联网 发布:量子通信网络快吗 编辑:程序博客网 时间:2024/06/07 13:52
题意:给定一个n和k,求所有小于等于n的数中k进制和-k进制的值相等的有多少个组合使得
显然之后项数为奇或者幂为偶数的那些项相同才能使得k进制和-k进制都相同 也就是
对于
有多少个
并且
从最高位考虑,
1)若
2)若
1.考虑
2.考虑
代码:
#include <iostream>#include <cstdio>using namespace std;typedef long long LL;LL K,n,tk[100000],res[100000];LL dfs(int bpos){ if(bpos%2==0){ if(res[bpos]) return tk[bpos/2]; else return dfs(bpos-1); } return res[bpos]*tk[bpos/2]+dfs(bpos-1);}int main(){ while(~scanf("%lld%lld",&n,&K)){ tk[0]=1; for(int i=1;;i++){ tk[i]=tk[i-1]*K; if(tk[i-1]*K>n)break; } LL tn=n; res[0]=0; while(tn>0){ res[++res[0]]=tn%K; tn=tn/K; } //if(n==0)res[++res[0]]=0; //printf("res0:%lld\n",res[0]); //for(int i=res[0];i>=1;i--)printf("%lld ",res[i]); //puts(""); printf("%lld\n",dfs(res[0])); } return 0;}
0 0
- UVALive 6283 Great Deceiver 思考题
- 【思考题】great cells(数学)
- GREAT + SWERC = PORTO UVALive
- UVALive 3181 Fixing the Great Wall
- 思考题
- 思考题:
- 思考题
- 思考题
- 思考题
- 思考题
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- js继承原理
- 设计模式2-简单工厂模式
- 马哥Linux运维笔记----7
- Makefile经典教程(掌握这些足够)
- jQuery CSS 操作 - position() 方法
- UVALive 6283 Great Deceiver 思考题
- ExtJs 4.2 textfield 去除边框样式为下划线
- 51nod 多重背包问题 (dp)
- spring boot实战(第八篇)上下文的创建
- C语言数组与指针详解(转载)
- Material Design 实现之Toolbar的应用及其菜单动画
- hdoj 2025 查找最大元素
- leetcode笔记:Implement strStr()
- IOS Android 手机助手原理以及源码(Android 手机自动识别 一)