DescriptionFarmer John commanded his cows to search for different sets of numbers the sum to a given number. The cows use is numbers that is an integer power of 2. Here is the possible sets of numbers that sum to 7:1) 1+1+1+1+1+1+1 2) 1+1+1+1+1+2 3) 1+1+1+2+2 4) 1+1+1+4 5) 1+2+2+2 6) 1+2+4 Help FJ count all possible representations for a given integer N (1 Given an N (1≤n≤10^6), use some 2 of the number of powers of the sum to find. Ask how many ways InputAn integer N.OutputThe number of metho
; atnowe:=b[nowe].f; - end; - end; - procedure BFs; - varL,r,now,nowe:longint; - begin inl:=1; r:=1; q[1]:=1; can[1]:=false;//sum:=1; - whileL Do to begin +now:=Q[l]; -nowe:=Head[now]; the whileNowe0 Do * begin $ //if (b[nowe].t=4) and (can[b[nowe].t]) then Writeln (' SB ');Panax Notoginseng ifcan[b[nowe].t] THEN begin - //Writeln (b[nowe].t); thecan[b[nowe].t]:=false; + Inc (R); A //Inc (SUM); theq[r]:=b[nowe].t; + end; -nowe:=b[nowe].f; $
Yesterday afternoon thought for a long time did not think out, sure enough is very weak, thinking ability is low.Like the idea of a monotone queue, maintenance of a length of the $k+1$ slider, each time the statistics $ans$ can be#include No more."Bzoj 3048" "USACO2013 Jan" Cow lineup Slider thought
Prefix and. Set F[i] As the first point of the prefix and%7=i. So the answer is Max (i-f[s[i]%7]).#include #include#includeusing namespacestd;Const intMAXN =50000+Ten;intA[MAXN],S[MAXN];intf[Ten],n,ans;intMain () { for(intI=1;i7; i++) f[i]=-1; scanf ("%d",N); for(intI=1; i) {scanf ("%d",A[i]); S[i]= (s[i-1]+a[i])%7; if(f[s[i]]==-1) f[s[i]]=i; Else{ans=max (ans,i-F[s[i]]); }} printf ("%d\n", ans);} bzoj4511: [Usaco2016 jan]subsequences summing to seve
is obviously a rmq problem, multiply the method, maintain the area of the maximum/small value on the line.1 varN,i,j,q,f,t,times:longint;2hmin,hmax:array[0.. -,0..50000] of Longint;3 function min (a,b:longint): Longint;4 begin5 ifA>B then exit (b)6 Elseexit (a);7 end;8 function Max (a,b:longint): Longint;9 beginTen ifA>B then exit (a) One Elseexit (b); A end; - begin - readln (n,q); the fori:=1to n Do - begin -READLN (hmax[0, I]); -hmin[0, i]:=hmax[0, I]; + end; - fori:=1to Tru
Title Link: BZOJ-3888Problem analysisFirst, the start and end points of each segment appearing at x coordinate 0 are calculated, and then the segments on the timeline are converted.Then it is to see if each segment is completely covered by a line whose y is smaller than it. Notice that the point of time to be discretized, and then should use the interval on the timeline to indicate that the two line ends coincident does not have a common part.After all the segments are sorted by Y from small to
public class Solution {public String inttoroman (int num) {int[] digits = new INT[4]; int i = 0; String s = ""; Digits[i] = num%10; while (num = NUM/10) > 0) {digits[++i] = num%10; } for (int j = 0; J Jan 14-integer to Roman; String; Integer; Math;
Code:public class Solution {public int maxarea (int[] height) { int low = 0; int high = height.length-1; if (High Jan 14-container with most water; Array; Pointer;
Code:public class Solution {public static string getpermutation (int n, int k) {string result = ""; if (n = = 1) return result + 1; int factorial_n = factorial (n-1); boolean[] isused = new Boolean[n]; Return Adddigit (Factorial_n, K-1, n-1, isused); } public static int factorial (int n) {if (n = = 1 | | n = = 0) return 1; Return n*factorial (n-1); } public static String adddigit (int factorial, int k, int n, boolean[] isused) {int times = k/factorial;
Test instructionsThe input n, m indicates that the sequence length is n and there is an ordered limit of M-bar {l,r,x}.Limit: The minimum value of all the l~r between the two is X.Asked the first few restrictions begin to appear contradictory, do not appear output "0".ExercisesFirst of all, the problem is quite strong, the normal solution is a bit difficult, it may be translated into two answers.We have a two-point "answer", that is, a contradiction in the ANS clause.Consider that if a limit s i
Use additional O (m+n) space, simple improvement. The one is of size row, to store the status of each row, and whether there is a 0 element in the row. Similarly, the other array of size col, storing the status of each column, the whether there are 0 element in the column. Then traverse the arrays, if the current element is true, which represents that there be at least one 0 element in the RO W (column). Then set all the elements in the row (column) to be zero.Code: Public classSolution { Public
this, we get a unique tree, and add the root to the list.Code:/*** Definition for a binary tree node. * public class TreeNode {* int val; * TreeNode left; * TreeNode rig Ht * TreeNode (int x) {val = x;} }*/ Public classSolution { PublicListintN) {ListNewArraylist(); if(n = = 0)returnret; returnListtrees (1, N); } PublicListintStartintend) { if(Start >end) {ListNewArraylist(); List.add (NULL); returnlist; } if(Start = =end) {ListNewArraylist(); List.add (NewTreeNode (start)
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.