HDU 5936 Difference(折半枚举)
来源:互联网 发布:创意美工作品图片大全 编辑:程序博客网 时间:2024/06/07 20:25
Difference
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1247 Accepted Submission(s): 335
Problem Description
Little Ruins is playing a number game, first he chooses two positive integers y and K and calculates f(y,K), here
f(y,K)=∑z in every digits of yzK(f(233,2)=22+32+32=22)
then he gets the result
x=f(y,K)−y
As Ruins is forgetful, a few seconds later, he only remembers K, x and forgets y. please help him find how many y satisfy x=f(y,K)−y.
Input
First line contains an integer T, which indicates the number of test cases.
Every test case contains one line with two integers x, K.
Limits
1≤T≤100
0≤x≤109
1≤K≤9
Output
For every test case, you should output ‘Case #x: y’, where x indicates the case number and counts from 1 and y is the result.
Sample Input
2
2 2
3 2
Sample Output
Case #1: 1
Case #2: 2
Source
2016年中国大学生程序设计竞赛(杭州)
Recommend
liuyiding
题目大意
输入两个正整数
解题思路
虽然题目没有给
知道这个后就可以想到一个最暴力的方法,每次枚举所有可能的
最后还有一个优化,由于
需要注意题目还有一个坑点,由于题面说
AC代码
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <map>using namespace std;#define LL long long#define mem(a,b) memset((a),(b),sizeof(a))const int ten[]={1, 10, 100, 1000, 10000, 100000};int X, K;int Pow[13][13];//i的j次方map<LL, int> cnt[10];//贡献为i的方案数void pre_work()//预处理{ for(int i=0;i<=9;++i) { Pow[i][0]=1; for(int j=1;j<=9;++j) Pow[i][j]=Pow[i][j-1]*i; } for(int k=1;k<=9;++k)//枚举所有可能的k { for(int i=0;i<=99999;++i)//枚举后5位 { LL res=-i; for(int j=0;j<=4;++j) res+=Pow[i/ten[j]%10][k]; ++cnt[k][res]; } }}int main(){ pre_work(); int T_T; scanf("%d", &T_T); for(int cas=1;cas<=T_T;++cas) { scanf("%d%d", &X, &K); LL ans=0; for(int i=0;i<=99999;++i)//枚举前5位 { LL res=-i*100000ll; for(int j=0;j<=4;++j) res+=Pow[i/ten[j]%10][K]; LL obj=X-res; if(cnt[K].find(obj)!=cnt[K].end()) ans+=cnt[K][obj]; } if(X==0)//特判X==0 --ans; printf("Case #%d: %lld\n", cas, ans); } return 0;}
- HDU 5936 Difference(折半枚举)
- HDU 5936 && 2016CCPC杭州 D: Difference(折半枚举)
- Hdu 5936 Difference【思维+折半枚举+二分】
- HDU 5936 Difference 折半枚举,暴力
- hdu 4715 Difference Between Primes (打表 枚举)
- poj2785(折半枚举)
- poj2549(折半枚举)
- POJ2785 (折半枚举)
- POJ3977(折半枚举)
- poj3977Subset (折半枚举)
- hdu 5735 Born Slippy 折半枚举
- poj3977 Subset(折半枚举)
- 折半枚举(双向搜索)
- poj3977(折半枚举,多坑)
- poj2785(二分折半枚举)
- 折半枚举(双向搜索)
- hdu 5936 Difference 二分
- 【折半枚举】
- setting.py
- 上天不易,硅谷被吐槽 | 硅谷锋向周刊
- 好声音冠名起风波,微鲸电视缘何铤而走险?
- 智能手环都开始加屏幕了,连刷公交的都不例外
- Tensorflow 反卷积
- HDU 5936 Difference(折半枚举)
- MySQL数据处理函数
- Ambari Agent源码梳理
- 优化定制化abap代码必须遵守的经典黄金规则
- POJ 1155 TELE 树形dp + 背包
- 机房收费系统—前期配置
- Postgres设置pg_log日志记录内容
- java(十四):transient与序列化
- Linux应用编程基础--(8)线程间的同步和互斥