[ABC146E] Rem of Sum is Num】的更多相关文章

预处理即可 我们要找的是 (f[i] - f[j]) % k == i - j 移项可得 f[i] - i = f[j] - j 在 i - j <= k 的条件下 因此题目变成了,对于每个右端点,在它的左边 k - 1 个有多少个满足 f[i] - i = f[j] - j f[i] 是前缀和数组 AC_CODE #include <map> #include <iostream> #define LL long long using namespace std; cons…
[题目链接]:http://codeforces.com/contest/577/problem/B [相似题目]:http://swjtuoj.cn/problem/2383/ [题意]:给出n个数,问是否能从中选出一些数,使得这些数的和是m的倍数. [题解]: 首先,先明白这样一个事实: 设:sum%dend=rem; (sum:一些数的和,dend:被除数,rem:余数) 则有:(rem+n)%dend=(sum+n)%dend; (n为一个新的数) 知道了上面的等式之后,题目就好做了:…
下面是今天写的几道题: 292. Nim Game You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the winner. You will take t…
期望结果:  ID  VAL  CumSum  1  10  10  2  20  30  3  30  60 方法一: 使用分析函数 select id,val,sum(val) over ( order by id ) as CumSum from table 方法二: 如果不支持分析函数,使用join SELECT a.id, sum(b.num) as num from dbo.dt a inner join dbo.dt b on a.id>=b.id group by a.id 参考…
Divide Sum Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) SubmitStatisticNext Problem Problem Description long long ans = 0;for(int i = 1; i <= n; i ++)    for(int j = 1; j <= n; j ++)        ans += a[i] / a[j];给出n,a…
离线+分块!! 思路:序列a[1],a[2],a[3]……a[n] num[i]表示区间[L,R]中是i的倍数的个数:euler[i]表示i的欧拉函数值. 则区间的GCD之和sum=∑(C(num[i],2)*euler[i]).当增加一个数时,若有约数j,则只需加上num[j]*euler[j],之后再num[j]++; 反之亦然!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #inc…
Max Sum of Max-K-sub-sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7034    Accepted Submission(s): 2589 Problem Description Given a circle sequence A[1],A[2],A[3]......A[n]. Circle se…
http://acm.hdu.edu.cn/showproblem.php?pid=1003 给出一个包含n个数字的序列{a1,a2,..,ai,..,an},-1000<=ai<=1000 求最大连续子段和及其起始位置和终止位置,很基础的动态规划(DP)问题,看完DP第一次做的DP题目 DP真的是一种很优美的算法,或者说思想,但是比较难理解,我对DP的理解还很浅薄 # include <stdio.h> # define INF 1000000000 int main() { i…
因为是circle sequence,可以在序列最后+序列前n项(或前k项);利用前缀和思想,预处理出前i个数的和为sum[i],则i~j的和就为sum[j]-sum[i-1],对于每个j,取最小的sum[i-1],这就转成一道单调队列了,维护k个数的最小值. ---------------------------------------------------------------------------------- #include<cstdio> #include<deque&…
链接:http://acm.hdu.edu.cn/showproblem.php?pid=3415 意甲冠军:环.要找出当中9长度小于等于K的和最大的子段. 思路:不能採用最暴力的枚举.题目的数据量是10^5,O(N^2)的枚举回去超时.本题採用的非常巧妙的DP做法,是用单调队列优化的DP. 运用的是STL的deque,从i:1~a找到以当中以i为尾的符合条件的子段.并将i本身放入双向队列.全部i从队列后放入,保证了队列的单调性. 代码: #include <iostream> #includ…