惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
G
Google Developers Blog
T
Tailwind CSS Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
人人都是产品经理
人人都是产品经理
J
Java Code Geeks
P
Proofpoint News Feed
V
Visual Studio Blog
爱范儿
爱范儿
The Cloudflare Blog
博客园 - 叶小钗
V
V2EX
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
M
MIT News - Artificial intelligence
Microsoft Security Blog
Microsoft Security Blog
博客园 - 聂微东
H
Help Net Security
B
Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 【当耐特】
量子位
宝玉的分享
宝玉的分享
WordPress大学
WordPress大学
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

OhYee 博客

小鹏辅助驾驶测评|OhYee 博客 小鹏非支持手机开启自动解锁|OhYee 博客 使用函数计算实现 301 重定向|OhYee 博客 针对 HTML 内容使用 Ant Design 图片弹框|OhYee 博客 博客进程泄露及僵尸进程解决|OhYee 博客 蓝易云服务器体验|OhYee 博客 SSH 调起本地 VSCode|OhYee 博客 【2022 秋招内推】阿里云后端研发工程师|OhYee 博客 使用函数计算获取 IP 地址信息|OhYee 博客 正确获取客户端 IP/HTTP Header 也可能重复|OhYee 博客 评测 Oculus Quest2 及 BigScreen|OhYee 博客 NextJS 热重载保留状态|OhYee 博客 如何优雅地贴 gist 代码|OhYee 博客 Linux 精细化文件权限|OhYee 博客 VSCode 容器开发环境|OhYee 博客 Clash 的不兼容更新排查|OhYee 博客 Zeek 导出 PCAP|OhYee 博客 记一次 ssh 配置问题|OhYee 博客 Git Commit 规范化工具|OhYee 博客 谈谈《星之卡比-探索发现》|OhYee 博客 VSCode 快捷键绑定 Shell 命令|OhYee 博客 ASN.1 语法及 X.509 证书格式解析解析|OhYee 博客 腾讯企业邮箱忽略 MX 记录发信|OhYee 博客 Chrome/Edge 标签组插件|OhYee 博客 【应届内推】阿里云后端研发工程师|OhYee 博客 损坏的 Typecho 备份处理为 JSON|OhYee 博客 VS Code VIM 插件高效使用|OhYee 博客 SSH 正反向代理|OhYee 博客 Let's Encrypt 根证书过期引发的问题|OhYee 博客 OpenWRT 忽略内核依赖|OhYee 博客
POJ 3071.Football|OhYee 博客
2017-08-03 · via OhYee 博客

这是一篇最后编辑于 8 年前 的文章,其内容可能与目前实际情况差异较大,请注意甄别

题目

{% fold 点击显/隐题目 %}

Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, …, 2n. In each round of the tournament, all teams still in the tournament are placed in a list in order of increasing index. Then, the first team in the list plays the second team, the third team plays the fourth team, etc. The winners of these matches advance to the next round, and the losers are eliminated. After n rounds, only one team remains undefeated; this team is declared the winner. Given a matrix P = [pij] such that pij is the probability that team i will beat team j in a match determine which team is most likely to win the tournament.

The input test file will contain multiple test cases. Each test case will begin with a single line containing n (1 ≤ n ≤ 7). The next 2n lines each contain 2n values; here, the jth value on the ith line represents pij. The matrix P will satisfy the constraints that pij = 1.0 ? pji for all i ≠ j, and pii = 0.0 for all i. The end-of-file is denoted by a single line containing the number ?1. Note that each of the matrix entries in this problem is given as a floating-point value. To avoid precision problems, make sure that you use either the double data type instead of float.

The output file should contain a single line for each test case indicating the number of the team most likely to win. To prevent floating-point precision issues, it is guaranteed that the difference in win probability for the top two teams will be at least 0.01.

2 0.0 0.1 0.2 0.3 0.9 0.0 0.4 0.5 0.8 0.6 0.0 0.6 0.7 0.5 0.4 0.0 -1

2

{% endfold %}

题解

画出来比赛的流程图,可以发现能够用位运算方便表示出如何进行比赛
如队伍i的第j场比赛的对手是对i的j位取反,后面的数为0到为1的范围内的数

然后使用dp[i][j]表示第i场比赛,队伍j获胜的概率
计算出所有的值然后选出最大的即可

代码

{% fold 点击显/隐代码 %}```cpp Football https://github.com/OhYee/sourcecode/tree/master/ACM 代码备份
//
#define debug
#include
//
/
#include
#include
#include
using namespace std;

const int maxn = 8;
const int maxm = 2 << 8;
double Pro[maxm][maxm];
double dp[maxn][maxm];

int getTeam(int number, int bit, int flag) {
int ans = number ^ (1 << bit); //把bit位取反

ans = (ans >> (bit)) << (bit);
if (flag)
    ans += (1 << bit) - 1;

return ans;

}

int main() {
#ifdef debug
freopen("in.txt", "r", stdin);
int START = clock();
#endif
cin.tie(0);
cin.sync_with_stdio(false);

int n;
while (cin >> n) {
    if (n == -1)
        continue;
    for (int i = 0; i < (1 << n); i++)
        for (int j = 0; j < (1 << n); j++)
            cin >> Pro[i][j];

    for (int i = 0; i < n; i++) {
        // cout << "Game round" << i + 1 << ": " << endl;
        for (int j = 0; j < (1 << n); j++) {
            if (i == 0) {
                // cout << "\t" << j << " vs. " << getTeam(j, i, 1) << endl;
                dp[i][j] = Pro[j][getTeam(j, i, 0)];
            } else {
                dp[i][j] = 0;
                for (int k = getTeam(j, i, 0); k <= getTeam(j, i, 1); k++) {
                    // cout << "\t" << j << " vs. " << k << endl;
                    dp[i][j] += dp[i - 1][k] * Pro[j][k];
                }
                dp[i][j] *= dp[i - 1][j];
            }
            // cout << "\t\tdp[i][j]=" << dp[i][j] << endl;
        }
    }

    int pos = 0;
    for (int i = 1; i < (1 << n); i++) {
        // cout << dp[n - 1][i] << endl;
        if (dp[n - 1][i] > dp[n - 1][pos])
            pos = i;
    }
    cout << pos + 1 << endl;
}

#ifdef debug
printf("Time:%.3fs.\n", double(clock() - START) / CLOCKS_PER_SEC);
#endif
return 0;
}

{% endfold %}