A. Dreamoon and stairs
Test instructions: Given n-level stairs, M, can be up to 1 or 2 stairs at a time, asking if there is a multiple of m in the number of steps required to go upstairs
Find the range, that is, the maximum number of steps is N (one level up), the minimum number of steps is n/2+n%2 in this range.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6 using namespacestd;7 8typedefLong LongLL;9 Ten intMain () One { A intN, m,i,flag=0, mn,mx; -Cin>>n>>m; -mx=N; themn=n/2+n%2; - - for(i=mn;i<=mx;i++){ - if(i%m==0) { +flag=1; -printf"%d\n", i); + Break; A } at } - if(!flag) printf ("-1\n"); -}View Code
B. Dreamoon and WiFi
Test instructions: Give two strings s1,s2 S1 contains only ' + ', '-' (+ delegate + 1,-Rep-1) S2 contains ' + ', '-', '? ' Three kinds, ask S1,s2 string to get the same number of probabilities
In S1, make a[0] represent-,a[1] +
In S2, make b[0] represent-,b[1] = +,b[2] Represents a question mark
Number of question marks is 0 and is not discussed for zero
Question Mark 0 is: Judge the Plus, the number of minus is equal
The question mark is not 0, then the Bad Plus is a[1]-b[1], that is, to choose from b[2] position a[1]-a[0] position, and then use this divided by the total number of programs 2^b[2]
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6 using namespacestd;7 8typedefLong LongLL;9 Chars1[ the],s2[ the],a[5],b[5];Ten One ALL C (intNintm) { - if(n<m| | n<0|| m<0)return 0; - if(m<n-m) m=n-m; theLL ans=1; - for(inti=m+1; i<=n;i++) ans*=i; - for(intI=1; i<=n-m;i++) ans/=i; - returnans; + } - + intMain () A { at intlen1,len2,i,j,pos,pos1,tot,sum,sum1; -Cin>>s1>>S2; -len1=strlen (S1); -Len2=strlen (S2); - - //printf ("C (2,3) =%d\n", C (2,3)); in - for(i=0; i<len1;i++){ to if(s1[i]=='+') a[1]++; + if(s1[i]=='-') a[0]++; - } the for(i=0; i<len2;i++){ * if(s2[i]=='+') b[1]++; $ Else if(s2[i]=='-') b[0]++;Panax Notoginseng Elseb[2]++; - } the if(b[2]==0){ + if(a[0]==b[0]&&a[1]==b[1]) printf ("1.000000000000\n"); A Elseprintf"0.000000000000\n"); the } + Else{ -pos1=a[1]-b[1]; $pos=b[2]; $tot=1; - for(i=1; i<=pos;i++) -tot*=2; the DoubleAns= (C (POS,POS1) *1.0)/tot; -printf"%.12lf\n", ans);Wuyi } the return 0; -}View Code
C. Dreamoon and Sums
Test instructions: Given a, B, find X,div (x,b)/mod (x,b) =k, where K is in the range [1,a], where mod (x,b)! = 0. To satisfy such conditions as the X and
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6 using namespacestd;7 8typedefLong LongLL;9LL mod=1000000007;Ten One intMain () A { - LL A, b; -Cin>>a>>b; theLL ans1= (A * (A +1)/2%mod*b%mod+a)%MoD; -LL ans2=b* (b-1)/2%MoD; -LL ans3=ans1*ans2%MoD; -cout<<ans3<<"\ n"; +}View Code
c = = = Translation----
Codeforces Round #272 (Div. 2)