Facebook hacker cup qualification round 题解
2013-11-27 12:10
459 查看
除了第三题有点难度之外,整体还是很简单的,满分水过。。。
A 找到第一个#,计算边长,验证一下就行了。其实,20组数据,6分钟内提交,人眼去看也差不多了。。。
B 简单模拟一下就行了,由于对效率要求不高,怎么方便怎么来
C 动态规划,关键是注意到给定的概率值只到三位小数,所以状态是有限的。。。
A 找到第一个#,计算边长,验证一下就行了。其实,20组数据,6分钟内提交,人眼去看也差不多了。。。
int main(){ int t, n; string str[50]; cin>>t; for(int test=1; test<=t; test++){ bool result = true; pair<int, int> pos; int len = 0; cin>>n; for(int i=0; i<n; i++) cin>>str[i]; int row = n; int col = str[0].size(); bool fir = false; for(int i=0; i<row; i++){ if(fir==true) break; for(int j=0; j<col; j++){ if(fir == true) break; if(str[i][j]=='#'){ pos = make_pair(i, j); fir = true; break; } } } int end = pos.second; for(end=pos.second; end<col; end++){ if(str[pos.first][end]!='#'){ break; } } len = end-pos.second; //cout<<"len: "<<len<<endl; int x = pos.first; int y = pos.second; for(int i=0; i<row; i++){ for(int j=0; j<col; j++){ if((i-x)<len && (j-y)<len && i>=x && j>=y && str[i][j]!='#') result=false; if((i-x)>=len || (j-y)>=len || i<x || j<y){ if(str[i][j] == '#') result = false; } if(result == false) break; } } if(result == true) cout<<"Case #"<<test<<": YES"<<endl; else cout<<"Case #"<<test<<": NO"<<endl; } return 0; }
B 简单模拟一下就行了,由于对效率要求不高,怎么方便怎么来
int main(){ int t, n, m, p; // shot, height, name vector<pair<int, pair<int, string> > > v; cin>>t; for(int tt=1; tt<=t; tt++){ cin>>n>>m>>p; v.clear(); int shot, h; string name; for(int i=0; i<n; i++){ cin>>name>>shot>>h; v.push_back(make_pair(shot, make_pair(h, name))); } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); // time, number vector<pair<int, int> > team[2]; team[0].clear(); team[1].clear(); for(int i=0; i<n; i++){ if(i%2 == 0) team[0].push_back(make_pair(0, i)); else team[1].push_back(make_pair(0, i)); } vector<string> res; res.clear(); for(int k=0; k<2; k++){ vector<pair<int, int> > cur, rest; cur.clear(); rest.clear(); for(int i=0; i<p; i++) cur.push_back(team[k][i]); for(int i=p; i<team[k].size(); i++) rest.push_back(team[k][i]); for(int i=1; i<=m; i++){ // there is no rest player if(rest.size() == 0) break; pair<int, int> outNum, inNum; for(int j=0; j<cur.size(); j++) cur[j].first++; sort(cur.begin(), cur.end(), greater<pair<int, int> >()); sort(rest.begin(), rest.end()); outNum = cur[0]; inNum = rest[0]; cur.erase(cur.begin()); rest.erase(rest.begin()); cur.push_back(inNum); rest.push_back(outNum); } for(int i=0; i<cur.size(); i++){ int index = cur[i].second; res.push_back(v[index].second.second); } }// end outer for loop sort(res.begin(), res.end()); cout<<"Case #"<<tt<<":"; for(int i=0; i<res.size(); i++) cout<<" "<<res[i]; cout<<endl; } return 0; }
C 动态规划,关键是注意到给定的概率值只到三位小数,所以状态是有限的。。。
import java.text.DecimalFormat; import java.util.Scanner; public class facebook { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner cin = new Scanner(System.in); int t = cin.nextInt(); double[][][][] dp = new double[205][110][1005][2]; for(int tt=1; tt<=t; tt++){ // initialization int K = cin.nextInt(); for(int i=0; i<2*K+1; i++) for(int j=0; j<K+5; j++) for(int k=0; k<dp[i][j].length; k++) for(int kk=0; kk<dp[i][j][k].length; kk++) dp[i][j][k][kk] = 0; double ps = cin.nextDouble(); double pr = cin.nextDouble(); double oripi = cin.nextDouble(); int pimul = (int) Math.round(oripi*1000); double pu = cin.nextDouble(); int pumul = (int) Math.round(pu*1000); double pw = cin.nextDouble(); double pd = cin.nextDouble(); int pdmul = (int) Math.round(pd*1000); double pI = cin.nextDouble(); // int pImul = (int) Math.round(pI*1000); dp[1][1][pimul][1] = oripi*ps+(1.0-oripi)*pr; dp[1][0][pimul][0] = oripi*(1.0-ps)+(1.0-oripi)*(1.0-pr); for(int i=2; i<=2*K-1; i++){ int upper = Math.min(K, i); for(int j=0; j<=upper; j++){ if((i-1-j) >= K) continue; for(int pp=0; pp<=1000; pp++){ if(j > 0) dp[i][j][pp][1] = dp[i-1][j-1][pp][1]*(1.0-pw) +dp[i-1][j-1][pp][0]*(1.0-pI); dp[i][j][pp][0] = dp[i-1][j][pp][1]*(1.0-pw) +dp[i-1][j][pp][0]*(1.0-pI); if(pp==0){ for(int tmp=0; tmp<=pdmul; tmp++){ dp[i][j][pp][0] += dp[i-1][j][pp+tmp][0]*pI; if(j > 0) dp[i][j][pp][1] += dp[i-1][j-1][pp+tmp][0]*pI; } } if(pp==1000){ for(int tmp=0; tmp<=pumul; tmp++){ dp[i][j][pp][0] += dp[i-1][j][pp-tmp][1]*pw; if(j > 0) dp[i][j][pp][1] += dp[i-1][j-1][pp-tmp][1]*pw; } } if(pp-pumul>=0 && pp!=0 && pp!=1000){ if(j > 0) dp[i][j][pp][1] += dp[i-1][j-1][pp-pumul][1]*pw; dp[i][j][pp][0] += dp[i-1][j][pp-pumul][1]*pw; } if(pp+pdmul<=1000 && pp!=0 && pp!=1000){ if(j > 0) dp[i][j][pp][1] += dp[i-1][j-1][pp+pdmul][0]*pI; dp[i][j][pp][0] += dp[i-1][j][pp+pdmul][0]*pI; } double oopi = (double)pp/1000.0; dp[i][j][pp][1] *= oopi*ps+(1.0-oopi)*pr; dp[i][j][pp][0] *= oopi*(1.0-ps)+(1.0-oopi)*(1.0-pr); }// end pp loop }// end j loop }// end i loop double res = 0; for(int i=K; i<=2*K-1; i++){ for(int pp=0; pp<=1000; pp++){ res += dp[i][K][pp][1]; } } DecimalFormat df = new DecimalFormat("0.000000"); System.out.println("Case #"+tt+": "+df.format(res)); } }// end main method }
相关文章推荐
- Facebook Hacker Cup 2016 Qualification Round Text Editor
- Facebook Hacker cup Qualification round Problem 1
- Facebook Hacker Cup 2016 Qualification Round The Price is Correct
- Facebook Hacker Cup 2015 Round 1 --- Homework
- Facebook Hacker Cup 2015 Round 1--Corporate Gifting(树形动态规划)
- Facebook Hacker Cup 2016 Round 1 Laundro, Matt
- FaceBook Hacker Cup 2016 Qualification - Text Editor (dp)
- Facebook Hacker Cup 2015 Round 1 --- Autocomplete
- Facebook Hacker Cup 2015 Round 1--Winning at Sports(动态规划)
- Facebook Hacker Cup 2015 Round 1 --- Winning at Sports
- Facebook Hacker Cup 2016 Round 1 Boomerang Tournament
- FaceBook Hacker Cup 2016 Qualification - High Security (贪心)
- Facebook Hacker Cup 2015 Round 1--Homework(筛选法求素数)
- Facebook Hacker Cup 2017 Round 1 Pie Progress
- Facebook Hacker Cup 2015 Round 1--Corporate Gifting(树动态规划)
- Facebook Hacker Cup 2015 Round 1 Homework(附带测试数据)
- Facebook Hacker Cup 2015 Round 1--Homework(筛选法求素数)
- Facebook Hacker Cup 2015 Round 1 Autocomplete (附带测试数据)
- Facebook Hacker Cup 2016 Round 2
- Facebook Hacker Cup 2015 Round 1 Winning at Sports (附带测试数据)