SRM 555 DIV2
2012-09-08 23:43
447 查看
第一次做出来第二道题,真不容易啊
第一道题比较水,穷举各种情况就可以了
第二道题就单源最短路径问题
第一道题比较水,穷举各种情况就可以了
#include <iostream> #include <string> #include <vector> #include <cstdlib> #include <cmath> #include <map> #include <algorithm> #include <list> #include <ctime> #include <set> #include <queue> using namespace std; class XorBoardDivTwo{ public: int theMax(vector <string> board){ int row=board.size(); int col=board[0].size(); int i,j,k,l,i1,i2; int res=0; vector <string> orign=board; vector <string> tmp,tmp2; for(i=0;i<row;i++){ tmp=orign; for(k=0;k<col;k++){ if(tmp[i][k]=='1') tmp[i][k]='0'; else tmp[i][k]='1'; } for(j=0;j<col;j++){ tmp2=tmp; for (l = 0; l < row; l++) { if (tmp2[l][j] == '1') tmp2[l][j] = '0'; else tmp2[l][j] = '1'; } int res_tmp=0; for(i1=0;i1<row;i1++){ for(i2=0;i2<col;i2++) if(tmp2[i1][i2]=='1') res_tmp++; } res=max(res,res_tmp); } } return res; } };
第二道题就单源最短路径问题
#include <iostream> #include <string> #include <vector> #include <cstdlib> #include <cmath> #include <map> #include <algorithm> #include <list> #include <ctime> #include <set> #include <queue> #include <stack> using namespace std; class CuttingBitString { public: int valid(string var) {//判断是不是1,5,25..... if (var.size() == 1) { if (var[0] == '1') return 1; else return 0; } int var_size = var.size(); if (var[0] == '0') return 0; long long tmp = 0; long long mul = 1; for (int i = var_size - 1; i >= 0; i--) { tmp = (tmp + (var[i] - '0') * mul); mul *= 2; } while (tmp % 5 == 0) { tmp = tmp / 5; } if (tmp == 1) return 1; return 0; } int getmin(string S) { map<int, map<int, int> > path; int i, j; int var_size = S.size(); string tmp; for (i = 0; i < var_size; i++) { for (j = 0; j < var_size; j++) { path[i][j] =0; } } for (i = 0; i < var_size; i++) { for (j = i; j < var_size; j++) { tmp = S.substr(i, j - i + 1); path[i][j] = valid(tmp); } } map<int, int> min_path; for (i = 0; i < var_size; i++) { min_path[i] = 1000; } min_path[var_size] = 0; for (i = var_size - 1; i >= 0; i--) { for (j = i; j < var_size - 1; j++) { if (path[i][j] == 1 && min_path[j + 1] < 1000) { min_path[i] = min(min_path[i], 1 + min_path[j+1]); } } if (path[i][var_size - 1]) min_path[i] = min(min_path[i], 1); } if (min_path[0] == 0||min_path[0]==1000) return -1; return min_path[0]; } };
相关文章推荐
- SRM 555 DIV2
- [容斥原理][复杂度分析] SRM 555 Div1 Hard MapGuessing
- srm555 div2
- SRM 555 DIV2 555
- SRM556 Div1 555
- [组合数] SRM 555 Div1 Medium XorBoard
- srm555 div1
- SRM 555 DIV 2
- SRM 587 Div II L3:ThreeColorabilityEasyy
- SRM 448 DIV 1 总结(dfs, dp)
- TopCoder SRM 474 DIV1 1000
- SRM588 KeyDungeonDiv1
- srm588 div1
- SRM149 - SRM150(少SRM150-DIV1-LV3)
- StrangeDictionary(SRM542-div2-3)
- SRM 543 Div2
- Topcoder SRM 654 DIV1 500 FoldingPaper2 递归 + 枚举
- TopCoder SRM 677 Div. 2 550 - FourStrings (枚举)
- TC SRM 551 div2 题解