[Swust OJ 403]--set of deletions

Source: Internet
Author: User

Title Link: http://acm.swust.edu.cn/problem/403/

Time limit (ms): Memory Limit (KB): 65535 DescriptionA collection has the following elements: 1 is the collection element, if p is the element of the set, then 2 * p +1,4*p+5 is also the element of the collection, take out the smallest element of k in this set, in order to combine from small to large to a multi-digit, it is required to remove the number m digits, so that the remaining number is the largest, Programmed output before and after deletion of multiple digits.
Note: There are no cases where all the numbers are deleted InputEnter only one row, the value of k,m, and k,m are less than or equal to 30000. OutputThe output is two lines, the first behavior is deleted before the number, and the second behavior is deleted after the number. Sample Input
5 4


Sample Output
13791595

Thinking of solving problems: Deal with bad words on the pit dad, for int conversion string Convenient lazy, Baidu Sstream head file usage, also learned to ~ ~ ~ (1) Use the collection information in the problem to get the smallest number (2) Sstream,int converted to string to be deleted sequence (3) Greedy---get deleted after the maximum value code is as follows (slightly rubbed):
1#include <iostream>2#include <string>3#include <cstdio>4#include <algorithm>5#include <sstream>//int Turn string6 using namespacestd;7typedefLong LongLL;8 intMain () {9     intLen, M, front, CNT, end;TenLL x[60010] = {0,1}, a, B; One      while(Cin >> Len >>m) { A         inti =1, j =1, K; -          for(k =2; K <= Len; k++){ -A = x[i] *2+1; theb = x[j] *4+5; -             if(A >b) { -J + +; -X[K] =b; +             } -             Else if(A = =b) { +i++; AJ + +; atX[K] =A; -             } -             Else{ -i++; -X[K] =A; -             } in         } -         strings ="", ans =""; to          for(i =1; I <= Len; i++){ + StringStream SS; -             stringstr; theSS <<X[i]; *SS >>str; $s + =str;Panax Notoginseng         } -cout << S <<Endl; the         string:: Iterator it =S.begin (); +S.insert (IT,'9');//effective sequence starting from 1 to prevent front from crossing ALen =s.size (); theFront = CNT =0, end =1; +          while(End <= len && cnt! =m) { -             if(S[end] <=S[front]) $S[++front] = s[end++]; $             Else{ -front--; -cnt++; the             } -         }Wuyi          while(End <=len) theS[++front] = s[end++]; -          for(i =1; i < len-m; i++) Wucout <<S[i]; -cout <<Endl; About     } $     return 0; -}
View Code

[Swust OJ 403]--set of deletions

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.