[题意]对于n个数,找出一些数使得它们的和能被n整除,输出任意一组方案,n<=10^6. [算法]构造/结论 [题解]引用自:http://www.cnblogs.com/Sakits/p/7407103.html by Sakits 对n个数求前缀和,即sum[i]=sigma(a[1~i])%n,若sum[i]=0则找到答案,否则n个前缀和填充1~n-1,根据抽屉原理必有两个前缀和相同,则中间那一段数字之和是n的倍数. #include<cstdio> ],a[]; int main…
二次联通门 : LibreOJ #507. 「LibreOJ NOI Round #1」接竹竿 /* LibreOJ #507. 「LibreOJ NOI Round #1」接竹竿 dp 记录一下前驱就好了 再随便用前缀和优化一下 O(N) */ #include <iostream> #include <cstdio> ; char Buf[BUF], *buf = Buf; inline long long max (long long a, long long b) { re…
题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example: Given the below binary tree and sum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ / \ 7 2 5 1 return [ [5,4,11,2],…