poj 3844
来源:互联网 发布:linux tcpdump 用法 编辑:程序博客网 时间:2024/06/06 04:15
题意:给好多数,看有多少个子串的和能被某数整除。
暴搜会超时,是一道技巧题
解题代码:
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>#include <stack>#include <queue>#include <vector>#include <iostream>#include <algorithm>using namespace std;#define MAX 1000010#define eps 1e-8#define LL __int64#define N 360#define Pi 3.1415926535int a[MAX];LL ans;int main(){ int i ,j ,k ,t ,n ,d ; scanf("%d",&t); while(t--){ scanf("%d%d",&d,&n); memset(a,0,sizeof(a)); int num = 0; ans = 0; while(n--){ scanf("%d",&k); num = (num+k)%d; if(num == 0) { a[num]++; } ans += a[num]; if(num != 0) { a[num]++; } } printf("%I64d\n",ans); }return 0;}
0 0
- poj 3844
- POJ 3844 Divisible Subsequences
- poj 3844 Divisible Subsequences
- POJ 3844Divisible Subsequences
- POJ 3844 Divisible Subsequences
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- c练习题1:求最大公约数,最小公倍数
- srand ()与rand()函数小应用之猜数游戏
- Spring2.5.6的注入讲解
- Selenium WebDriver操作ligerui记录
- dijkstra_最短路径_hdu_3790
- poj 3844
- 多线程(六):ThreadLocal 关键字
- word2010总是出现配置进度框、word2003关闭时出现:您正试图运行的函数包含有宏
- MFC 读取配置文件ini
- 黑马程序员--Java基础--认识JAVA
- .NET 时间字符串转换
- 信号章节相关概念
- MFC中注册DLL函数
- POJ 1269 Intersecting Lines(判断两直线关系)