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;
}