Iqiyi Art 2018 Fall School recruit algorithm engineer (first game)

Source: Internet
Author: User
Tags iqiyi

    • Welcome Fork and Star:nowcoder-repository-github
Bracket Matching Depth
    • Topic:
链接:https://www.nowcoder.com/questionTerminal/a2d5b1875bb0408384278f40d1f236c9来源:牛客网一个合法的括号匹配序列有以下定义:1、空串""是一个合法的括号匹配序列2、如果"X"和"Y"都是合法的括号匹配序列,"XY"也是一个合法的括号匹配序列3、如果"X"是一个合法的括号匹配序列,那么"(X)"也是一个合法的括号匹配序列4、每个合法的括号序列都可以由以上规则生成。例如: "","()","()()","((()))"都是合法的括号序列对于一个合法的括号序列我们又有以下定义它的深度:1、空串""的深度是02、如果字符串"X"的深度是x,字符串"Y"的深度是y,那么字符串"XY"的深度为max(x,y) 3、如果"X"的深度是x,那么字符串"(X)"的深度是x+1例如: "()()()"的深度是1,"((()))"的深度是3。牛牛现在给你一个合法的括号序列,需要你计算出其深度。输入描述:输入包括一个合法的括号序列s,s长度length(2 ≤ length ≤ 50),序列中只包含'('和')'。输出描述:输出一个正整数,即这个序列的深度。示例1输入(())输出2
    • Answer:
#include <iostream>using namespaceStd#include <string>#include <stack>//Test Cases://( (()) () ) ( ( (()) (()) )() )////The corresponding output should be:////4////Your output is:////7intMain ()//60%{string str; stack<Char> STA; CIN >> str;intdepth =0;intResult_depth =0; for(inti =0; I < str.size (); i++) {if(Sta.empty ()) {depth =0; }if(str[i]=='(') {Sta.push (str[i]); Depth + =1; }Else{Sta.pop (); } result_depth = (result_depth>depth)?    result_depth:depth; } cout << result_depth << Endl;return 0;} -Seriously, thinking is simple.intMain () {string str; stack<Char> STA; CIN >> str;intdepth =0;intResult_depth =0; for(inti =0; I < str.size (); i++) {if(Str[i] = ='(') {Sta.push (str[i]); Depth + =1; }Else{Depth-=1; } result_depth = (result_depth > Depth)?    result_depth:depth; } cout << result_depth << Endl;return 0;}
Cow number
    • Topic:
链接:https://www.nowcoder.com/questionTerminal/c167db5218e54ef2870aebe5b14743f2来源:牛客网牛牛养了n只奶牛,牛牛想给每只奶牛编号,这样就可以轻而易举地分辨它们了。 每个奶牛对于数字都有自己的喜好,第i只奶牛想要一个1和x[i]之间的整数(其中包含1和x[i])。牛牛需要满足所有奶牛的喜好,请帮助牛牛计算牛牛有多少种给奶牛编号的方法,输出符合要求的编号方法总数。输入描述:输入包括两行,第一行一个整数n(1 ≤ n ≤ 50),表示奶牛的数量 第二行为n个整数x[i](1 ≤ x[i] ≤ 1000)输出描述:输出一个整数,表示牛牛在满足所有奶牛的喜好上编号的方法数。因为答案可能很大,输出方法数对1,000,000,007的模。示例1输入44 4 4 4输出24
    • This problem is not understood
    • Reference link
Square string
    • Topic
链接:https://www.nowcoder.com/questionTerminal/b43fb39898f448e39adbcffde5ff0dfc来源:牛客网如果一个字符串S是由两个字符串T连接而成,即S = T + T, 我们就称S叫做平方串,例如"","aabaab","xxxx"都是平方串.牛牛现在有一个字符串s,请你帮助牛牛从s中移除尽量少的字符,让剩下的字符串是一个平方串。换句话说,就是找出s的最长子序列并且这个子序列构成一个平方串。输入描述:输入一个字符串s,字符串长度length(1 ≤ length ≤ 50),字符串只包括小写字符。输出描述:输出一个正整数,即满足要求的平方串的长度。示例1输入frankfurt输出4
    • The answer is mainly to simplify the problem to find the most common firstborn sequence.
//Square string#include <iostream>using namespaceStd#include <string>#define MAX (b) ((a) > (a): (b))//Test Cases://fjkjsakljflkjakljjfiwoqjfioq WFOIQWJFIOJQ////The corresponding output should be:////16////Your output is:////intFindmaxcom (String A_, String b_) {intdp[Wuyi][Wuyi] = {0};intRET =0; for(inti =1; I <= a_.size (); i++) { for(intj =1; J <= B_.size (); j + +) {if(A_[i-1]==b_[j-1])//(A_[i]==b_[j] This bug took a lot of time{Dp[i][j] = dp[i-1][j-1] +1; }Else{Dp[i][j] = max (dp[i-1][j],dp[i][j-1]); }//ret = (ret > dp[i][j])? Ret:dp[i][j];}} ret=dp[a_.size ()][b_.size ()];returnRET;}intMain () {string str;Chartemp[ -];//cin >> str;file* fp = fopen ("Input.txt","r+");if(Fp!=null) {Fgets (temp, -, FP);    str = temp; }intRET =0; String A, B; for(inti =0; I < str.size (); i++) {a = Str.substr (0, i), B = Str.substr (i, str.size ()-i);if(i = = -)        {intStop =0; }intMax_com_len = Findmaxcom (A, b); ret = Ret>max_com_len?    Ret:max_com_len; } cout << ret *2<< Endl;return 0;}

Iqiyi Art 2018 Fall School recruit algorithm engineer (first game)

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.