Hash, because the question requires a k-th number, many people may think of sorting from small to large and then finding the k-th number. However, note that | Xi-XJ | duplicate operations may occur, that is, the sorting order must be processed.
The
Started with Floyd, TLE! In the second step, I found a set of 1000 pieces of data. After 4S was taken out, the program itself had a problem. I handed it in again... Later, I used Dijkstra to do it... 200 + ms;
#include #include #include using
/* I started thinking about this question last night. I saw my teammate 1y passing through quickly, which was a hit. Then I keep thinking about various situations.Status, all kinds of debug, failed. In the afternoon, another teammate was also very
This is a bare monotonous queue problem, but the O (n) algorithm is 5188 + MS, which is more than 5s... Who can tell me what the God-class code of 500 + MS is... T_t
My code:
#include #include #include using namespace std;const int N =
To output the longest ascending subsequence, you only need to add a pre array to record the first of the newly added sequence. You can traverse the array once.
The Code is as follows:
# Include # Include # Include Using namespace STD;Const int n= 100
It seems like a problem. Prim, 48 Ms water over...
#include #include #include using namespace std;const int N = 505;const int inf = 0x7ffffff;int dis[N][N];int low[N];int vis[N];int v[N];void Prim(int n){int flag, i, j, min, sum = 0;for(i = 1; i
The trie tree can be classified as an advanced data structure. In the black book, The trie tree and the line segment tree are discussed together. It is called a dictionary tree probably because its structure is too similar to a dictionary.
Like this
Trie, insert each word into the trie tree, and then forcibly split each word into the tree to find a match! There are several details to be aware of, all marked in the code comments.
My code:
# Include # Include # Include Using namespace STD;Const
Problem 1: greedy, I'm two...
Problem 2, i'm speechless...
Fast Power function:
Int exp_mod (int A, int N, int B){Int T;If (n = 0) return 1% B;If (n = 1) return a % B;T = exp_mod (A, n/2, B );T = T * T % B;If (N & 1) = 1) t = T * A % B;Return T;}
/* Question: calculate the number of the sum of numbers in the range [1 to 10 ^ 9;Idea: Define DP [I] [J] (I = 1 to 9, j = 1 to 81), which indicates the sum of the numbers with the bits of I and the sum of the bits of J.Number. DP [I] [J] = (I-1
When I checked the spfa information, I occasionally saw a kind of application, and then I knocked on 1A very calmly.
15 ms + 328 K code:
#include #include #include using namespace std;const int N = 207;const int inf = 100000000;int vis[N], map[N][N];
/* Contribute countless wa, just because I wrote a mistake in one place. It was a miserable evening! However, it's still nice to be able to pass.Idea: Use the trie tree to re-label the string, then use and query sets, use a [I] to record the
Code + notes:
# Include # Include # Include Using namespace STD;Const int n= 100;Int s [N];Bool used [N];Int CMP (int A, int B){Return A> B;}Bool DFS (int n, int U, int left, int Len){// N is the total number of wooden sticks.// U is the number of
The data in this question is a bit problematic. I don't know how much is the maximum number of N numbers. I guessed the number and used Hash to do it. Actually, I got 1a ....
# Include # Include # Define n 100007Int hash [N];Int main (){Int N,
/* Set the reverse order number of the original sequence to sum, move one number each back, you can find the regular sum + = n-2 * num [I]-1;(N indicates the number of elements, and num [I] indicates the number of Moving Elements );When finding the
The shortest path is very bare. Here we use Dijkstra to solve the problem. The front side has already written the Floyd and spfa algorithms.
Spfa: http://www.cnblogs.com/vongang/archive/2011/08/16/2141334.html
FLOYD:
I didn't understand it at first, but I still wanted to use DFS for Recursive solution. Later I looked at the solution report (it seems that this question can be solved using DP) and BFS again, store the optimal solution to I with a best [I] and
More than 1085 changes, see the code.
My code:
#include #include #include using namespace std;const int N = 250007;struct node {int val;int num;} a[55];int c1[N], c2[N];int main() {//freopen("data.in", "r", stdin);int n, i, j, sum, k;while(cin >> n)
/* The question is to find the largest submatrix, indicating that the line generation has not learned well. Fortunately, this question is not affected. The main idea of this question is to convert two dimensions into one dimension. Add the elements
/* Today I reviewed the previously made SG function questions. The original code of this question actually ran 781 ms, and I was dizzy! Write againOnce, the VIS array is defined as a global variable, wa... T_tMy code (78 + MS ):*/# Include # Include
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service