SRM summary 440

Source: Internet
Author: User

Question 1: http://www.topcoder.com/stat? C = problem_statement & PM = 10309.

Solution: According to DI = 1/2 * g * (Ti ^ 2), take the first one as a reference to obtain the proportional relationship between all the following and the first one.

Then calculate the first T1 according to sum (Ti) = T, and then find G according to D1 = 1/2 * g * (T1 ^ 2 ).

Later, I looked at other people's code and found that there is a simpler method. I first enlightened T.

# Include <iostream> <br/> # include <stdio. h> <br/> # include <vector> <br/> # include <cmath> <br/> using namespace STD; </P> <p> struct incrediblemachineeasy <br/> {<br/> double fun (INT Xi, int X1) <br/>{< br/> return SQRT (double) XI/X1); <br/>}< br/> double gravitationalacceleration (vector <int> height, int t) <br/>{< br/> double totel = 1; <br/> for (INT I = 1; I <peight. size (); I ++) <br/>{< br/> totel + = fun (height [I], height [0]); <br/>}< br/> // cout <totel <Endl; <br/> double T = (double) T/totel; <br/> return 2.0 * (double) height [0]/(T * t); <br/>}< br/> };

Question 2: http://www.topcoder.com/stat? C = problem_statement & PM = 10288.

Solution: search for records and make statistics.

# Include <iostream> <br/> # include <vector> <br/> # include <string> <br/> using namespace STD; </P> <p> struct mazewandreingeasy <br/> {<br/> int Sx, Sy; <br/> int; <br/> bool flag [55] [55]; <br/> int dir [4] [2]; // = }, {0}, {0,-1 }}; </P> <p> bool judge (int x, int y) <br/>{< br/> If (x> = 0 & x <SX & Y> = 0 & Y <Sy) <br/> return true; <br/> return false; <br/>}</P> <p> void DFS (vector <string> maze, int X, int y, int totel) <br/>{< br/> If (maze [x] [Y] = '*') <br/>{< br/> An = totel; <br/>}< br/> flag [x] [Y] = true; // EXE <br/> int COUNT = 0; <br/> bool f [10]; <br/> int XX, YY; <br/> memset (F, false, sizeof (f )); <br/> for (INT I = 0; I <4; I ++) <br/>{< br/> xx = x + dir [I] [0]; <br/> YY = Y + dir [I] [1]; <br/> If (Judge (XX, YY) = false) continue; <br/> If (maze [XX] [YY] = 'X') continue; <br/> If (flag [XX] [YY] = true) continue; <br/> count ++; <br/> F [I] = true; <br/>}< br/> int add = 0; <br/> If (count> 1) Add = 1; <br/> for (Int J = 0; j <4; j ++) <br/>{< br/> If (F [J] = false) continue; <br/> xx = x + dir [J] [0]; <br/> YY = Y + dir [J] [1]; <br/> DFS (maze, XX, YY, totel + Add ); <br/>}</P> <p> int decisions (vector <string> maze) <br/>{< br/> SX = maze. size (); <br/> Sy = maze [0]. size (); <br/> for (INT I = 0; I <SX; I ++) <br/> {<br/> for (Int J = 0; j <sy; j ++) <br/> {<br/> If (maze [I] [J] = 'M ') <br/>{< br/> memset (flag, false, sizeof (FLAG); </P> <p> dir [0] [0] =-1; dir [0] [1] = 0; <br/> dir [1] [0] = 1; dir [1] [1] = 0; <br/> dir [2] [0] = 0; dir [2] [1] =-1; <br/> dir [3] [0] = 0; dir [3] [1] = 1; </P> <p> int temp = 0; <br/> DFS (maze, I, j, temp ); <br/> return an; <br/>}< br/> };

Question 3: http://www.topcoder.com/stat? C = problem_statement & PM = 10289.

Solution: Use next_permutation () to generate a full arrangement and judge in sequence. A group of data in system test 238 has timed out. I also know that the big data will time out, but the DP Method hasn't come up yet, so I should stop this one first. Thank you!

# Include <iostream> <br/> # include <algorithm> <br/> # include <vector> <br/> using namespace STD; </P> <p> // denominator: size! </P> <p> struct wickedteacher <br/> {<br/>/* <br/> void print (iterator: vector <int> X) <br/>{< br/> cout <* x <""; <br/>}< br/> */<br/> long gcd (long, long B) <br/>{< br/> If (B = 0) return a; <br/> return gcd (B, A % B ); <br/>}< br/> string cheatprobability (vector <string> numbers, int K) <br/>{< br/> int size = numbers. size (); <br/> vector <int> test (size); <br/> for (INT I = 0; I <size; I ++) test [I] = I; <br/> Long Count = 0; </P> <p> int sum = 0; <br/> for (Int J = 0; j <size; j ++) <br/> for (INT r = 0; r <numbers [test [JJ]. size (); R ++) <br/>{< br/> sum = sum * 10 + numbers [test [JJ] [r]-'0 '; <br/> sum % = K; <br/>}</P> <p> If (sum = 0) Count ++; </P> <p> while (next_permutation (test. begin (), test. begin () + size) <br/>{< br/> // for_each (test. begin (), test. begin () + size, print); <br/>/* <br/> for (INT I = 0; I <test. size (); I ++) <br/>{< br/> cout <test [I]; <br/>}< br/> cout <Endl; <br/> */<br/> // test [0]... test [last] <br/> sum = 0; <br/> for (Int J = 0; j <size; j ++) <br/> {<br/> for (INT r = 0; r <numbers [test [J]. size (); R ++) <br/>{< br/> sum = sum * 10 + numbers [test [J] [r]-'0 '; <br/> sum % = K; <br/>}< br/> If (sum = 0) Count ++; <br/>}< br/> long totel = 1; <br/> for (int p = 2; P <= size; P ++) totel * = P; <br/> long temp = gcd (totel, count); <br/> totel/= temp; <br/> count/= temp; <br/> // count/totel <br/> string STR; <br/> If (totel = 0) <br/> Str. push_back ('0'); <br/> else <br/> while (totel) <br/>{< br/> Str. push_back (totel % 10 + '0'); <br/> totel/= 10; <br/>}< br/> Str. push_back ('/'); <br/> If (COUNT = 0) <br/> Str. push_back ('0'); <br/> else <br/> while (count) <br/> {<br/> Str. push_back (count % 10 + '0'); <br/> count/= 10; <br/>}< br/> reverse (Str. begin (), str. end (); <br/> return STR; <br/>}< br/> };

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.