HackerRank "Playing with numbers"】的更多相关文章

This is 'Difficult' - I worked out it within 45mins, and unlocked HackerRank Algorithm Level 80 yeah! So the idea is straight forward: 1. sort the input array and calculate partial_sum()2. find the negative\positive boundary with the accumulated give…
Numeros, The Artist, had two lists A and B, such that, B was a permutation of A. Numeros was very proud of these lists. Unfortunately, while transporting them from one exhibition to another, some numbers from List A got left out. Can you find out the…
Sorting is often useful as the first step in many different tasks. The most common task is to make finding things easier, but there are other uses also. Challenge Given a list of unsorted numbers, can you find the numbers that have the smallest absol…
C. Wizards and Numbers 题目连接: http://codeforces.com/problemset/problem/167/C Description In some country live wizards. They love playing with numbers. The blackboard has two numbers written on it - a and b. The order of the numbers is not important. L…
A. Colourful Graph 可以在$2n$步之内实现交换任意两个点的颜色,然后就可以构造出方案. #include <bits/stdc++.h> using namespace std ; typedef long long LL; const int mod=1e9+7,Maxn=222; const LL Inf=1LL<<60; int n,m,K; int col[Maxn],col2[Maxn]; int done[Maxn],pre[Maxn]; vecto…
Codechef April Challenge 2019 游记 Subtree Removal 题目大意: 一棵\(n(n\le10^5)\)个结点的有根树,每个结点有一个权值\(w_i(|w_i\le10^9|)\).你可以进行若干次(包括\(0\)次)操作,每次你可以选择一个连通块,将其删去.若你的操作次数为\(k\),则总收益为剩下结点权值之和\(-X\cdot k\).求最大总收益. 思路: 树形DP,\(f_x\)表示以\(x\)为根的子树的最大总收益.转移时\(f_x=w_x+\s…
Maximum Remaining 题意:给n个数,取出两个数$a_{i}$,$a_{j}$,求$a_{i}\% a_{j}$取模的最大值 直接排个序,第二大(严格的第二大)模第一大就是答案了. #include <bits/stdc++.h> using namespace std; int a[(int)1e6]; int main() { ios::sync_with_stdio(false); cin.tie(); int n; cin >> n; ; i < n;…
Subtree Removal 很显然不可能选择砍掉一对有祖先关系的子树.令$f_i$表示$i$子树的答案,如果$i$不被砍,那就是$a_i + \sum\limits_j f_j$:如果$i$被砍,那就是$-x$.取个$max$就好了. 时间.空间复杂度$O(n)$. #include <bits/stdc++.h> using namespace std; ; int tc, n, xx; int a[N]; vector<int> g[N]; long long f[N];…
MASTERING CREATIVITY, 1st EditionThis guide is free and you are welcome to share it withothers.From James Clear:For most of my life, I didn't consider myself to be particularly creative. I didn't play a musicalinstrument (or even know how to read mus…
传送门 \(Maximum\ Remaining\) 对于两个数\(a,b\),如果\(a=b\)没贡献,所以不妨假设\(a<b\),有\(a\%b=a\),而\(b\%a<a\).综上,我们可以发现答案就是严格次大值 //minamoto #include<bits/stdc++.h> #define R register #define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i) #define fd(i,a,b) for(R i…