Microsoft 2016 school enrollment written second part of the topic personal ideas

Source: Internet
Author: User

A. Lucky substrings

This problem is not difficult, because the string length is only 100, then its substring is certainly not more than 1w, the list of all strings is not a problem, as for the test of a substring in which the number of different letters is Fibonacci number, we only need to advance the Fibonacci sequence less than 1w of the items are generated, Then after enumerating a substring, count the number of different letters (edge-finding statistics, if the current letter appeared before the addition, if not appear to remember and + 1), go to this inside to find the line. The Fibonacci sequence will not push a few items to 1w ...
Finally, the dictionary order from small to large, and also to go to heavy, then use a string and then directly sort+unique, fix

#include <iostream>#include <stdio.h>#include <math.h>#include <string.h>#include <string>#include <algorithm>using namespace STD;Chars[ $];stringans[20000];intp_ans=0;intfib[10000];intp_fib=0;voidGENER_FB () {fib[1]=1; fib[2]=1;intI=3; while(true) {Fib[i] = fib[i-1]+fib[i-2];if(fib[i]> -) {P_fib =i;return;    } i++; }}BOOLFindintx) { for(intI=1; i<=p_fib;i++) {if(Fib[i] = = x)return true; }return false;}intMain () {GENER_FB ();Cin>>s;intlen=strlen(s);intI for(i=0; i<len;i++) {Charnow[ $]={0};intappear[ $]={0};intSum_appear=0; for(intJ=i; j<len; J + +) {Now[j-i] = s[j];if(appear[s[j]]==0) {appear[s[j]]=1;            Sum_appear + +; }if(Find (Sum_appear)) {stringSTR (now);            Ans[++p_ans] = str; }}} sort (&ans[1], &ans[p_ans+1]); P_ans = Unique (&ans[1], &ans[p_ans+1])-ans-1; for(i=1; i<=p_ans;i++) {cout<<ans[i]<<endl; }//system ("pause");    return 0;}
B. Numeric Keypad

I've thought about it for a while, and I don't know what other people are doing ...
This problem can notice so many points, the first is the number of the input is particularly large, there are 500, so we must be a processing, each should try and input as much as possible, because if there is a small front, the back of the big also useless;
The key problem is that sometimes if you lose the same, the back is not, like the example of 131, if you lose the second 3, then you will find the third no solution. What do we do? It's really easy, at this point we just have to go back to the previous layer and try a smaller number. You will find that such a fallback will only occur once, because once you have rolled back, you can fill in the back with no brains. If the returned one is not 0, then you can no brain fill 9, such as 131 you back to 12 when the back, you do not have to think about, you must fill in 9, anyway, you in the second is already smaller than him, if the back of this one is 0 words will not, because 0 to 9, you can only the back of all the brain filled 0, For example, 876, the answer is 800.
It is recommended to pre-process one map[i][j] , indicating that the number I can go to the number J, which will give you a lot of things to save behind.

#include <iostream>#include <string.h>#include <math.h>#include <stdio.h>#include <algorithm>using namespace STD;Charinput[ -];intTint Map[Ten][Ten];intans[ -];voidInitmap () {intI,j; for(i=1; i<=9; i++) { for(j=1; j<=9; j + +) {if((I-1)/3<= (J-1)/3&& (I-1)%3<= (J-1)%3)MapI [j]=1; }    } for(i=1; i<=7; i+=3)MapI [0]=1; for(i=2; i<=8; i+=3)MapI [0]=1;Map[0][0]=1;return;}BOOLGointPosintLast) {if(pos==strlen(input))return true;intnow = input[pos]-' 0 ';BOOLok=false; for(intI=now; i>=0; i--) {if(Map[Last] [i]==1) {ans[pos]=i;if(I==now) {if(Go (pos+1, i) = =false)                {Continue; }Else                     return true; }Else{ for(inttmp=pos+1; tmp<strlen(input); tmp++) {if(i==0) ans[tmp]=0;Elseans[tmp]=9; }return true; }        }    }return false;}voidInit () {memset(ANS,0,sizeof(ans));}intMain () {initmap ();Cin>>t; for(intfiles=1; files<=t; files++) {init ();Cin>>input; Go0,1); for(intI=0; i<strlen(input); i++)cout<<ans[i];cout<<endl; }//system ("pause");    return 0;}
C. Spring Outing

The problem was my algorithm WA, and then thought for a long time did not want to come out where the wrong, and later today the discussion just know ...
The key to this problem lies in "where we know we can go," and everyone knew at first that "I could stay at home at least".
So consider such a thing, for a person, if all the previous locations are pass off, now cast K, if K is behind 0, then I certainly do not vote; If K is in front of 0, then I am sure to vote, otherwise I will have to stay at home without any other choice; We can know according to the behavior of all the K in the end can go, if half of the people will vote K, then K can go, conversely K cannot go;
The same truth, if K can go, we see K-1, if someone more want to go to K-1, then he will vote, otherwise will not vote. Of course, if the result is k can not go, then the last one must be able to go to the choice is 0, it becomes the choice between K-1 and 0.
So, we just have to try it from place K, and we'll know where they're going to be for the first time (that's the last one of our algorithms).
Since the inputs are all 0~n, we can record each number in each person's position, so it is very convenient to find them.
Note that it is not that a person will never vote in the back of a known desirable place, such as a person's volunteer is 0 1 2, then according to the conclusion, if 2 has been able to go, he will still vote 1, or will definitely go to 2. It's not that a person who wants to stay at home is bound to hold on.
The subject is not yet open, so no code is posted.

Microsoft 2016 school enrollment written second part of the topic personal ideas

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.