【HDOJ】4704 Sum】的更多相关文章

数学题.f(n) = 2^(n-1) mod (1e9+7). #include <cstdio> #define MAXN 100005 char buf[MAXN]; __int64 phi = 1e9+; __int64 mod = 1e9+; __int64 power2(__int64 n) { __int64 ret = , ; --n; while (n) { ) ret = ret * base % mod; base = base*base%mod; n >>=…
典型的深搜,剪枝的时候需要跳过曾经搜索过的相同的数目,既满足nums[i]=nums[i-1]&&visit[i-1]==0,visit[i-1]==0可以说明该点已经测试过. #include <stdio.h> #include <string.h> #define MAXNUM 1005 int nums[MAXNUM]; int visit[MAXNUM]; int t, n; void output() { ; ; i<t; ++i) { if (j…
[LeetCode]129. Sum Root to Leaf Numbers 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/sum-root-to-leaf-numbers/description/ 题目描述: Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a numbe…
404. Sum of Left Leaves [题目]中文版  英文版 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: int sumOfLeftLea…
[题意]对于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…
[Description] Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target,…
Difficulty: Easy  More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/sum-of-square-numbers/submissions/ Given a non-negative integer c, your task is to decide whether there're two integers aand b such that a2 + b2 = c. Example 1: Inpu…
题目如下: 解题思路:我的想法对于数组中任意一个元素,找出其左右两边最近的小于自己的元素.例如[1,3,2,4,5,1],元素2左边比自己小的元素是1,那么大于自己的区间就是[3],右边的区间就是[4,5].那么对于元素2来说,和左边区间合并组成[2,3]以及和右边区间合并组成[2,4,5],这两段区间包括2在内的所有subarray的最小值都是2,其分别可以组成的subarry的个数是 len([3])和len([4,5]),左右区间合并在一起可以组成的subarray的个数是len([3])…
划分树解.主席树解MLE. /* 3473 */ #include <iostream> #include <sstream> #include <string> #include <map> #include <queue> #include <set> #include <stack> #include <vector> #include <deque> #include <algorit…
DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……sigh) //HDOJ 3415 #include<queue> #include<cmath> #include<vector> #include<cstdio> #include<cstring> #include<cstdlib>…