USACO 1.4

Source: Internet
Author: User

PROB Packing Rectangles [ANALYSIS] ---- the first question is what we saw three days ago. After taking an exam, the whole school answered the question. Today, I finally came out and thought about it every day, I finally understood this question.

/* Solution 11 enumerative permutation Number 2 enumeration Flip 3 MINIMUM enumeration in 6 cases 4 Minimum all records all minimum values */int rectx [4], recty [4]; int meijux [4], meijuy [4]; bool vis [4]; int sumx, sumy, sumarea = INT_MAX; map <PII, int> vec; map <PII, int >:: iterator p; void update (int x, int y) {if (sumarea> x * y) {sumarea = x * y; vec. clear (); vec [make_pair (min (x, y), max (x, y)] = 1;} else if (sumarea = x * y) {vec [make_pair (min (x, y), max (x, y)] = 1 ;}} int maxb (int a = 0, int B = 0, int c = 0, int d = 0) {Return max (a, max (B, max (c, d);} // judge the void check () function () {// case 1 // 0 1 2 3 sumx = meijux [0] + meijux [1] + meijux [2] + meijux [3]; sumy = maxb (meijuy [0], meijuy [1], meijuy [2], meijuy [3]); update (sumx, sumy ); // case 2 // 0 1 2 // 3 sumx = maxb (meijux [0] + meijux [1] + meijux [2], meijux [3]); sumy = meijuy [3] + maxb (meijuy [1], meijuy [2], meijuy [0]); update (sumx, sumy ); // case 3 // 0 1 2 // 3 2 sumx = meijux [2] + maxb (meijux [0] + Meijux [1], meijux [3]); sumy = maxb (meijuy [3] + maxb (meijuy [0], meijuy [1]), meijuy [2]); update (sumx, sumy); // case 4 // 0 1 3 // 2 sumx = maxb (meijux [1], meijux [2]) + meijux [0] + meijux [3]; sumy = maxb (meijuy [1] + meijuy [2], meijuy [0], meijuy [3]); update (sumx, sumy); // case 5 // case 6 // 0 1 // 2 3 sumy = maxb (meijuy [0] + meijuy [2], meijuy [1] + meijuy [3]); if (meijuy [2]> = meijuy [3]) {if (meijuy [2]> = meijuy [3] + meijuy [1]) {Sumx = maxb (meijux [1], meijux [3]) + meijux [2], meijux [0]);} else {sumx = maxb (meijux [2] + meijux [1], meijux [2] + meijux [3], meijux [0] + meijux [1]);} else {if (meijuy [3]> = meijuy [0] + meijuy [2]) {sumx = maxb (meijux [0], meijux [2]) + meijux [3], meijux [1]);} else {sumx = maxb (meijux [2] + meijux [3], meijux [0] + meijux [3], meijux [0] + meijux [1]); }}// DB (sumx <"" <sumy); update (sumx, sumy);} void dfs (in T depth) {if (depth = 4) {check (); return ;}// a full array of enumeration F (I, 4) {if (! Vis [I]) {// DB (I); vis [I] = 1; // enumeration F (j, 2) {if (j = 0) {meijux [depth] = rectx [I]; meijuy [depth] = recty [I];} else {meijux [depth] = recty [I]; meijuy [depth] = rectx [I];} dfs (depth + 1);} vis [I] = 0 ;}return ;} int main () {FOPENTIFOPENTOF (I, 4) SCFD (rectx [I], recty [I]); SET (vis, 0); dfs (0); PCFLN (sumarea); for (p = vec. begin (); p! = Vec. end (); p ++) {printf ("% d \ n", p-> first. first, p-> first. second );}}

I use map to judge the repetition, and then correspond to the six situations of the question. It turns out that we can ignore the 5th cases, and we can repeat the fourth case. We need to consider the 6th cases separately, each person is categorized differently, but it must be the height of the mounted block 2 and block 3 (in fact, there are still duplicates in the 6th and above) case 1 ~ 5. I am very clear about the question, so I will not talk about case 6.

The height is easy to calculate:

Sumy = maxb (meijuy [0] + meijuy [2], meijuy [1] + meijuy [3]); // perform classification under the sumx installation, only the maximum values of the two blocks in the sumx are changed. if (meijuy [2]> = meijuy [3]) {if (meijuy [2]> = meijuy [3] + meijuy [1]) {sumx = maxb (meijux [1], meijux [3]) + meijux [2], meijux [0]);} else {sumx = maxb (meijux [2] + meijux [1], meijux [2] + meijux [3], meijux [0] + meijux [1]) ;}} else {if (meijuy [3] >= meijuy [0] + meijuy [2]) {sumx = maxb (meijux [0], meijux [2]) + meijux [3], meijux [1]);} else {sumx = maxb (meijux [2] + meijux [3], meijux [0] + meijux [3], meijux [0] + meijux [1]);}

Paste the AC case this time. For later use .. The question is debugged twice. The first time it was a cheap, ', 'wrong' + '. As a result, maxb has the default parameter. No error is reported, WA .. The second time is case 6. I think it is wrong. I think it over again.!

USER: Rain M [m3324631]TASK: packrecLANG: C++Compiling...Compile: OKExecuting...   Test 1: TEST OK [0.000 secs, 3188 KB]   Test 2: TEST OK [0.000 secs, 3188 KB]   Test 3: TEST OK [0.000 secs, 3188 KB]   Test 4: TEST OK [0.000 secs, 3188 KB]   Test 5: TEST OK [0.000 secs, 3188 KB]   Test 6: TEST OK [0.000 secs, 3188 KB]   Test 7: TEST OK [0.000 secs, 3188 KB]   Test 8: TEST OK [0.000 secs, 3188 KB]   Test 9: TEST OK [0.000 secs, 3188 KB]   Test 10: TEST OK [0.000 secs, 3188 KB]   Test 11: TEST OK [0.000 secs, 3188 KB]   Test 12: TEST OK [0.000 secs, 3188 KB]   Test 13: TEST OK [0.000 secs, 3188 KB]   Test 14: TEST OK [0.000 secs, 3188 KB]   Test 15: TEST OK [0.000 secs, 3188 KB]   Test 16: TEST OK [0.000 secs, 3188 KB]   Test 17: TEST OK [0.000 secs, 3188 KB]   Test 18: TEST OK [0.000 secs, 3188 KB]   Test 19: TEST OK [0.000 secs, 3188 KB]   Test 20: TEST OK [0.000 secs, 3188 KB]   Test 21: TEST OK [0.000 secs, 3188 KB]All tests OK.Your program ('packrec') produced all correct answers!  This is yoursubmission #4 for this problem.  Congratulations!Here are the test data inputs:------- test 1 ----1 22 33 44 5------- test 2 ----20 2020 2020 2020 20------- test 3 ----4 55 44 516 1------- test 4 ----4 52 55 22 10------- test 5 ----12 184 62 1719 3------- test 6 ----10 105 515 1520 20------- test 7 ----1 11 201 2020 20------- test 8 ----5 83 1215 414 10------- test 9 ----4 55 66 44 5------- test 10 ----1 55 1010 1515 20------- test 11 ----3 48 57 14 5------- test 12 ----17 1116 204 613 19------- test 13 ----4 22 62 35 8------- test 14 ----1 22 33 44 5------- test 15 ----4 88 1212 1616 20------- test 16 ----3 51 32 42 5------- test 17 ----4 34 46 35 5------- test 18 ----49 5049 5049 5049 50------- test 19 ----10 5045 3028 3836 20------- test 20 ----50 4949 4848 4747 46------- test 21 ----50 4948 4746 4545 44Keep up the good work!Thanks for your submission!

PROB The Clocks [ANALYSIS] ---- this question is also tangled.

 

This RE always appears in the Early Stage

bad syscall #32000175 (RT_SIGPROCMASK) 
Your program printed data to stderr.  Here is the data:          -------------------          terminate_called_after_throwing_an_instance_of_'std::bad_alloc'          __what():__std::bad_alloc          -------------------
 

No way. Baidu and google finally have a clue. STL stack or pointer overflow or error, but what is the relationship with stderr? Please give me a variety of explanations!

// Solution 1: BFS, // a total of 9 methods, not all used, each vertex can have up to 4 statuses, a total of 4 ^ 9 statuses/* solution 1 data base: nodestatus hash with (3*3 to int) {9 9 123 6 9 126 6 61 2 3 46 3 6 trans-> 334 222 212 11011,111,110 (int) 9 ways: 110,1001, 1011101010,100100100, 011011000,11000000, 110110000} 1input2search: for 9-hash-expend (); 3 output; */struct node {int step, way, pre; int mat; node (int a = 0, int B = 0, int c = 0, int p = 0): step (a), mat (B), way (c ), pre (p) {}} First, nodetop, nodetmp; hash_map <int, bool> has; node que [MAXN]; int front = 0, rear = 0, kk = 0, anss [100]; int expe [] = {0, 110110000, 11000000,11011000, 100100100,10111010, 1001001,110110, 111,11011}; int hashi (int a []) {int n = 0; F (I, 9) {switch (a [I]) {case 3: n = n * 10 + 1; break; case 6: n = n * 10 + 2; break; case 9: n = n * 10 + 3; break; case 12: n = n * 10 + 4; break;} return n;} int expend (int hx, int cas) {int matt = hx + Expe [cas], ans = 0; int fuck [9] = {0}, I = 0, matm = matt; while (matm) {fuck [I ++] = matm % 10; if (fuck [I-1] = 5) fuck [I-1] = 1; matm/= 10 ;} ans + = fuck [I-1]; for (int j = I-2; j> = 0; j --) {ans * = 10; ans + = fuck [j];} return ans;} int bfs () {/* init: takes the queue header of the hash table queue-expend-hash weight-Press the queue */has. clear (); // que. push_back (first); rear ++; que [rear ++] = first; while (front! = Rear) {nodetop = que [front ++]; if (nodetop. mat = 444444444) return nodetop. step; nodetmp. step = nodetop. step + 1; nodetmp. pre = front-1; // expend () FOR (I, 1, 9) {nodetmp. mat = expend (nodetop. mat, I); nodetmp. way = I; if (has. find (nodetmp. mat) = has. end () {has [nodetmp. mat] = 1; // que. push_back (nodetmp); rear ++; que [rear ++] = nodetmp ;}}return 0;} void output (int depth) {if (que [depth]. pre! = 0) {output (que [depth]. pre);} anss [kk ++] = que [depth]. way; return;} int main () {FOPENTIFOPENTOkk = 0; int a [9]; F (I, 9) SCF (a [I]); first = node (0, hashi (a),); int de = bfs (); if (de) {output (front-1); for (int I = 0; I <kk-1; I ++) {printf ("% d", anss [I]);} printf ("% d \ n", anss [kk-1]);}

I have to say that the data requirements for this question are quite strict ,.

Self-Encouragement

USER: Rain M [m3324631]TASK: clocksLANG: C++Compiling...Compile: OKExecuting...   Test 1: TEST OK [0.011 secs, 7876 KB]   Test 2: TEST OK [0.011 secs, 7876 KB]   Test 3: TEST OK [0.097 secs, 8608 KB]   Test 4: TEST OK [0.162 secs, 9268 KB]   Test 5: TEST OK [0.184 secs, 9532 KB]   Test 6: TEST OK [0.475 secs, 11644 KB]   Test 7: TEST OK [0.508 secs, 11908 KB]   Test 8: TEST OK [0.529 secs, 11908 KB]   Test 9: TEST OK [0.508 secs, 11908 KB]All tests OK.Your program ('clocks') produced all correct answers!  This is yoursubmission #10 for this problem.  Congratulations!Here are the test data inputs:------- test 1 ----9 9 126 6 66 3 6------- test 2 ----12 9 129 9 912 9 12------- test 3 ----6 9 33 3 912 12 12------- test 4 ----9 3 99 9 99 9 9------- test 5 ----6 12 1212 12 1212 12 12------- test 6 ----3 12 96 6 612 12 12------- test 7 ----12 3 33 6 612 3 6------- test 8 ----12 3 99 12 123 6 9------- test 9 ----9 12 912 3 129 12 9Keep up the good work!Thanks for your submission

Suddenly we found that this section was not the same day before and after, and the time difference was... ORZ

PROB Arithmetic Progressions [ANALYSIS]-This question is awesome.

The key to this question lies in the fixed boundary and the inverted enumeration coefficient k.

bool has[MAXN];int n,m;int cal(int a,int b,int k){return a + k * b;}int main(){FOPENTIFOPENTO//FOPENSCFD(n,m);FOR(i,0,m) FOR(j,0,m) {has[i*i + j*j] = 1;}n--; bool flag = 1; int upsum = 2 * m * m; int upa = 2 * m * m - n + 1; int upb = 2 * m * m / n; FOR(b,1,upb) FOR(a,0,upa) { if( cal(a,b,n) > upsum) continue; bool isok = 1; for(int k = n;k  >= 0;k--) { int ans = cal(a,b,k); if(!has[ans]){ isok = 0; break; } }if(isok) printf("%d %d\n",a,b),flag = 0;  }if(flag) puts("NONE");}
USER: Rain M [m3324631]TASK: ariprogLANG: C++Compiling...Compile: OKExecuting...   Test 1: TEST OK [0.000 secs, 3340 KB]   Test 2: TEST OK [0.000 secs, 3340 KB]   Test 3: TEST OK [0.000 secs, 3340 KB]   Test 4: TEST OK [0.000 secs, 3340 KB]   Test 5: TEST OK [0.022 secs, 3340 KB]   Test 6: TEST OK [0.130 secs, 3340 KB]   Test 7: TEST OK [1.490 secs, 3340 KB]   Test 8: TEST OK [3.380 secs, 3340 KB]   Test 9: TEST OK [2.981 secs, 3340 KB]All tests OK.Your program ('ariprog') produced all correct answers!  This is yoursubmission #4 for this problem.  Congratulations!Here are the test data inputs:------- test 1 ----32------- test 2 ----57------- test 3 ----1410------- test 4 ----1013------- test 5 ----1250------- test 6 ----18100------- test 7 ----21200------- test 8 ----22250------- test 9 ----25250Keep up the good work!Thanks for your submission!

Think about how to prove this sparse relationship at night.

PROB Mother's Milk [ANALYSIS] ---- simulate it. At first, I did not expect to simulate it. I read the question carefully and found out.

Another point is to record the capacity of C when A is 0 !.

//solution 1dfs//solution 2DP maybe/*solution 11select one ( no 0 )2chose one to pull (if can't return)remeber all c*/map<int,int> mt;map<int,int>::iterator p;int has[22][22][22];//hashint a[3];//initint tma[3]={0};//statuvoid dfs(){for(int i = 0;i<3;i++){if(tma[i]) {for(int j = 0;j<3;j++) {if(i == j) continue;if(a[j] - tma[j]) {int botm = min(tma[i],a[j] - tma[j]);tma[i] -= botm;tma[j] += botm;if(!has[tma[0]][tma[1]][tma[2]]) {if(!tma[0])mt[tma[2]]=1;has[tma[0]][tma[1]][tma[2]] = 1;dfs();}tma[i] += botm;tma[j] -= botm;}}}}return;}int main(){FOPENTIFOPENTOSET(has,0);mt.clear();SCFT(a[0],a[1],a[2]);tma[2]=a[2];has[0][0][a[2]]=1;mt[a[2]];dfs();p = mt.begin();printf("%d",p->first);p++;for(;p != mt.end();p++){printf(" %d",p->first);}puts("");}

I didn't let 0 output, WA once... Tragedy, or we can see the first time congratulation and so on ..

USER: Rain M [m3324631]TASK: milk3LANG: C++Compiling...Compile: OKExecuting...   Test 1: TEST OK [0.000 secs, 3224 KB]   Test 2: TEST OK [0.000 secs, 3224 KB]   Test 3: TEST OK [0.000 secs, 3224 KB]   Test 4: TEST OK [0.000 secs, 3224 KB]   Test 5: TEST OK [0.000 secs, 3224 KB]   Test 6: TEST OK [0.000 secs, 3224 KB]   Test 7: TEST OK [0.000 secs, 3224 KB]   Test 8: TEST OK [0.000 secs, 3224 KB]   Test 9: TEST OK [0.000 secs, 3224 KB]   Test 10: TEST OK [0.000 secs, 3224 KB]All tests OK.Your program ('milk3') produced all correct answers!  This is yoursubmission #2 for this problem.  Congratulations!Here are the test data inputs:------- test 1 ----2 5 10------- test 2 ----20 20 20------- test 3 ----5 11 15------- test 4 ----2 12 20------- test 5 ----19 4 11------- test 6 ----5 11 13------- test 7 ----3 20 20------- test 8 ----7 16 20------- test 9 ----20 10 9------- test 10 ----7 12 18Keep up the good work!Thanks for your submission!

Conclusion 1.4

There are still a lot of questions worth doing in this section, mostly focusing on Deep Search, simulation, or enumeration.

As you can see, many questions can be done using DP. It's amazing. Wait for this chapter to finish and look back at the class DP.

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.