Question A: Root number of A stick
Solution: Save all the situation and add it.
#include <bits/stdc++.h>using namespaceStd;map<Char,int>Q;classp{ Public: intcmdstrings) {intsum=0; for(intI=0; I<s.length (); i++) {sum+=Q[s[i]]; } returnsum; }};intMain () {strings; P solve; q['0']=6; q['1']=2; q['2']=5; q['3']=5; q['4']=4; q['5']=5; q['6']=6; q['7']=3; q['8']=7; q['9']=6; q['+']=2; q['-']=1; q['=']=2; CIN>>s; cout<<solve.cmd (s) <<Endl; return 0;}Question B: I don't have an apple.
Solution: Naturally there are three kinds of situations, buy separately, set buy, and mix buy, judge
#include <bits/stdc++.h>using namespacestd;intMain () {intn,m,p,q,k=0, S,r; scanf ("%d%d%d%d",&n,&m,&p,&q); S=n/p; R=n%p; K+=min (s*q,n*m); K+=min (q,m*R); printf ("%d\n", K); return 0;}Question C:led
Solution: Save that graphic and then XJB (code reference a classmate of civil engineering)
Include<stdio.h>#include<string.h>intMain () {Charnum1[ -]={" _ _ _ _ _ _ _ _ "}; Charnum2[ -]={"| | | _| _|| _|| _ |_ || _|| _|"}; Charnum3[ -]={"|_| || _ _| | _|| _| || _| _|"}; Charstr,a[ -]={" /"}; intI,k,j,len; scanf ("%s", a); Len=strlen (a); for(i=0; i<len;++i) {j=a[i]-'0'; K=j*3; printf ("%c%c%c", num1[k],num1[k+1],num1[k+2]); } printf ("\ n"); for(i=0; i<len;++i) {j=a[i]-'0'; K=j*3; printf ("%c%c%c", num2[k],num2[k+1],num2[k+2]); } printf ("\ n"); for(i=0; i<len;++i) {j=a[i]-'0'; K=j*3; printf ("%c%c%c", num3[k],num3[k+1],num3[k+2]); } printf ("\ n"); return 0;}Question D: The road was chosen by itself
Solution: Should all look at the odd couple of relationships, one is the use of binary, one is two, the result needs to be inverted output, so the use of the stack
#include <bits/stdc++.h>using namespacestd;Const intmaxn=1000005;intB[MAXN];intMain () {intx; inta[ -]; scanf ("%d",&x); for(intI=0;i< -; i++) {scanf ("%d",&A[i]); B[a[i]]=i; } intu=B[x]; U= -+u; Stack<Char>s; while(u!=1) { if(u%2==0) S.push ('L');ElseS.push ('R'); U=u/2; } while(!S.empty ()) {Putchar (S.top ()); S.pop (); } puts (""); return 0;}Question E:all roads leads to Rome
Solution: The standard solution is DP, which can be done with combinatorial mathematics, i.e. C (n,m)
#include <iostream> #include <cmath> using namespace STD; int main () { int N,m,l,r; int a,b,c,d,ans=1 ; CIN >>n>>m>>a>>b>>c>>D; L =abs (a-c), R=abs (D-b); for (int I=l+r;i>l;i-- =ans*i/(l+r-i+1 ); } cout <<ans<<ENDL;}
Question F: Can't find the north
Solution: The best way to find the shortest possible use of BFS, of course, DFS can also do (a basic search problem)
#include <bits/stdc++.h>using namespacestd;intInf= (1<< to)-1;intMx;Charm[ A][ A]={"##########","#**#***#*#","#*#**##*##","#***##***#","##**#*#**#","#***#*#**#","#**#*****#","#****###*#","#***#**#*#","##########",};inta,b,c,d;voidDfsintXintYints) { if(m[x][y]=='#') { return; } Else if(x==c&&y==d) {Mx=min (mx,s); } s++; M[x][y]='#'; DFS (x, y-1, s); DFS (x, y+1, s); DFS (x+1, y,s); DFS (x-1, y,s); M[x][y]='*';}intMain () {intT; CIN>>T; while(t--) {Mx=inf; CIN>>a>>b>>c>>D; if(m[a][b]=='#'|| m[c][d]=='#') {cout<<"-1"<<Endl; Continue; } Else if(a==c&&b==d) {cout<<"0"<<Endl; Continue; } Else{DFS (A, B,0); if(mx==inf) {cout<<"-1"<<Endl; } Else{cout<<Mx<<Endl; } } } return 0;}
2016 C Language Program Design Competition (junior group), Jiangxi University of Technology