Tc srm 552 div2

Source: Internet
Author: User

Reprint please indicate the source, thank you http://blog.csdn.net/ACM_cxlove? Viewmode = Contents
By --- cxlove

In a tragedy, the network is broken and the network is broken...

250pt: foxandflowershopdivtwo

A rectangle contains a lattice that cannot be retrieved. A child matrix contains the most 'F '.

Consider limiting the four sides of the grid to brute force attacks.

#include<iostream>#include<cstdio>#include<cstring>class FoxAndFlowerShopDivTwo{public:    int theMaxFlowers(vector <string> flowers, int r, int c){        int ans=0;        int R=flowers.size();        int C=flowers[0].size();        int t=0;        for(int i=0;i<r;i++)            for(int j=0;j<C;j++)                if(flowers[i][j]=='F')                    t++;        ans=max(t,ans);        t=0;        for(int i=r+1;i<R;i++)            for(int j=0;j<C;j++)                if(flowers[i][j]=='F')                    t++;        ans=max(t,ans);        t=0;        for(int i=0;i<R;i++)            for(int j=0;j<c;j++)                if(flowers[i][j]=='F')                    t++;        ans=max(t,ans);        t=0;        for(int i=0;i<R;i++)            for(int j=c+1;j<C;j++)                if(flowers[i][j]=='F')                    t++;        ans=max(t,ans);        return ans;    }};

500pt: foxpaintingbils

There are three colors of the ball, heap into a triangle with a height of N, the adjacent ball color cannot be the same, ask the maximum number of heap into a number.

A simple rule can be yy. When n % 3 = 0 or N % 3 = 2, the sum of each heap is a multiple of 3.

In addition, no matter how heap occurs, the number of balls in the three colors is the same.

The result is very simple. You can calculate the number of colors required for each heap. Just make a minimum judgment.

The next step is n % 3 = 1. We can find that it depends mainly on how the first layer is stacked. Each layer uses one more color than the other two colors, and the other two colors are the same.

Then you must think of putting the first layer with a maximum of colors. In part, this is correct, but the data range is large and cannot be simulated step by step.

In addition, after a period of time, the most colors are not the most.

N * (n + 1)/6 for each color is not considered. Then the remaining part is used as the extra ball.

But the rest may not be enough, so we will set the heap number to 1, and the remaining balls will come out until they are satisfied. Unfortunately, this was written during the competition, then it hangs on a group of data, TLE.

In fact, we can find that we don't need to simulate it step by step. If we don't consider the extra one, it's the ANS heap. Suppose we need to subtract the K heap. In the end, we must satisfy

Leftb + leftr + leftg + K * (N * (n + 1)/2-1)> = ANS-K, that is, there is an ANS-K heap, then we need to have at least ANS-K balls left, and simply solve the K of the inequality.

The comments are originally violent, TLE.

class FoxPaintingBalls{public:    long long theMax(long long R, long long G, long long B, int N){        LL ans=0;        LL n=N;        if(n%3!=1)            return min(B,min(R,G))/((LL)n*(n+1)/6);        if(R<G) swap(R,G);        if(R<B) swap(R,B);        if(G<B) swap(G,B);        if(n==1)  return B+R+G;        ans=min(R/(n*(n+1)/6),min(G/((n+1)*n/6),B/(n*(n+1)/6)));        LL leftR=R-(ans*(n*(n+1)/6));        LL leftG=G-(ans*(n*(n+1)/6));        LL leftB=B-(ans*(n*(n+1)/6));        if(leftB+leftG+leftR>=ans)  return ans;        return ans-(ans-(leftB+leftG+leftR)+n*(n+1)/2-1)/(n*(n+1)/2);      /*  while(1){            ans--;            leftB+=n*(n+1)/6;            leftR+=n*(n+1)/6;            leftG+=n*(n+1)/6;            if(leftB+leftG+leftR>=ans) return ans;        }      */    }};

1000pt: Maximize

Continue to obtain the YY rule. First, if n is less than K, it is clear that the nth position must be placed at the largest. Others, because the Lexicographic Order is the smallest, the order is from small to large.

Consider the case where K is an odd number. Let's push it back.

