1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | /// Raihan Ruhin /// CSE, Jahangirnagar University. /// Dhaka-Bangladesh. /// id: raihanruhin (topcoder / codeforces / codechef / uva ), 3235 (lightoj) /// mail: raihanruhin@ (yahoo / gmail / facebook) /// blog: ruhinraihan.blogspot.com #include<bits/stdc++.h> using namespace std; #define SET(a) memset(a,-1,sizeof(a)) #define CLR(a) memset(a,0,sizeof(a)) #define PI acos(-1.0) #define MOD 1000000007 #define MX 100010 #define READ freopen("B-large-practice.in", "r", stdin) #define WRITE freopen("output.txt", "w", stdout) vector<long long>tidy; void precal(int sz, long long number) { if(sz==18) { tidy.push_back(number); return; } int lastDigit = number%10; for(int i=lastDigit;i<=9;i++) precal(sz+1, number*10+i); return; } int main() { READ; WRITE; ios_base::sync_with_stdio(0);cin.tie(0); int tc,kk=1; long long n; string s; cin>>tc; precal(0, 0); while(tc--) { cin>>n; auto it = upper_bound(tidy.begin(), tidy.end(), n); it--; cout<<"Case #"<<kk++<<": "<< *it <<"\n"; } return 0; } |
Monday, 24 April 2017
Tidy Numbers (Codejam Qualification Round 2017, Problem B)
Oversized Pancake Flipper ( Codejam Qualification Round 2017, Problem A)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | /// Raihan Ruhin /// CSE, Jahangirnagar University. /// Dhaka-Bangladesh. /// id: raihanruhin (topcoder / codeforces / codechef / uva ), 3235 (lightoj) /// mail: raihanruhin@ (yahoo / gmail / facebook) /// blog: ruhinraihan.blogspot.com #include<bits/stdc++.h> using namespace std; #define SET(a) memset(a,-1,sizeof(a)) #define CLR(a) memset(a,0,sizeof(a)) #define PI acos(-1.0) #define MOD 1000000007 #define MX 100010 #define READ freopen("A-large-practice.in", "r", stdin) #define WRITE freopen("output.txt", "w", stdout) int minFlip(string s, int k) { int n = s.length(); int cnt = 0; for(int i=0;i<=n-k;i++) { if(s[i]=='-') { cnt++; for(int j=i;j<i+k;j++) s[j] = s[j]=='-' ? s[j]='+' : s[j]='-'; } } for(int i=n-1;i>n-k;i--) if(s[i]!='+') return -1; return cnt; } int main() { READ; WRITE; ios_base::sync_with_stdio(0);cin.tie(0); int tc,kk=1, n, k; string s; cin>>tc; while(tc--) { cin>>s; cin>>k; n = minFlip(s, k); if(n==-1) cout<<"Case #"<<kk++<<": IMPOSSIBLE\n"; else cout<<"Case #"<<kk++<<": "<< n <<"\n"; } return 0; } |
Subscribe to:
Posts (Atom)