Test instructions: Morse code, enter a number of letters of the Morse number, a dictionary and several encodings. For each number, determine which word it might be,If more than one word matches exactly, output the first word and add a "! "; If you can't match exactly, add or remove as few characters as possible at the end of the code,Make it match a word and add "? ”。Analysis: The first time to do, a look at what ah, do not, now come back to see, found can be done, you can use the map of the STL
#include string>5#include 6#include 7#include 8 using namespacestd;9 Const intN =25000+5;Ten One stringS[n]; Avectorint>G[n]; -mapstring,int>M; - intDp[n]; the - stringChangestringSintPos//the delete operation and the change operation can be seen as the same - { - stringAns =""; + for(intI=0; I) - { + if(pos = = i) ans + ='*'; A ElseAns + =S[i]; at } - returnans; - } - - stringAddstringSintPOS) - { in stringAns =""; - for(intI=0; I) to { +
. Regardless of the variable ordering of the S-tree, the first character always describes the value of x1, the Seco nd character describes the value of x2, and so on. So, the line110Corresponds to the VVA ( x1 = 1, x2 = 1, x3 = 0).The input is terminated by a test case starting with n = 0. This test case is should not being processed.OutputFor each s-tree, output of the line 'S-tree #J:", whereJIs the number of the S-tree. Then print a line this contains the value of for each of the givenmVvas,
= Find (x), FY =Find (y); if(FX! = FY) Pre[fx] =fy; }BOOLisconnct ()//Determine whether the graph is connected, that is, all the points are in a set {intCNT =0; for(inti =1; I if((outdegree[i]! =0|| Indegree[i]! =0) Pre[i] = = i) cnt++; if(CNT = =1)return true; return false;}BOOLIseulur ()//whether there is Euler pathway {intCNT =0; intFlag =0; for(inti =1; I -; i++) if((outdegree[i]! =0|| Indegree[i]! =0) (indegree[i]! =Outdegree[i])) Judging the singularity, the method is n
"Topic link": Click here~~"The main idea": Euler function: The number of the number of N-"Thinking": Bare Euler function, pay attention to the case of N==1, n==1 case, should output 0,POJ still judge 1 can also, but old Ojuva must be 0 before, pay attention to.Code:#include Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. POJ 2407 Relatives UVA 10299 relatives (Euler function)
D[u][0][1]=sum{d[v][0]}D[u][1][1]=d[u][1][0]=sum{min (d[v][0],d[v][1])}D[u][0][0]=sum{d[v][0]}-d[min][0]+d[min][1] (D[min][1]=min (d[v][1]))It's been a long time. See LRJ is the first DFS to find a good path, and then the reverse direction along the path recursion. O (n).Inefficient lately!Who laughs last who laughs best!1#include 2#include 3#include 4#include 5 #definePB Push_back6 using namespacestd;7 Const intinf=1e4;8 Const intmaxn=10010;9 intN;Tenvectorint>VT[MAXN]; One intd[maxn][2][2]; A
The main idea: a ring can open and close. Now there are N (1Title Analysis: The set of rings to be opened with a binary number, a total of 2^n cases, enumeration of each case. When the ring is opened, the ring is isolated, the next is to judge the rest of the ring is connected with a few rings, if some ring is still connected with more than two rings, the scheme is not feasible, it is impossible to form a chain, and then determine whether the remaining ring is connected to a circle, if there is,
Test instructions: There is a bee, every year the drone produces a females and drone, and then die, females produce a drone, and then die, there is not a dead females, ask the number of drones and the total number of bees after n yearsIdea: recursion + test InstructionsThe number of drones this year is m[x], last year was m[x-1],The number of females this year is f[x], last year for F[x-1]According to test instructions, you can get:M[X]=F[X-1]+M[X-1];F[x]=m[x-1]+1PS: According to recursion can a
Title: To an nTopic Analysis: First of all to determine whether from 1 to N, and then backtracking.Note: This problem has a pit, according to the sample output will be PE.The code is as follows:# include UVA-208 Firetruck (backtracking)
the same).InputThe input consists of T test Cases. The number of test cases T is given on the first line of the input file. Each test case takes one line containing a circular sequence so is written as an arbitrary linear sequence. Since the circular sequences is DNA sequences, only four symbols, A, C, G and T, is Allowed. Each sequence have length at least 2 and at the most.OutputPrint exactly one line for each test case. The line was to contain the lexicographically smallest sequence for t
Title: Give a string of parentheses to see if it matches.Topic Analysis: A beginning with the interval DP write, timed out ...Note: The empty string is valid.The code is as follows:# include UVA-673 parentheses Balance (stack)
"Source" https://uva.onlinejudge.org/index.php?option=com_onlinejudgeitemid=8page=show_problem problem=2266This problem is relatively simple, the main work is the segmentation of the string, how to write a beautiful code point is the focus, readability is very important. The use of function atof (stdlib.h) is more convenient than a bit to spell numbers.#include #include#include#include#defineMaxLen 100005using namespacestd;intSubexplen (Char* S,intstart) { intlen=0; if(s[start]!='(') {
Determine if there is a Euler loop as long as two conditionsDiagram is connected, no singularity points existPay attention to the case where the margin is 0. In addition this problem data pits.#include #include #include using namespace Std;const int maxn=208;struct fuck{int u,v,next;}EDGE[MAXN*MAXN];int HEAD[MAXN];int tol;void Init (){tol=0;memset (head,-1,sizeof (head));}void Addedge (int u,int v){Edge[tol].u=u;Edge[tol].v=v;Edge[tol].next=head[u];head[u]=tol++;}BOOL VIS[MAXN];int DU[MAXN];void
Test instructionsGiven the set of 4 N (1 Analysis:Obviously the four-heavy cycle is not enough, I first thought is to use a map to save A+b,c+d, and then in the search statistics. Timeout....And then the book said with a hash table to achieve, see some of the hash of the puzzle is too ingenious, learn a bit.There is the problem can be solved with two points, first calculate the A+b, and then enumerate C+d, and then two points to find the scope.Hash 630ms:#include #include Constintn=4005;inta[4][
https://uva.onlinejudge.org/index.php?option=com_onlinejudgeItemid=8page=show_problemproblem= 565A record path can use a two-dimensional array to record the amount of change. Then you can push all the values forward from the back.#include #includestring>#include#include#include#include#include#includeusing namespacestd;#defineMEM (A, B) memset (A,b,sizeof (a))#definePF printf#defineSF scanf#defineDebug printf ("!\n")#defineINF 8000#defineMAX (A, b) a>b?a:b#defineBlank pf ("\ n")#defineLL Long Lo
Topic PortalTest Instructions: Training guide P189Analysis: The idea of a complete reference book, K^k table into an orderly table:Table 1:a1 + B1 Table 2:a2 + B1 .......Table K:ak + B1 can maintain a K-length array representing the current top-K small number and, when the array of line I is read, First push first, that is the smallest, then can be updated to the second, that is-b[i] + b[i+1]. The logn of the priority queue can be used to get the minimum value of each moment, and the total co
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.