A0, a1, a2 ...... Ak-1, a0-a1 + A2 ...... + Ak-1, a1-a2 + a3-a4 ...... + (A0-a1 + A2 ...... + Ak-1)

Then we can find that the simplification of item k + 1 is A0, and so on, and item k + 2 is A1.

Only n % (k + 1) = K, the result is a0-a1 + A2 ...... + Ak-1, then require this maximum, obviously the odd number of items to take big, even number of items to take small.

In other cases, the maximum number of a (n % (k + 1) is required, which is the same as that of n <K.

Consider the case where K is an even number.

A0, A1, A2 ,...... Ak-1, a0-a1 + A2 -...... -Ak-1,-A0 + 2a1-2a2 + 2A3 ...... + 2ak-1, 2a0-3a1 + 4a2 ...... -4ak-1

We can find that the coefficients of each item are gradually increasing. First, when n is an even number, the odd coefficient is positive, and the even coefficient is negative. This requires that the odd number is big, the even number is small. Looking at the relative change of the coefficient, the coefficient of the following item is not smaller than the previous one. Therefore, for a large one, the latter is larger, and for a small one, the latter is smaller.

However, we found that when n is less than 2 * K, the coefficient of the negative number is not completely increasing, that is, the coefficient is the same, so no matter what the order is, the result is the same, the question requires us to follow the Lexicographic Order, so we need to sort the small series in ascending order.

Finally, through the parity of N, it is determined whether the odd digit is a large number or the even digit is a large number.

TC data is weak. If K is an odd number and N % (k + 1) = K, the coefficient is + 1,-1, so the small part of the number should also be in ascending order, and the sorting will also pass through in descending order .... Bytes

# Include <iostream> # include <cstdio> # include <cstring> # include <cmath> # include <vector> # include <string> # include <algorithm> # include <queue> # define ll long # define EPS 1e-7using namespace STD; bool CMP (int A, int B) {return A> B;} class foxplusminus {public: vector <int> maximize (vector <int> first, int N) {int K = first. size (); vector <int> ans, ans1, ans2; sort (first. begin (), first. end (); // when n <K, the nth bit is taken as the maximum I F (n <k) {for (Int J = 0, I = 0; j <K; I ++, J ++) if (j = N) {ans. push_back (first [k-1]); I --;} else ans. push_back (first [I]); Return ans;} If (K & 1) {// n % (k + 1) maximum if (N % (k + 1 )! = K) {n = n % (k + 1); For (Int J = 0, I = 0; j <K; I ++, J ++) if (j = N) {ans. push_back (first [k-1]); I --;} else ans. push_back (first [I]); Return ans;} // The larger the odd digit, the better, the smaller the even bit, the better the principle else {for (INT I = 0, j = K-1; I <K; I + = 2, j --) ans1.push _ back (first [J]); For (INT I = 1, j = 0; I <K; I + = 2, J ++) ans2.push _ back (first [J]); sort (ans1.begin (), ans1.end (); // when TC data is weak, the following sentence cannot be sorted, because the Lexicographic Order should be ascending // sort (ans2.begin (), ans2.end (), CMP); For (INT I = 0; I <min (ans1.size (), ans2.size (); I ++) {ans. push_back (ans1 [I]); ans. push_back (ans2 [I]);} If (ans1.size ()> ans2.size () ans. push_back (ans1 [ans1.size ()-1]); Return ans ;}} else {for (INT I = 0, j = K-1; I <K; I + = 2, J --) ans1.push _ back (first [J]); For (INT I = 1, j = 0; I <K; I + = 2, J ++) ans2.push _ back (first [J]); // sort (ans1.begin (), ans1.end ()); // small numbers from large to small sort (ans2.begin (), ans2.end (), CMP); If (n <2 * k) // the latter part of small numbers does not affect, sort (ans2.begin () + (n-k + 1)/2, ans2.end (); If (N & 1) {for (INT I = 0; I <K; I + = 2) {ans. push_back (ans2 [I/2]); ans. push_back (ans1 [I/2]) ;}} else {for (INT I = 0; I <K; I ++ = 2) {ans. push_back (ans1 [I/2]); ans. push_back (ans2 [I/2]) ;}} return ans ;}}};

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.