Hdu2847 (violent)

Source: Internet
Author: User

I read a question last year, but I was dumb about using DFS + circular linked list. It's silly. But now I have been thinking about this question for a long time and there are still several times of Wa. In fact, this question is still very watery. Simply perform brute-force enumeration. The premise of enumeration is to calculate the complexity. We can know that for 01 strings with a length of N and K whose length is m, A maximum of M 0or1 values can be added to obtain a total number of K values. You can then enumerate from K * 1, K * 2, K * 3. We can see that you only need to enumerate 2 ^ 20 times at most. The complexity of 10 ^ 7 can still be improved when compared to about 20 times each time, because the number of data groups is small

Hdu2847

# Include <iostream> # include <stdio. h> # include <string. h> # include <math. h> # include <algorithm> # include <string> # include <queue> # include <stdlib. h> using namespace STD; # define n 100 char G [N]; int Len; int mcheck (int x) {char TMP [N]; int CNT = 0; while (x) {TMP [CNT ++] = x % 2 + '0'; X >>=1 ;}int tcnt = 0; For (INT I = cnt-1; I >= 0; I --) {If (G [tcnt] = TMP [I]) {tcnt ++; If (tcnt = Len) return 1 ;}} return 0;} int main () {wh Ile (scanf ("% s", g )! = EOF) {int K; Len = strlen (g); scanf ("% d", & K); If (G [0] = '0 ') {// if it is set to 0, it is still troublesome to printf ("0 \ n"); continue;} int ans =-1; for (INT I = K ;; I + = k) {If (mcheck (I) = 1) {ans = I; break;} int CNT = 0; int TMP [N]; while (ANS) {TMP [CNT ++] = ans % 2; ans >>=1 ;}for (INT I = cnt-1; I> = 0; I --) printf ("% d", TMP [I]); printf ("\ n");} return 0 ;}

 

Hdu2847 (violent)

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.