A
Test instructions: Give a piece of paper with a width of B, each time with a short edge as the side length of the square, ask how many squares can be obtained
First, divide directly into a/b, and then use a%b,b as the length and width of the new paper, to do the same thing.
When you do it = = the process of simulating division (with subtraction = =) To find out time-outs, and then a special sentence if a/b>10000 alone processing = = It was actually over.
= = Tle---tle---tle------
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stack>6#include <vector>7#include <map>8#include <queue>9#include <algorithm>Ten #definemod=1e9+7; One using namespacestd; A -typedefLong LongLL; - the intMain () { -LL a,b,ans=0; -Cin>>a>>b; - while(1){ + if(a<b) Swap ( A, a); - if(b==0) Break; +ans+=a/b; ALL tmp=a%b; atA=b; -b=tmp; - } -cout<<ans<<"\ n"; - return 0; -}
View Code
B
Test instructions: Gives two identical string s,t, defines the number of characters at the corresponding position of two strings, asks the minimum distance that can be obtained by one exchange, and outputs the position of the interchange
DP[A][B], respectively, will be in the same position, S[i] and T[i] different positions recorded down,
If DP[A][B] and dp[b][a] are present, then after the swap, just match, the maximum distance minus 2 if only dp[a][b] exists, then the maximum distance minus 1
Say this question, oneself do time is a little train of thought have no, study this question well =
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stack>6#include <vector>7#include <map>8#include <queue>9#include <algorithm>Ten #definemod=1e9+7; One using namespacestd; A -typedefLong LongLL; - Const intmaxn=200005; the CharS[MAXN],T[MAXN]; - intdp[ the][ the]; - intHAS[MAXN]; - + intMain () { - inti,j,n,ans=0; +scanf"%d",&n); ACin>> (s+1) >> (t+1); at for(i=1; i<=n;i++){ - if(s[i]!=T[i]) { -dp[s[i]-'a'][t[i]-'a']=i; -has[s[i]-'a']=i; -ans++; - } in } - to for(i=0;i< -; i++){ + for(j=0;j< -; j + +){ - if(dp[i][j]!=0&&dp[j][i]!=0){ theprintf"%d\n", ans-2); *printf"%d%d\n", Dp[i][j],dp[j][i]); $ return 0;Panax Notoginseng } - } the } + A for(i=0;i< -; i++){ the for(j=0;j< -; j + +){ + if(dp[i][j]!=0&&has[j]!=0){ -printf"%d\n", ans-1); $printf"%d%d\n", Dp[i][j],has[j]); $ return 0; - } - } the } - Wuyiprintf"%d\n", ans); theprintf"-1-1\n"); - return 0; Wu}
View Code
C
Test instructions: Given the length of W, width of h glass, now cut n knives, ask each cut, the largest glass fragments of the area
Because each time a knife down, the current interval will be divided into 2 parts, so in order to make the largest area, from the current horizontal range of the largest selection of the longest, from the current vertical range to take the largest width
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stack>6#include <vector>7#include <map>8#include <queue>9#include <Set>Ten#include <algorithm> One #definemod=1e9+7; A using namespacestd; - -typedefLong LongLL; themultiset<int>HH,VV; - Set<int>ph,qv; - Set<int>:: iterator r,l; - + intMain () { - CharC; + intX,w,h,n; Ascanf"%d%d%d",&w,&h,&n); GetChar (); atPh.insert (0);p H.insert (h); -Qv.insert (0); Qv.insert (w); - Hh.insert (h); Vv.insert (w); - - while(n--){ -scanf"%c%d",&c,&x); GetChar (); in - if(c = ='H') to { +L =ph.lower_bound (x); -R = l; l--; the Ph.insert (x); *Hh.insert (X (*l)); $Hh.insert ((*r)-x);Panax NotoginsengHh.erase (Hh.find (*R)-(*l))); - } the Else + { AL =qv.lower_bound (x); theR = l; l--; + Qv.insert (x); -Vv.insert (X-(*l)); $Vv.insert ((*r)-x); $Vv.erase (Vv.find (*R)-(*l))); - } - theprintf"%i64d\n", (Long Long) (*hh.rbegin ()) * (*Vv.rbegin ())); - Wuyi the } - return 0; Wu}
View Code
Write with the array, timed out, and then see the puzzle, with the STL inside things, is really not familiar with too unfamiliar
Go---go---go----
Codeforces Round #296 (Div. 2)