Tc-552-div2

Source: Internet
Author: User
Tags acos

Question 250:

Retrieve a vertex from a matrix and find the matrix that does not contain the largest weight of that vertex.

You can directly enumerate four cases.

/* Gains: */# include <iostream> # include <cstdlib> # include <vector> # include <map> # include <cstring> # include <set> # include <string> # include <algorithm> # include <sstream> # include <ctype. h> # include <fstream> # include <string. h> # include <stdio. h> # include <math. h> # include <stack> # include <queue> # include <ctime> // # include <conio. h> using namespace STD; const int inf_max = 0x7fffff; const int inf_min =-(1 <30); const double EPS = 1e-10; Const double Pi = ACOs (-1.0); # define Pb push_back // A. Pb () # define chmin (A, B) (a) <(B )? (A) :( B) # define chmax (A, B) (a)> (B )? (A) :( B) template <class T> inline t gcd (t a, t B) // notes: gcd ({if (a <0) return gcd (-a, B); If (B <0) return gcd (A,-B); Return (B = 0 )? A: gcd (B, A % B);} template <class T> inline t lcm (t a, t B) // notes: lcm ({if (a <0) return lcm (-a, B); If (B <0) return lcm (A,-B); return a * (B/gcd (A, B ));} typedef pair <int, int> PII; typedef vector <PII> vpii; typedef vector <int> VI; typedef vector <VI> VVI; typedef long ll; int dir_4 [4] [2] = {}, {-}, {0,-1 }}; int dir_8 [8] [2] = {}, {-1,-1}, {0,-1 }, {1,-1}, {}, {}; // bottom, bottom left, left, top left, top right, top right, right bottom. ****************************** ********************************* // Flag = 0, horizontal; flag = 1, vertical int calc (vector <string> flowers, bool flag, int start, int end) {int ret = 0; If (Start> end) return 0; if (! Flag) {for (Int J = 0; j <flowers [0]. length (); j ++) {for (INT I = start; I <= end; I ++) {If (flowers [I] [J] = 'F') RET ++ ;}} else {for (INT I = 0; I <flowers. size (); I ++) {for (Int J = start; j <= end; j ++) {If (flowers [I] [J] = 'F') RET ++ ;}}return ret;} class foxandflowershopdivtwo {public: int themaxflowers (vector <string> flowers, int R, int c) {int ret = 0, TMP; TMP = calc (flowers, false, 0, R-1 ); ret = chmax (TMP, RET); TMP = calc (flowers, false, R + 1, flowers. size ()-1); ret = chmax (TMP, RET); TMP = calc (flowers, true, 0, C-1); ret = chmax (TMP, RET ); TMP = calc (flowers, true, C + 1, flowers [0]. length ()-1); ret = chmax (TMP, RET); return ret ;}}; // powered by fileedit // powered by tztester 1.01 [25-feb-2003] // powered by codeprocessor

500:

The question requires that three colors be used to dye a bunch of balls in a triangle. The colors of adjacent balls are different. Note that there will be rules :.

1

2 3

3 1 2

1 2 3 1

2 3 1 2 3

3 1 2 3 1 2

There are two scenarios for the number of balls:

1. The number of balls of the same color in 1, 2, and 3 is n % 3 = 2;

2. One more of the color 1 in all 1, 2, and 3. The color 2 and 3 are the same. The number of color 1 is Ceil (sum/3), and the number of color 2 and 3 is floor (sum/3), where SUM = (n + 1) * N;

Three colors of RGB can dye up to R, G, and B respectively. There are two cases:

1. The total number of R + G + B is not enough, and the number of dyeing is limited. The value is floor (R + G + B)/sum );

2. The minimum color limit is the number of colors. Floor (min_color/Ceil (sum/3); min_color = min (R, G, B );

Code:

/* Gains: */# include <iostream> # include <cstdlib> # include <vector> # include <map> # include <cstring> # include <set> # include <string> # include <algorithm> # include <sstream> # include <ctype. h> # include <fstream> # include <string. h> # include <stdio. h> # include <math. h> # include <stack> # include <queue> # include <ctime> // # include <conio. h> using namespace STD; const int inf_max = 0x7fffff; const int inf_min =-(1 <30); const double EPS = 1e-10; Const double Pi = ACOs (-1.0); # define Pb push_back // A. Pb () # define chmin (A, B) (a) <(B )? (A) :( B) # define chmax (A, B) (a)> (B )? (A) :( B) template <class T> inline t gcd (t a, t B) // notes: gcd ({if (a <0) return gcd (-a, B); If (B <0) return gcd (A,-B); Return (B = 0 )? A: gcd (B, A % B);} template <class T> inline t lcm (t a, t B) // notes: lcm ({if (a <0) return lcm (-a, B); If (B <0) return lcm (A,-B); return a * (B/gcd (A, B ));} typedef pair <int, int> PII; typedef vector <PII> vpii; typedef vector <int> VI; typedef vector <VI> VVI; typedef long ll; int dir_4 [4] [2] = {}, {-}, {0,-1 }}; int dir_8 [8] [2] = {}, {-1,-1}, {0,-1 }, {1,-1}, {}, {}; // bottom, bottom left, left, top left, top right, top right, right bottom. ****************************** * ********************************* Class foxpaintingbils {public: long long themax (long R, long g, long B, int N) {ll Minx = chmin (R, chmin (G, B )); ll tot = (n + 1) * n/2; ll one = TOT/3; if (n = 1) return r + G + B; return chmin (R + G + B)/tot, Minx/One) ;}}; // powered by fileedit // powered by tztester 1.01 [25-feb-2003] // powered by codeprocessor

1000 points. Currently, no. Please wait for the problem to be solved...

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.