【2017中国大学生程序设计竞赛 - 网络选拔赛】Palindrome Function
【链接】http://acm.hdu.edu.cn/showproblem.php?pid=6156
【题意】
已知函数f(x, k),如果10进制数x在k进制下是个回文数,那么f(x, k)值为k,否则为1
现给出l, r, x, y, 求出∑∑f(i, j) (l<=i<=r) (x<=j<=y)
【题解】
【错的次数】
【反思】
【代码】
#include <bits/stdc++.h>
#define int long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x+1)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
using namespace std;
const int MAXN = 110; int dp[40][MAXN][MAXN][2];
int num[MAXN],temp[MAXN],base;
int dfs(int start,int cur,bool state,bool f)
{
if(cur<0) return state;
if(!f&&dp[base][start][cur][state]!=-1)
return dp[base][start][cur][state];
int en=f?num[cur]:base-1;
int ans=0;
for(int i=0;i<=en;i++)
{
temp[cur]=i;
if(start==cur&&i==0)
{
ans+=dfs(start-1,cur-1,state,f&&i==en);
}
else if(state&&cur<(start+1)/2)
{
ans+=dfs(start,cur-1,temp[start-cur]==i,f&&i==en);
}
else
{
ans+=dfs(start,cur-1,state,f&&i==en);
}
}
if(!f&&ans>=0)
dp[base][start][cur][state]=ans;
return ans;
}
int f(int n)
{
int len=0;
while(n)
{
num[len++]=n%base;
n/=base;
}
num[len]=0;
return dfs(len-1,len-1,1,1);
}
main()
{
ios::sync_with_stdio(false);
int t;
cin >> t;
memset(dp,-1,sizeof dp);
int cas = 0;
while(t--)
{
int L,R,l,r;
cin >> L >> R >> l >> r;
int ans = 0;
for (base = l;base <= r;base++)
{
int num = f(R)-f(L-1);
ans = ans + (num)*base;
ans = ans + R-L + 1 - num;
}
cout << "Case #" << ++cas <<": "<<ans<<endl;
}
return 0;
}
【2017中国大学生程序设计竞赛 - 网络选拔赛】Palindrome Function的更多相关文章
- HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛
普通的数位DP计算回文串个数 /* HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 2-36进制下回文串个数 */ ...
- HDU 6154 - CaoHaha's staff | 2017 中国大学生程序设计竞赛 - 网络选拔赛
/* HDU 6154 - CaoHaha's staff [ 构造,贪心 ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 题意: 整点图,每条线只能连每个方格的边或者对角线 问面积大于n的 ...
- HDU 6150 - Vertex Cover | 2017 中国大学生程序设计竞赛 - 网络选拔赛
思路来自 ICPCCamp /* HDU 6150 - Vertex Cover [ 构造 ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 题意: 给了你一个贪心法找最小覆盖的算法,构造一组 ...
- HDU 6154 CaoHaha's staff(2017中国大学生程序设计竞赛 - 网络选拔赛)
题目代号:HDU 6154 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 CaoHaha's staff Time Limit: 2000/1 ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6155 Subsequence Count 矩阵快速幂
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6155 题意: 题解来自:http://www.cnblogs.com/iRedBean/p/73982 ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha's staff(几何找规律)
Problem Description "You shall not pass!"After shouted out that,the Force Staff appered in ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6152 Friend-Graph(暴力搜索)
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6152 Problem Description It is well known that small ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 1004 HDU 6153 A Secret (字符串处理 KMP)
题目链接 Problem Description Today is the birthday of SF,so VS gives two strings S1,S2 to SF as a presen ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 1005 HDU 6154 CaoHaha's staff (找规律)
题目链接 Problem Description "You shall not pass!" After shouted out that,the Force Staff appe ...
随机推荐
- 3.React Native在Android中自己定义Component和Module
React Native终于展示的UI全是Native的UI.将Native的信息封装成React方便的调用. 那么Native是怎样封装成React调用的?Native和React是怎样交互的? V ...
- 如何调试Blink?
内容 尽管有很多工具和技巧可用于调试Blink,这个文章的重点调试Blink除布局測试之外的feature. 1 介绍 2 Linux 2.1 入门 2.2 启动Debugger 3 实用的工具 3. ...
- JavaWeb与JSP初识
JavaWeb执行过程 目录结构 Web程序部署在Tomcat的/webapps下面. 一个webapps文件夹可以部署多个不同的Web应用,webapps/web1,webapps/web2. 如果 ...
- 在使用FireFox浏览器时,经常打开新标签,页面总是不断自动刷新,解决办法
可以用如下方法尝试(逐个尝试,看看哪个管用): 1.地址栏输入 about:support,右上角有个翻新Firefox,点击,等待浏览器重启,即可. 2.点击:工具-附加组件,把“火狐主页和标签管理 ...
- shell脚本的if判断语句
if条件判断语句 if (表达式) #if ( Variable in Array ) 语句1 else 语句2 fi 1.测试数字大小 #!/bin/sh NUM=100 if (( $NUM &g ...
- nginx 实现跨域
nginx 添加头部跨域. location / { add_header 'Access-Control-Allow-Origin' '*'; //允许的域 add_header 'Access-C ...
- 紫书 习题 10-22 UVa 10479 (找规律)
自己一直在纠结这个串的构造方法 而没有观察串本身的规律-- 2的63次方用 unsigned long long 然后可以发现串是递归构造的. 将串分成1,1,2,4,8,16, 然后会发现s串里面1 ...
- JS关键字 import
今天开发时使用import作为方法名,报错 后查明报错原因:import是js中的关键字,在取方法名时不能取import
- 【Henu ACM Round#14 F】 President and Roads
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 处理出起点到任意点的最短路以及最短路条数=>dis[0][i],cnt[0][i] 然后 把所有的边反向 处理出在反图上终点到 ...
- ORA-00922: 选项缺失或无效
1.错误描写叙述 SQL> create table info_stu from select t.stu_id,t.stu_name,t.stu_age from info t; create ...