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