codeforces [Gym-100814K]
题意给你一个a,b,问a除b小数点后n位中,子串组合的数能被p整除的有多少个
a,b位1e16,n为1e6,p为300
思路首先,要先处理出来后小数点后n位,这个就是模拟一下除法,很简单(当时没想到哈)这是一个有意思的“迪屁”这个梗是去年,北大吉如一比赛之后和队友说:这比赛太垃圾了,满场都是数据结构,连一个有意思的迪屁都没有。
接下来就该转移了,转移方程为dp[i][x] = g[i - 1][y] + int(a[i] % p == x)这个表示,到i这一位,子串能构成x的倍数有多少个,那个y满足,(y + a[i]) % p=x,y=(x - a[i] + p) % p;当你转移完了这一位的时候,当前i位对i+1位的影响就是x * 10,所以转移的时候不要忘了乘10,来作为下一位的转移的根据。
每一位都是由上一位转移过来,所以就可以滚动一下,滚第一维
PS:一个有点玄学的地方就是,如果你把n和p开成long long 就wrong了,我至今也不知道怎么回事,及其玄学。
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstring>
#include <map>using namespace std;
typedef long long LL;const int N = 1e6;
LL A[N + 5] , dp[2][300] , g[2][300];
LL a , b ; int p ,n ;int main()
{int T;scanf("%d",&T);while(T--){scanf("%lld %lld %d %d",&a , &b , &n , &p);for(int i = 1 ; i <= n ; i++){A[i] = (a * 10 / b);a = a * 10 % b;}memset(dp , 0 , sizeof(dp));memset(g , 0 , sizeof(g));LL ans = 0;int t = 0;for(int i = 1 ; i <= n ; i++){t = 1 - t;memset(g[t] , 0 , sizeof(g[t]));for(int x = 0 ; x < p ; x++){int y = (x - A[i] + p) % p;dp[t][x] = g[1 - t][y] + (LL)((A[i]) % p == x);g[t][(x * 10) % p] += dp[t][x];}ans = ans + dp[t][0];}printf("%lld\n",ans);}return 0;
}
codeforces [Gym-100814K]相关推荐
- Codeforces Gym 101173 CERC 16 D BZOJ 4790 Dancing Disks
Codeforces Gym 101173 CERC 16 D & BZOJ 4790 Dancing Disks 强烈安利这道构造题目,非常有意思. 这里用到的思想是归并排序! 多路归并排序 ...
- Codeforces Gym 101086 M ACPC Headquarters : AASTMT (Stairway to Heaven)
Codeforces Gym 101086 M ACPC Headquarters : AASTMT (Stairway to Heaven) 题目来源: Codeforces 题意: 给出一些比赛, ...
- [Codeforces Gym 101651/100725B] Banal Tickets
Codeforces Gym 100725 题解: 先分两种情况, 积为000与积非0" role="presentation" style="position ...
- Codeforces Gym 100513G G. FacePalm Accounting 暴力
G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...
- Codeforces Gym 100269 Dwarf Tower (最短路)
题目连接: http://codeforces.com/gym/100269/attachments Description Little Vasya is playing a new game na ...
- Codeforces Gym 100676G Training Camp 状压dp
http://codeforces.com/gym/100676 题目大意是告诉你要修n门课,每门课有一个权值w[i], 在第k天修该课程讲获得k*w[i]的学习点数,给出了课程与先修课程的关系,要修 ...
- codeforces Gym 100338E Numbers (贪心,实现)
题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...
- Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset
Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...
- Codeforces Gym 100650B Countdown (离线)
题目链接:http://codeforces.com/gym/100650 根据给出的树和d,求出一些结点,这些结点形成子树的第d层结点数应该尽量多,具体要求可以参考题目. dfs一个结点前保存询问深 ...
- Codeforces Gym 101630J Travelling from Petersburg to Moscow (最短路)
题目链接 http://codeforces.com/gym/101630/attachments 题解 zyb学长的题. 先枚举第\(k\)大的边权,设其边权为\(x\),然后把每条边边权减掉\(x ...
最新文章
- c 语言 声明 定义,C/C++语言声明与定义详解
- Lync 手机客户端登录过程
- 吉林大学c语言考试题库,吉林大学C语言题库.docx
- 【TweenMax】实例TimelineMax
- win10安装vbox没有虚拟网卡_消失的虚拟网卡
- 190523每日一句
- arcgis下载地址
- Pyinstller打包的exe文件反编译
- Unbuntu卸载anaconda(最新最全亲测)
- 时间序列预测 | Python实现GAN时间序列数据生成建模
- spss-多元线性回归分析
- matlab各向异性高斯核方向导数滤波器,加权组合多尺度各向异性高斯核对象轮廓检测...
- 三友硅业的化工厂人员定位系统——新导智能
- 关于win10输入法问题(打不出中文)解决方法
- 斑马zt410标签纸大小不能调的原因
- 定时任务:创建静态定时任务、动态定时任务
- Uncaught TypeError: Cannot read property ‘dispatch‘ of undefined
- 古筝d调变降e调怎么办_古筝怎么从D调转成E调
- yocto project
- Python语法学习之函数