UVA_167_The Sultan's Successors
来源:互联网 发布:游戏优化怎么做 编辑:程序博客网 时间:2024/06/06 12:36
#include<iostream>#include<vector>#include<string>#include<sstream>#include<cmath>#include<algorithm>using std::cin;using std::cout;using std::endl;using std::vector;using std::string;using std::stringstream;using std::swap;using std::sort;using std::max;bool check(const vector<int>&board, const int &row, const int &column){ for (int i = 1; i < board.size(); i++) { //两个棋子在同一列 if (board[i] == column) { return false; } //k=-1 if ((row - i == column - board[i]) || (row - i == board[i] - column)) { return false; } } return true;}void get(vector<vector<int>>&solution){ for (int one = 1; one <= 8; one++) { vector<int>board(1); board.push_back(one); for (int two = 1; two <= 8; two++) { board.resize(2); if (check(board, 2, two)) { board.push_back(two); } else { continue; } for (int three = 1; three <= 8; three++) { board.resize(3); if (check(board, 3, three)) { board.push_back(three); } else { continue; } for (int four = 1; four <= 8; four++) { board.resize(4); if (check(board, 4, four)) { board.push_back(four); } else { continue; } for (int five = 1; five <= 8; five++) { board.resize(5); if (check(board, 5, five)) { board.push_back(five); } else { continue; } for (int six = 1; six <= 8; six++) { board.resize(6); if (check(board, 6, six)) { board.push_back(six); } else { continue; } for (int seven = 1; seven <= 8; seven++) { board.resize(7); if (check(board, 7, seven)) { board.push_back(seven); } else { continue; } for (int eight = 1; eight <= 8; eight++) { board.resize(8); if (check(board, 8, eight)) { board.push_back(eight); solution.push_back(board); } else { continue; } } } } } } } } }}int calculate(const vector<vector<int>>&value,const vector<int>&board){ int sum=0; for (int i = 1; i <= 8; i++) { sum += value[i][board[i]]; } return sum;}int main(){ //freopen("input.txt", "r", stdin); //freopen("output.txt","w",stdout); vector<vector<int>>solution; get(solution); int T; while (cin >> T) { while (T--) { vector<vector<int>>value(9, (vector<int>)9); for (size_t i = 1; i <= 8; i++) { for (size_t j = 1; j <= 8; j++) { int num; cin >> num; value[i][j] = num; } } int maximum = 0; for (size_t i = 0; i < solution.size(); i++) { maximum = max(maximum, calculate(value, solution[i])); } stringstream stream; stream << maximum; string str; stream >> str; for (int n = 5; n > str.size(); n--) { cout << ' '; } cout << maximum << endl; } } return 0;}
0 0
- UVA_167_The Sultan's Successors
- UVA_167_The Sultan's Successors
- The Sultan's Successors
- UVA167The Sultan's Successors
- uva167 The Sultan's Successors
- 167 - The Sultan's Successors
- vua167 - The Sultan's Successors
- UVaOJ167 - The Sultan's Successors
- uva167 The Sultan's Successors
- UVA The Sultan's Successors
- uva167 The Sultan's Successors
- 167The Sultan's Successors
- UVa 167 - The Sultan's Successors
- 167 - The Sultan's Successors 回溯
- Uva 167 The Sultan's Successors
- uva 167 - The Sultan's Successors
- uva 167 - The Sultan's Successors
- UVa 167 - The Sultan's Successors
- 数据库锁
- Minimum Inversion Number
- xutils引入SQLcipher实现加密本地数据库
- 第三周项目:输出星号图-倒三角
- BZOJ2226: [Spoj 5971] LCMSum
- UVA_167_The Sultan's Successors
- Cookie和Session
- 翻转问题(开关,开灯问题)求解技巧
- 解决C# FileUpload上传文件过大的时候出现的错误
- 【引用】 PB绝对有用的未公开函数
- 几个常见工具的使用
- 第八届河南省程序设计大赛-B.最大岛屿0000110011000000
- 逆向工程实战--Afkayas.1
- 逻辑回归(代价函数,梯度下降) logistic regression--cost function and gradient descent