/// 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.in", "r", stdin) #define WRITE freopen("output.txt", "w", stdout) int main() { READ; WRITE; ios_base::sync_with_stdio(0);cin.tie(0); int tc,kk=1, n, taken[30]; string s; cin>>tc; while(tc--) { cin>>n; getline(cin, s); vector< pair< int, string> > v; for(int i=0;i<n;i++) { int cnt=0; CLR(taken); getline(cin, s); int l=s.size(); for(int j=0;j<l;j++) if(isalpha(s[j])) if(taken[s[j]-'A']==0) { taken[s[j]-'A']++; cnt++; } //cout<<s<<" "<<cnt<<endl; v.push_back(make_pair(102-cnt, s)); } sort(v.begin(), v.end()); cout<<"Case #"<<kk++<<": "<< v[0].second <<"\n"; } return 0; }
Sunday, 10 July 2016
Google APAC 2017 University Test Round A Problem A. Country Leader
Google APAC 2017 University Test Round A Problem C. Jane's Flower Shop
/// 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("C-large-practice.in", "r", stdin) #define WRITE freopen("output.txt", "w", stdout) int m; vector<double> v; double chk(double x) { double val = v[0], r=x; for(int i=1;i<=m;i++) { val+=v[i]*r; r*=x; } return val; } int main() { READ; WRITE; ios_base::sync_with_stdio(0); cin.tie(0); int tc,kk=1; double x; cin>>tc; while(tc--) { v.clear(); cin>>m; for(int i=0;i<=m;i++) { cin>>x; if(!i) x*=-1.0; v.push_back(x); } reverse(v.begin(), v.end()); double hi=2.0, lo=0.0, mid; for(int i=0; i<100; i++) { mid=(hi+lo)/2.0; if(chk(mid)<=0.0) hi=mid; else lo=mid; } cout<<"Case #"<<kk++<<": "<< setprecision(10)<<fixed<< mid-1.0 <<"\n"; } return 0; }
Google APAC 2017 University Test Round A Problem B. Rain (Spoj WATER - Water among Cubes)
/// 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) int h[55][55], w[55][55], r, c, dx[]={1, -1, 0, 0}, dy[]={0, 0, 1, -1}; int main() { READ; WRITE; ios_base::sync_with_stdio(0);cin.tie(0); int tc,kk=1, n; cin>>tc; while(tc--) { cin>>r>>c; //CLR(visit); for(int i=1;i<=r;i++) for(int j=1;j<=c;j++) { cin>>h[i][j]; if(i==1 || i==r || j==1 || j==c) w[i][j]=h[i][j]; //boundary else w[i][j]=1000; //inf } bool updateFound=true; while(updateFound) { updateFound=false; for(int i=2;i<r;i++) for(int j=2;j<c;j++) { int mn=w[i][j]; for(int k=0;k<4;k++) { int x=i+dx[k]; int y=j+dy[k]; mn=min(mn, max(w[x][y], h[x][y])); } if(mn<w[i][j]) { w[i][j]=mn; updateFound=true; } } } int ans=0; for(int i=1;i<=r;i++) for(int j=1;j<=c;j++) if(w[i][j]>h[i][j]) ans+=w[i][j]-h[i][j]; cout<<"Case #"<<kk++<<": "<< ans <<"\n"; } return 0; }
Saturday, 9 July 2016
DNA Sorting (UVA 612, HDU 1379, POJ 1007, ZOJ 1188, UVALive 5414, Regionals 1998 >> North America - East Central NA)
/// 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 int main() { ios_base::sync_with_stdio(0);cin.tie(0); int kk=1, tc, n, m, cnt; string s; cin>>tc; while(tc--) { cin>>n>>m; vector< pair<int, pair<int, string> > > v; for(int i=0;i<m;i++) { cin>>s; cnt=0; for(int j=0;j<n-1;j++) for(int k=j+1;k<n;k++) if(s[j]>s[k]) cnt++; v.push_back(make_pair(cnt, make_pair(i,s))); } sort(v.begin(), v.end()); if(kk>1) cout<<"\n"; for(int i=0;i<m;i++) cout<<v[i].second.second<<"\n"; kk++; } return 0; }
Subscribe to:
Posts (Atom)