Codechef August lunchtime 2014

Source: Internet
Author: User

Question

A string composed of two types of characters, A and B, each time you can select any length of the ECHO sub-sequence (not necessarily consecutive) and delete. It takes at least a few times to empty the entire string.

Idea: if it is a text return string, it only needs one time; otherwise, it needs two times (select all a for the first time and select all B for the second time ).

Accepted code:

 1 def is_palidrome(s): 2       n = len(s); 3       for i in xrange(n / 2): 4           if s[i] != s[n - i - 1]: 5             return False; 6     return True; 7  8 if __name__ == ‘__main__‘: 9     T = int(input())10     while T:11         T -= 1;12         H = raw_input();13         print 1 if is_palidrome(H) else 2;

Question B

Knowledge point: the formula ind = (A * ind + B) % m is given, and the length of the cyclic section is obtained. From the formula, we can see that the cyclic section does not exceed M.

In addition, the accuracy of this question is also a pitfall, which can be manually output: ". 5" and ". 0 ".

Accepted code:

1 /************************************** * *********************************** 2> File Name: wall. CPP 3> author: stomach_ache 4> mail: [email protected] 5> created time:, Sunday, August 31, 2014 6> propose: 7 *************************************** * *******************************/8 9 # include <cmath> 10 # include <string> 11 # include <cstdio> 12 # include <vector> 13 # include <iomanip> 14 # include <Fstream> 15 # include <cstring> 16 # include <iostream> 17 # include <algorithm> 18 using namespace STD; 19/* Let's fight !!! */20 21 const int max_m = 524300; 22 typedef long ll; 23 ll ind [max_m], d [max_m], vis [max_m]; 24 ll T, H, n, m, a, B, IND; 25 # define rep (I, n) for (INT I = (0); I <(n); I ++) 26 void seed (LL & IND) {27 ind = (A * ind + B) % m; 28} 29 30 int main (void) {31 IOs :: sync_with_stdio (false); 32 CIN> T; 33 while (t --) {34 CIN> H> N> m> A> B> ind; 35 rep (I, m) CIN> d [I]; 36 37 int loop = 1; 38 mem Set (VIS,-1, sizeof (VIS); 39 vis [ind] = 0; 40 ind [0] = ind; 41 LL ans = 0; 42 while (loop <n) {43 ans + = d [ind]; 44 seed (IND); 45 if (vis [ind]! =-1) break; 46 vis [ind] = loop; 47 ind [loop] = ind; 48 + + loop; 49} 50 51 if (loop <= n-1) {52 LL sum = 0; 53 for (INT I = vis [ind]; I <loop; I ++) sum + = d [ind [I]; 54 LL times = (n-1-loop)/(loop-vis [ind]); 55 ans + = times * sum; 56 loop + = times * (loop-vis [ind]); 57 loop ++; 58} 59 While (loop <= n-1) {60 ans + = d [ind]; 61 seed (IND); 62 loop ++; 63} 64 65 cout <ans * H/2; 66 If (ANS * H % 2) cout <". 5 "; 67 else cout <". 0 "; 68 cout <Endl; 69} 70 71 return 0; 72}

Question C

To be continued...

Question d

To be continued...

Codechef August lunchtime 2014

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.