[Codeforces 155c hometask] Bai xiaosi × string + dp -- it's really annoying to handle strings. Especially for line breaks, it seems that we don't need to use cin. What should we do if DP is transferred?! [Reaching 1.1%]

Source: Internet
Author: User
# Include <cstdlib> # include <cstdio> # include <cstring> # include <iostream> using namespace STD; const int max_size = 1e5 + 10; char text [max_size]; /** title: bai xiaosi × string + dp -- it's really annoying to process strings. Especially for line breaks, it seems that there is no use of CIN. Although the efficiency is low, it's so sad that DP transfer really doesn't. what should I do when the water reaches home! Problem: codeforces 155c hometask little exp.: line breaks are automatically ignored when a single character (char) is entered in Cin, but neither scanf nor getchar works. Pre-Knowledge: None. Only ur intelligence. Knowledge Point: DP Thx to: Severin & GZM provided AC Code At the beginning, it was very rude to mistake someone else's ID .. Jin soul (ah, haha, hello, reference: Ghost, but it is not publicly released, so it will not be provided :) thought: It seems I really want to be complicated. [Previous error ideas]: Perform the transfer based on the letters left after the previous transfer to see whether to delete the left or the right. The number of valid statuses is displayed. Obviously, this D fart P is obviously the idea of brute force search. Not to mention brute-force search. [Correct idea]: The characters s [0] And s [1] that are not allowed to appear are read each time. Note that each letter can appear in a pair at most. For the read string text [I], just remove text [n.. K. Text [n .. k] has the following rules: Text [n .. the property of K] Is that for I: n <= I <= K, text [I] = s [0] or text [I] = s [1]; that is to say, text [N] to text [k] (including N and K) are all undesirable characters. Count the number of times that text [n.. K] needs to be crossed out if s [0] Or s [1] is removed. Add a small number of times to sum. For example, aaaaabcddddd 2 ad BC, in text [0 .. 4], we need to cut out a five times, cut out d 0 times, then sum = sum + 0 = 0; (sum is initialized to 0) Text [5 .. 6] B needs to be crossed once. C once, sum = sum + 1 = 1 Text [7 .. at the end of the statement, you need to cut d five times and a 0 times. At this time, sum = sum + 0 = 1. The result is 1. [Why?] (High-Energy warning: I am a mathematical idiot. I boast that this proof method is correct. I beg for a brick or point out the place where the proof fails.) for the original string text, the remaining strings are valid after the first character s [] is removed as the minimum number of times. Obtain the string text 'for string text', repeat to the minimum number of times to remove the I-to-disallow character s [], the new string is still valid, but we did not change the text content (that is, we did not really remove the letters), but recorded the minimum number of times to accumulate. The reason that you do not need to change the text content is that each letter appears at most once in a prohibited letter pair. Therefore, it is not allowed that letters in S [] and s '[] cannot be the same and independent of each other. In the preceding example, the attacker attempts to attack the white kernel */INT main () {char a = 0; char B = 0; int K; int ans = 0; gets (text ); int lent = strlen (text); scanf ("% d \ n", & K); For (int K = 0; k <K; k ++) {CIN> A; CIN> B; For (INT I = 0; I <lent; I ++) {int left = 0, Right = 0; while (Text [I] = A | text [I] = B) {If (Text [I] = A) left ++; if (Text [I] = B) Right ++; I ++;} ans + = min (left, right) ;}} printf ("% d \ n ", ans); Return 0 ;}

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.