"Problem Solving report" CF Round #320 (Div. 2)

Source: Internet
Author: User
Tags polyline

Raising bacteria

Test instructions: The number of germs in the box doubles every day, and you can put as many germs as you want on any given day, and finally make the number of bacteria in the box equal to X, and ask at least how many bacteria to put in.

Idea: Obviously, Double is the binary left one bit, then put a bacterium, to the next day into 2 binary is the 1->10 for any binary number such as: 1001110, only need to put 1 in the first day, 4th, 5, 6 days each put one, and so on a day, you can. So the answer is clearly the number of x in binary 1.

Finding Team Member

Test instructions: 2n individuals, each team of two people has the power of AIJ. Everyone wants the team to be the most powerful. How it will eventually be combined.

Idea: Find the largest figure in the matrix AIJ, obviously IJ will form a team, and then IJ has teamed up, and the IJ-related columns are deleted, and then find the remaining maximum combination. The answer can be answered by analogy.

Looking directly in the matrix will obviously time out. We can sort each of the matrices and then scan and mark each of the teammates from the big to the small, and then scan to a value to see if the corresponding IJ is already teaming up and skip this if you've already teamed up.

A problem about Polyline

Test instructions: polyline over point (0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – ...-(2 KX, 0) – (2kx + x, x) – .... The smallest x given a coordinate (a, b) causes the polyline to pass through a point (a, B).

Idea: First calculate the coordinates (a+b,0) of the position of the first x-axis after that point, and then find the x-coordinate of the point at a total of several points. That is (a+b)/b. It then takes a multiple of 2, which is the number of line segments for this polyline. Then we can calculate the X.

"Or" Game

Test instructions: Given a sequence, you can manipulate k times, each time you select one of the numbers to multiply it by X, so that when the operation is complete, all numbers are performed or the result of the operation is the largest.

Idea: Consider the binary of all numbers. If there is a number with the largest number of bits, then it must be used for all operations on this number, because the number of bits multiplied by the number of X will increase, and all the number or the result of the bits number is equal to the maximum number of bits in this series, Therefore, the number of binary digits will be the largest (because X is greater than or equal to 2) if all operations are used on the bits number that is the largest.

When this is done, what if there are multiple numbers with the largest number of bits and the same? So first consider the first operation will definitely operate on one of these numbers, and after the operation, the number becomes the only bits number of the largest, then the next operation is certainly in this number, so you can conclude that K operations will be used in the same number!

As for which one, direct traversal is good ~

It is important to note that, when traversing, the o[i]=a[0]|a[1]|...| can be preprocessed first. a[i-1]|a[i+1]|a[i+2]|...| A[N-1], this step can be O (n) completed, and then calculate the value of the first position and then o[i] fetch or.

O[i], first preprocess the left half: a[0]. A[i-1], and then the right half of a[i+1]...a[n-1]. Each scan can be completed in two steps.

Weakness and Poorness

Test instructions: Given a sequence a1~an, one x makes the a1-x,a2-x,..., an-x weakness minimum.

Weakness defined as the poorness of the largest subsequence of a sequence

Poorness is the absolute value of the sum of this sequence.

Idea: Assuming there is only one sequence, we ask for an X to make the poorness of this sequence minimal. By taking x as the independent variable, the result of this poorness as the function f (x), it can be learned that f (x) is a convex function (first increases, then becomes smaller, the middle may have a constant).

So the question we ask for is G (x) =min (F1 (x), f2 (x) ...). It can be learned that g (x) is also a convex function. g (x) The function value of this function can be solved by DP. is the largest continuous sub-segment and DP.

So the problem is to ask G (X) The extremum of the convex function, the direct set of three-point solution can be.

PS: The accuracy of this problem card is a bit tight ...

#include <stdio.h>#include<algorithm>#include<string.h>#include<math.h>#include<map>#include<queue>#include<Set>using namespacestd;#defineCIN (x) scanf ("%d", &x)#definefor (I,n) for (i=0;i< (n); i++)#defineCLR (a,v) memset (A, (v), sizeof (a))inta[200005];intN;DoubleFDoublex) {    Doubleans1=0, ans2=0; Doubleansans1=0, ansans2=0;  for(intI=0; i<n;i++) {ans1=max (ans1+ (A[i]-x), (a[i]-x)); Ansans1=Max (ANS1,ANSANS1); Ans2=min (ans2+ (A[i]-x), (a[i]-x)); Ansans2=min (ans2,ansans2); }    returnMax (ansans1,-ansans2);}DoubleSanfen (DoubleLDoubleR) {    DoubleMid,midmid,fmid,fmidmid; Mid= (l+r)/2; Midmid= (mid+r)/2; Fmid=f (mid); Fmidmid=f (midmid);  while(r-l>0.00000000001){        if(fmid>Fmidmid) {L=mid; Mid=Midmid; Fmid=Fmidmid; Midmid= (mid+r)/2; Fmidmid=f (midmid); }Else{R=Midmid; Midmid=mid; Fmidmid=Fmid; Mid= (L+midmid)/2; Fmid=f (mid); }    }    returnFmid;}intMain () {CIN (n); intma=-10000, I; intMi=10000;        for (i,n) {CIN (a[i]); Ma=Max (A[I],MA); Mi=min (a[i],mi); } printf ("%.12lf\n", Sanfen (Mi,ma)); return 0;}

The last question does not do ...

"Problem Solving report" CF Round #320 (Div. 2)

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.