sum (bestcoder)】的更多相关文章

分析:就是判断简单的前缀有没有相同,注意下自身是m的倍数,以及vis[0]=true; #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <iostream> #include <algorithm> #include <map> #include <queue> #include <vect…
sum Accepts: 640 Submissions: 1744 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) 问题描述 给定一个数列,求是否存在连续子列和为m的倍数,存在输出YES,否则输出NO 输入描述 输入文件的第一行有一个正整数T(1≤T≤101\leq T \leq 101≤T≤10),表示数据组数. 接下去有T组数据,每组数据的第一行有两个正整数n,m (1≤n…
sum 题意: 问题描述 给定一个数列,求是否存在连续子列和为m的倍数,存在输出YES,否则输出NO 输入描述 输入文件的第一行有一个正整数T,表示数据组数. 接下去有T组数据,每组数据的第一行有两个正整数n,m . 第二行有n个正整数x 表示这个数列. 输出描述 输出T行,每行一个YES或NO. 输入样例 2 3 3 1 2 3 5 7 6 6 6 6 6 输出样例 YES NO 题解: 这题虽说是1001,但当时真的不会,最后问了学长才知道,要用什么鸽巢定理,大致是这样的:给你一个n个数的数…
大晚上的更一道下午的水题吧.(虽然WA了好多次= =,但真实情况是我比较水) 描述 Given a sequence, you're asked whether there exists a consecutive subsequence whose sum is divisible by m. output YES, otherwise output NO. 输入 The first line of the input has an integer T (1≤T≤10), which repr…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5586 题目大意就是把一段序列里面的数替换成f(x),然后让总和最大. 首先可以计算出初始的总和,以及每一个值换成f(x)的增益a[x]. 那么就是求一段子序列a[x]的最值了,经典的DP. 其实我一开始想到这个思路是因为列了一个式子: S = sum(n)-sum(rt)+sum’(rt)-sum’(lt)+sum(lt) =sum(n)+(sum’(rt)-sum’(lt))-(sum(rt)-s…
HDU 5666 Segment 题意:给你条斜率为-1,常数项为q(q为质数)的直线,连接原点与直线上整数格点,问你在有多少个格点在形成的无数个三角形内,而不在线段上,结果对P取模. 思路:bestcoder题解上有思路,一条以(0,0)为起点,(x,y)为终点的线段上格点的个数(不包含端点时),一定是gcd(x,y)−1,题目由于p为质数,所以所有线段上都没有格点,需要注意的是p为质数,情况就很少了,然后就是数据太大的问题,改一改快速幂就可以了. #include <cstdio> #in…
A题 Aaronson http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=718&pid=1001 感觉一开始写的这个不好,太冗余了. #include <cstdio> int main() { int n,m; int t; while(~scanf("%d",&t)) { while(t--) { scanf("%d%d",&n,&…
1.BestCoder Round #89 2.总结:4个题,只能做A.B,全都靠hack上分.. 01  HDU 5944   水 1.题意:一个字符串,求有多少组字符y,r,x的下标能组成等比数列. 2.总结:有个坑,y,r,x顺序组公比q>1,也可反着来x,r,y顺序组. #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorit…
Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 354    Accepted Submission(s): 100 Problem Description ZYB has a tree with N nodes,now he wants you to solve the numbers of nodes distanced no m…
题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cstdio> #include <iostream> #include <cstring> #include <string> #include <algorithm> using namespace std; ; const int INF = 0x3f3f…