Y
来源:互联网 发布:优酷怎么不能登录淘宝 编辑:程序博客网 时间:2024/06/08 15:54
Y - odd-even number
代码如下:
#include<iostream>#include<cstring>using namespace std;typedef long long LL;int bit[20];LL dp[20][10][20];// pos pre sta LL dfs(int pos, int pre, int sta, bool lead, bool limit){if (pos == -1){if (pre % 2 != sta % 2 && !lead)//判定条件return 1;return 0;}if (!limit && dp[pos][pre][sta] != -1)return dp[pos][pre][sta];int up = limit ? bit[pos] : 9;LL temp = 0;for (int i = 0; i <= up; i++){int sta2;if (lead && i == 0)//全为0sta2 = 0;else if (i % 2 == pre % 2)//pre 和 i 相同奇偶sta2 = sta + 1;else if (sta % 2 != pre % 2 || lead && i != 0)//不同奇偶 或者 第一次出现sta2 = 1;else if (sta != 0 || !limit)continue;temp += dfs(pos - 1, i, sta2, lead && i == 0, limit && i == bit[pos]);}if (!limit)dp[pos][pre][sta] = temp;return temp;}LL solve(LL x){memset(dp, -1, sizeof(dp));int pos = 0;while (x){bit[pos++] = x % 10;x /= 10;}return dfs(pos - 1, 0, 0, 1, 1);}int main(){int t;LL le, ri;cin >> t;int cnt = 1;while (t--){cin >> le >> ri;LL ans1 = solve(ri);LL ans2 = solve(le - 1);cout << "Case #" << cnt++ << ": " << ans1 - ans2 << endl;}return 0;}
阅读全文
0 0
- y
- y
- Y
- Y
- Y
- Y
- y
- Y
- Y
- y
- Y
- Y
- Y
- Y
- Y
- Y
- Y
- Y-Combinator
- HDU-6186 CS Course (线段树)(2017ACM/ICPC广西邀请赛)
- SDUT-3341
- 方法的重载,数组的定义,及数组Date171109T1916
- Lesson 4上机练习题——多态
- JSON.parse()和JSON.stringify()
- Y
- learn opencv- 深度学习使用Keras
- Quartz学习——Quartz简单入门Demo(二)
- jackson 实体转json 为NULL或者为空不参加序列化
- OpenStack公共组件oslo之五——oslo.service
- bzoj 1012
- Android 自定义圆形扫描动效
- 判断对象是空对象
- 欢迎使用CSDN-markdown编辑器