[算法]2016.9.4
来源:互联网 发布:com域名 编辑:程序博客网 时间:2024/05/18 02:37
1.篮球联赛
悲剧的期末考试...哭哭
题目链接:http://cxsjsx.openjudge.cn/2016finalreview/1/
本来看到是个 4 * 4 的小数据量就希望能穷举...结果举了半天也没举成功
其实是个深搜,可以这么理解吧,肯定有更好的方法,暂时没想到。
考试时有个纠结的地方就在于(1,4)改了那对应的(4,1)也要改,其实完全没必要。。只用考虑一半的表格就行了
#include <iostream>#include <string>#include <cstring>#include <cmath>#include <algorithm>using namespace std;char game[5][5];int score[5];int cmax;void dfs(int x, int y){ if (x == 0 && y == 4) dfs(1, 2); if (x == 1 && y == 4) dfs(2, 3); if (x == 2 && y == 4) { int temp = 1; for (int i = 1; i < 4; ++i) { if (score[i] > score[0]) temp++; } cmax = min(cmax, temp); } if (game[x][y] == 'W') { score[x]++; dfs(x, y + 1); score[x]--; } if (game[x][y] == 'L') { score[y]++; dfs(x, y + 1); score[y]--; } if (game[x][y] == '?') { score[x]++; dfs(x, y + 1); score[x]--; score[y]++; dfs(x, y + 1); score[y]--; } return;}int main(){ int t; cin >> t; while (t--) { cmax = 5; memset(game, 0, sizeof(game)); memset(score, 0, sizeof(score)); for (int i = 0; i < 4; ++i) for (int j = 0; j < 4; ++j) cin >> game[i][j]; dfs(0, 1); cout << cmax << endl; } system("pause"); return 0;}2.函数指针
题目链接:http://cxsjsxmooc.openjudge.cn/test/20151/
指针的知识有点忘记了...
定义一个指针: int *p = ...;
p是指针,后面再引用时*p代表指针指向的内容。
#include <iostream>#include <string>using namespace std;template<class T>ostream & operator <<(ostream & o, T(*a)()){ o << (*a)(); return o;}string Print1() {return "****";}int Print2() {return 100;}int main(){cout << Print1 << Print2 << endl; return 0;}
0 0
- [算法]2016.9.4
- 4算法
- 算法4
- [算法4]TF-IDF算法
- 算法8-4:Kruskal算法
- 算法4_查找算法
- 《算法4》排序算法总结
- 常用算法(4)-归并算法
- 一步步学算法(算法题解)---4
- 【算法】4 五张图带你体会堆算法
- 最短路算法(4)- SPFA算法
- 项目 4 - 验证算法之Floyd算法
- 算法导论复习(4) floyd算法
- <算法4>第四章图算法总结
- 【图算法】(4)最短路径算法
- 算法导论 4-4
- 递归算法4C#
- 排序算法(4)
- spring源码导入eclipse
- ecshop购物车原理
- 马士兵视频:锁问题
- C++primer 第四章
- android alertdialog不能弹出弹窗问题
- [算法]2016.9.4
- java集合类
- Java基础零碎知识
- 第三方登录之QQ登录集成(二)
- 二进制中1的个数——剑指offer
- java异常类处理
- [MFC] 对话框文件拖拽
- php://input的细节问题
- final finally finalize三者有什么区别