[算法]2016.9.4

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值