HDU 5936 Difference 【中途相遇法】(2016年中国大学生程序设计竞赛(杭州))
Difference
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 62 Accepted Submission(s): 19Problem DescriptionLittle Ruins is playing a number game, first he chooses two positive integers y and K and calculates f(y,K), heref(y,K)=∑z in every digits of yzK(f(233,2)=22+32+32=22)then he gets the result
x=f(y,K)−yAs 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.
InputFirst 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≤9OutputFor 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 Input2
2 2
3 2Sample OutputCase #1: 1
Case #2: 2SourceRecommend
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5936
题目大意:
(y每位上的数字的K次幂之和)
X=f(y,K)-y。现在给定X和K,求有多少Y满足题意。
数据范围 
题目思路:
【中途相遇法】
数据范围x在[0,109],y的位数不会超过10位。
所以想直接对半分,先枚举前5位,记下相应的值,再枚举后5位,与前面的匹配看是否能够凑成x,最后统计答案即可。
一开始用map写,T了。一脸懵逼。
后来改成将每个出现的值都记下来,排序,正反扫一遍。。过了。
可以预处理一些操作、运算。
//
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-8)
#define J 10000
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#define N 14
#define M 100004
using namespace std;
typedef long long LL;
double anss;
LL aans;
int cas,cass;
int n,m,lll,ans;
LL e[N];
LL mi[N][N],c[N][M],d[N][M];
bool cmp(int a,int b)
{
return a<b;
}
void init()
{
int i,j;
for(e[]=,i=;i<;i++)e[i]=e[i-]*;
for(i=;i<;i++)
{
mi[i][]=;
for(j=;j<;j++)mi[i][j]=mi[i][j-]*i;
}
for(j=;j<;j++)
{
for(i=;i<e[];i++)
c[j][i]=mi[i/e[]][j]+mi[i%e[]/e[]][j]+mi[i%e[]/e[]][j]+mi[i%e[]/e[]][j]+mi[i%e[]][j]-i*e[],
d[j][i]=mi[i/e[]][j]+mi[i%e[]/e[]][j]+mi[i%e[]/e[]][j]+mi[i%e[]/e[]][j]+mi[i%e[]][j]-i;
sort(c[j],c[j]+e[],cmp);
sort(d[j],d[j]+e[],cmp);
}
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
int x,y,z;
init();
// for(scanf("%d",&cass);cass;cass--)
for(scanf("%d",&cas),cass=;cass<=cas;cass++)
// while(~scanf("%s",s))
// while(~scanf("%d%d",&n,&m))
{
printf("Case #%d: ",cass);
ans=;
scanf("%d%d",&n,&m);
for(i=,j=e[]-;i<e[] && j;)
{
if(c[m][i]+d[m][j]>n)j--;
else if(c[m][i]+d[m][j]<n)i++;
else
{
x=y=;
while(c[m][++i]==c[m][i-] && i<e[])x++;
while(d[m][--j]==d[m][j+] && j)y++;
ans+=x*y;
}
}
printf("%d\n",ans-(n==));
}
return ;
}
/*
// //
*/
HDU 5936 Difference 【中途相遇法】(2016年中国大学生程序设计竞赛(杭州))的更多相关文章
- HDU 5963 朋友 【博弈论】 (2016年中国大学生程序设计竞赛(合肥))
朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Descr ...
- HDU 5965 扫雷 【模拟】 (2016年中国大学生程序设计竞赛(合肥))
扫雷 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submissi ...
- HDU 6273.Master of GCD-差分数组 (2017中国大学生程序设计竞赛-杭州站-重现赛(感谢浙江理工))
Super-palindrome 题面地址:http://acm.hdu.edu.cn/downloads/CCPC2018-Hangzhou-ProblemSet.pdf 这道题是差分数组的题目,线 ...
- HDU 5969 最大的位或 【贪心】 (2016年中国大学生程序设计竞赛(合肥))
最大的位或 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem De ...
- HDU 5968 异或密码 【模拟】 2016年中国大学生程序设计竞赛(合肥)
异或密码 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Des ...
- HDU 5961 传递 【图论+拓扑】 (2016年中国大学生程序设计竞赛(合肥))
传递 Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem ...
- HDU 5937 Equation 【DFS+剪枝】 (2016年中国大学生程序设计竞赛(杭州))
Equation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDU 5943 Kingdom of Obsession 【二分图匹配 匈牙利算法】 (2016年中国大学生程序设计竞赛(杭州))
Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- HDU 5938 Four Operations 【贪心】(2016年中国大学生程序设计竞赛(杭州))
Four Operations Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
随机推荐
- 10.21_Nutz批量插入顺序,POI,wiki持续关注,POI,SSH,数据库优先
(1)Nutz,dao的批量插入会关注顺序吗? http://www.douban.com/group/topic/64322582/ (2)工作需要优先!!! POI,SSH,数据库管理及plsq ...
- UVA 11991 Easy Problem from Rujia Liu?(vector map)
Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...
- 九度OJ 1081 递推数列 -- 矩阵二分乘法
题目地址:http://ac.jobdu.com/problem.php?pid=1081 题目描述: 给定a0,a1,以及an=p*a(n-1) + q*a(n-2)中的p,q.这里n >= ...
- Entity Framework 的事务 DbTransaction
事务代码实现如下: public static void Transaction() { myitEntities entity = null; DbTransaction tran = null; ...
- Shell数组
#!/bin/bash#数组的使用#数组赋值方式:#1. user[index]=value index为0,1,2,3,4....数组下标值#2. user=(value0 value1 value ...
- PHP 冒泡排序法
<?php // 冒泡排序法:将一个数组中的值按照从小到大的顺 序排序 $arr = array(33, 1, 4, 5, 2, 3, 7, 9, 8, 99); $len = count($a ...
- 自己编写的sublime text 3 插件
一些小功能,比较杂. 具体的功能在这里查看 1.本地环境的php运行结果获取. 2.快捷打开常用的文件,文件夹,url.(ctrl+shift+a) 3.常用的缩进转换. 下边是网络爬虫代码. #py ...
- ubuntu下的软件安装
1.软件安装 最近开始将个人电脑由windows换成linux,第一步就是会装一些个人软件,以前玩linux都是用yum或者apt-get来进行安装. 下面介绍一下如何从官网下载文件并且安装的方法. ...
- VS2015安装开发ios android
前几天很火,装了一下,结果是不是太满意,装了VS2015只是多了一个android和ios的模版,最终还是要装xamarin ,最后装了个xamarin ,然后破解 破解地址:http://www.c ...
- POJ 1836 Alignment 水DP
题目: http://poj.org/problem?id=1836 没读懂题,以为身高不能有相同的,没想到排中间的两个身高是可以相同的.. #include <stdio.h> #inc ...