hdu 5936 二分好题 2016年中国大学生程序设计竞赛(杭州)
来源:互联网 发布:whatsapp软件下载 编辑:程序博客网 时间:2024/05/17 09:33
Difference
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 933 Accepted Submission(s): 259
Problem Description
Little Ruins is playing a number game, first he chooses two positive integersy 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 remembersK ,x and forgets y . please help him find how many y satisfy x=f(y,K)−y .
then he gets the result
As Ruins is forgetful, a few seconds later, he only remembers
Input
First line contains an integer T , which indicates the number of test cases.
Every test case contains one line with two integersx ,K .
Limits
1≤T≤100
0≤x≤109
1≤K≤9
Every test case contains one line with two integers
Limits
Output
For every test case, you should output 'Case #x: y', wherex indicates the case number and counts from 1 andy is the result.
Sample Input
22 23 2
Sample Output
Case #1: 1Case #2: 2
题意:
看上面的式子
题解:
将y这个数分为两半,先处理后一半,然后枚举后一半再二分查找前一半,判断是否可以满足上面的式子
题目卡时间看的很气,数组开 long long 不行,会超时
并且再指数次方的那里需要预处理,并且不能先处理前一半,因为后一半和前一半有乘以100000的一个关系,利用好又可以减少时间
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 100005#define LL long longint a[maxn],sum[20][20],num[maxn];int main(){ for(int i=1;i<10;i++){ sum[i][0]=1; for(int j=1;j<=9;j++){ sum[i][j]=sum[i][j-1]*i; } } int T; int cases=1,x,k,temp,pos; //freopen("in.txt","r",stdin); scanf("%d",&T); while(T--) { LL t; pos=0; scanf("%d%d",&x,&k); memset(num,0,sizeof(num)); for(int i=1;i<100000;i++){ temp=i; while(temp) { num[i]+=sum[temp%10][k]; temp/=10; } a[pos++]=num[i]-i; } sort(a,a+pos); LL ans=0; for(LL i=0;i<100000;i++){ t=num[i]-i*100000; t=x-t; temp=lower_bound(a,a+pos,t)-a; while(a[temp]==t&&temp<pos) ans++,temp++; } printf("Case #%d: %lld\n",cases++,ans); } return 0;}
阅读全文
0 0
- hdu 5936 二分好题 2016年中国大学生程序设计竞赛(杭州)
- HDU 5936 Difference(思维+二分)——2016年中国大学生程序设计竞赛(杭州)
- HDU 5943 Kingdom of Obsession(2016年中国大学生程序设计竞赛(杭州)),好题
- HDU 5936 Difference 【中途相遇法】(2016年中国大学生程序设计竞赛(杭州))
- (2016年中国大学生程序设计竞赛(杭州)) HDU 5938 Four Operations 思维题 + 枚举
- HDU 5943 Kingdom of Obsession 【二分图匹配 匈牙利算法】 (2016年中国大学生程序设计竞赛(杭州))
- 2016年中国大学生程序设计竞赛(杭州)-重现赛
- 2016年中国大学生程序设计竞赛(杭州)-重现赛
- 2016年中国大学生程序设计竞赛(杭州)
- 2016年中国大学生程序设计竞赛(杭州) 部分题解
- HDU5938+贪心+(2016年中国大学生程序设计竞赛(杭州))
- HDU 5934 Bomb 【图论缩点】(2016年中国大学生程序设计竞赛(杭州))
- HDU 5935 Car 【模拟】 (2016年中国大学生程序设计竞赛(杭州))
- HDU 5938 Four Operations 【贪心】(2016年中国大学生程序设计竞赛(杭州))
- HDU 5935 Car (贪心)——2016年中国大学生程序设计竞赛(杭州)
- HDU 5938 Four Operations(2016年中国大学生程序设计竞赛(杭州))
- HDU 5937 Equation 【DFS+剪枝】 (2016年中国大学生程序设计竞赛(杭州))
- HDU 5933 ArcSoft's Office Rearrangement 【模拟】(2016年中国大学生程序设计竞赛(杭州))
- ASH ORA-01843: 无效的月份
- oracle中使用jobs时出现ORA-06553错误
- Arduino可穿戴教程之第一个程序——Blink(一)
- Linux命令分析: touch
- Linux如何查看JDK的安装路径
- hdu 5936 二分好题 2016年中国大学生程序设计竞赛(杭州)
- 本机上访问tomcat项目可以,局域网内的其他机器访问不到项目
- maven 安装感想、 配置、构建一个maven projec
- java的8大排序
- matlab cell数组的用法
- unsigned int mysql中的unsigned
- C++ Http请求中文传参乱码问题
- C++中四种类型转换
- 记录appium基于python的日常问题