Problem A. Arithmetic Derivative-XVII Open Cup named after E.V. Pankratiev||找规律&数学&DFS
来源:互联网 发布:java集合框架视频教程 编辑:程序博客网 时间:2024/06/11 21:26
题目描述:
签到题,找规律,
手推了规律如下:
AC代码:
/*2017年8月29日22:33:28Problem A. Arithmetic DerivativeAC 找规律+简单DFS+溢出处理 */#include <iostream>#include <map>#include <set>#include <string>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>#include <queue>#include <vector> using namespace std;typedef long long ll;const ll inf=2e18;//讲满足k=1的前6个数存下来 用来搜索 ll p[]={4,27,3125,823543,285311670611,302875106592253}; ll cur,k,r;//当前层数的值,需要搜索的层数,上界 ll ans[1000]; set<ll> st;//用set是因为题目要求排序+去重 set<ll>::iterator it;void dfs(ll num,ll cur){if(num==k){for(int i=0;i<6;i++){ll tmp=cur*p[i];//这里是对溢出的处理 /*如果不满足条件也就是说 p[i]*cur 会大于INF,那么数据会发生溢出溢出的数据不满足条件,舍去 */ if((inf/cur)>=p[i]){/*不发生溢出再考虑与r的大小*/ if(tmp<=r) st.insert(tmp);else return;}else return;}}else if(num<k){for(int i=0;i<6;i++){if((inf/cur)>=p[i])dfs(num+1,cur*p[i]);else return;}}}int main(){scanf("%lld%lld",&k,&r);dfs(1,1);printf("%lld\n",st.size());for(it=st.begin();it!=st.end();it++){if(it!=st.begin()) printf(" ");printf("%lld",*it);}printf("\n");return 0;}
阅读全文
0 0
- Problem A. Arithmetic Derivative-XVII Open Cup named after E.V. Pankratiev||找规律&数学&DFS
- Problem D. Clones and Treasures XVII Open Cup named after E.V. Pankratiev||简单模拟
- Problem L. Canonical duel XVII Open Cup named after E.V. Pankratiev||并查集
- Problem F. Matrix Game XVII Open Cup named after E.V. Pankratiev||字符串最大表示法
- XVII Open Cup named after E.V. Pankratiev. Eastern Grand Prix. Problem F. Buddy Numbers 贪心、数论、构造
- XVII Open Cup named after E.V. Pankratiev. Eastern Grand Prix. Problem G. Gmoogle 模拟、字符串处理、文本搜索
- XVII Open Cup named after E.V. Pankratiev. XXI Ural Championship G glassese of solutions
- XVII Open Cup named after E.V. Pankratiev. Grand Prix of SPb D cutting potatoes
- XVII Open Cup named after E.V. Pankratiev Problem I. Rage Minimum Query 手写小根堆、卡时间+卡内存、或者随机化
- 【opencup】XVI Open Cup named after E.V. Pankratiev. GP of SPB K.Captain Tarjan【树形dp】
- CodeForces - 630E A rectangle (数学规律)
- UVA 1640 The Counting Problem(统计题,找规律 + dfs)
- HDOJ-2058(The sum problem)(找规律)(数学)
- Problem A. Number Theory Problem(2016China-Final)【找规律】
- UVA 10161 --- Problem A.Ant on a Chessboard 找规律
- “玲珑杯”#19 A -- A simple math problem 找规律
- 数学+找规律题
- 【lightoj1008】数学找规律
- iOS NSData 转 字符串 (蓝牙特征值转字符串)
- git相关-- git命令 及 git add后 未commit git reset --hard如何恢复
- 从理解RNN到LSTM 网络
- 网页顶部加载进度条实现
- MyBatis学习路上打的那些码(二、准备工作和一个小demo)
- Problem A. Arithmetic Derivative-XVII Open Cup named after E.V. Pankratiev||找规律&数学&DFS
- ui bootstrap element iview
- 全面解读Math对象及位运算
- 1002:Lucky Word
- Codeforces 842C Ilya And The Tree(树上DP+因子个数估计)
- C++中const的用法
- java中transient关键字使用学习
- 最少拦截系统(最长上升子序列)
- 滴滴面试总结之MySQL存储引擎以及索引原理