[Brush Problem codeforces]651b/651a

Source: Internet
Author: User

651B Beautiful Paintings
651A Joysticks

Click to view the original question

651B is a sort problem, just one more step to the weight and then the number of records. Sift one layer at a time until it is all 0. Learn a correct posture from this question: given a sorted array, how to turn it into a new array of weights.

Only one while loop + one pointer is required.

#defineN 10#include<iostream>using namespacestd;intMain () {inta[n]={2,2,3,5,7,7,7,8, One, One}; intb[n]={}; intd[i]={}; intp=0; intcou=0;  while(p<N) {intcoup=1;  while(p+1<n && a[p+1]==A[p]) {P++; Coup++; } B[cou]=A[p]; C[cou]=coup; P++; Cou++; }     for(intI=0; i<cou;i++) {//n number is compressed into the number of coucout <<b[i] <<" "<<c[i] <<Endl; }    return 0;}/*Output 2 23 15 17 38 111 2 Press any key to continue ...*/

About 651A, or experience is not enough, from the beginning of the speculation greedy, found WA, and then to DP, found also not, and then to the memory search, the general line, the results finally still did not think of a detail 1 and 1 of the situation.

The general idea is that the results are determined only by the initial A and B, and there are only two types of state transfers: charging A and charging B. So the direct search on the line, remember 1 and 1 of the case of a special sentence.

So thought a pass, the result is greedy is also right, just forgot 1 and 1 of special sentence.

[Brush Problem codeforces]651b/651a

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.