(第六场)Singing Contest 【模拟】

本文介绍了一个涉及2^n位歌手的歌唱比赛问题,每位歌手需在比赛中选择最优歌曲以获得胜利。通过对歌手策略的分析,使用贪心算法和DFS深度优先搜索来确定最终胜者。

题目链接:https://www.nowcoder.com/acm/contest/144/A

标题:A、Singing Contest

| 时间限制:1 秒 | 内存限制:256M

Jigglypuff is holding a singing contest. There are 2n singers indexed from 1 to 2n participating in the contest. The rule of this contest is like the knockout match. That is, in the first round, singer 1 competes with singer 2, singer 3 competes with singer 4 and so on; in the second round, the winner of singer 1 and singer 2 competes with the winner of singer 3 and singer 4 and so on. There are n rounds in total. Each singer has prepared n songs before the contest. Each song has a unique pleasantness. In each round, a singer should sing a song among the songs he prepared. In order not to disappoint the audience, one song cannot be performed more than once. The singer who sings the song with higher pleasantness wins. Now all the singers know the pleasantness of songs prepared by all the others. Everyone wants to win as many rounds as he can. Assuming that singers choose their song optimally, Jigglypuff wants to know which singer will win the contest?
输入描述: The input starts with one line containing exactly one integer t which is the number of test cases. (1 ≤ t ≤ 10)

For each test case, the first line contains exactly one integer n where 2n is the number of singers. (1 ≤ n ≤ 14)

Each of the next 2n lines contains n integers where aij is the pleasantness of the j-th song of the ith singer. It is guaranteed that all these 2nx n integers are pairwise distinct. (1≤ aij ≤ 109)

输出描述: For each test case, output "Case #x: y" in one line (without quotes), where x is the test case number (starting from 1) and y is the index of the winner.

示例 1

输入

2

1

1

2

2

1 8

2 7

3 4

5 6

输出

Case #1: 2

Case #2: 4

 

题意概括:

歌唱比赛,有2^N位歌手,每位歌手准备N首歌,每首歌可以得到的分数不同,每首歌只能唱一次。1和2比,3和4比...赢了的继续比下去,问最后谁会获胜。每位歌手的歌曲得分用一个二维矩阵表示,A[ i ][ j ]表示第 i 位歌手唱第 j 首歌可以得到的分数。

官方题解:

由于每个选⼿手的策略略都是尽可能赢,所以他该认输的时候只能认输。
能赢的时候只要选权值⼤大于对⽅方最⼤大值的最⼩小值,⼤大的留留在后⾯面不不会 更更差。
直接模拟即可。

解题思路:

每次对决,遵循贪心的原则,排序之后lower_bound()可以打败对手的最小值,遍历对决可以用DFS二分一下。

 

AC code:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 const int MAXN = (1<<14)+15;
 5 int f[MAXN][15];
 6 int N;
 7 
 8 int dfs(int l, int r)
 9 {
10     if(r == l+1)
11     {
12         sort(f[l], f[l]+N);
13         sort(f[r], f[r]+N);
14         int a = lower_bound(f[l], f[l]+N, f[r][N-1])-f[l];
15         int b = lower_bound(f[r], f[r]+N, f[l][N-1])-f[r];
16         if(a == N)
17         {
18             f[r][b] = 0;
19             return r;
20         }
21         else
22         {
23             f[l][a] = 0;
24             return l;
25         }
26     }
27     else
28     {
29         int mid = (l+r)>>1;
30         int x = dfs(l, mid);
31         int y = dfs(mid+1, r);
32         sort(f[x], f[x]+N);
33         sort(f[y], f[y]+N);
34         int a = lower_bound(f[x], f[x]+N, f[y][N-1])-f[x];
35         int b = lower_bound(f[y], f[y]+N, f[x][N-1])-f[y];
36         if(a == N)
37         {
38             f[y][b] = 0;
39             return y;
40         }
41         else
42         {
43             f[x][a] = 0;
44             return x;
45         }
46     }
47 }
48 
49 int main()
50 {
51     int T_case;
52     scanf("%d", &T_case);
53     int cnt = 0;
54     while(T_case--)
55     {
56         scanf("%d", &N);
57         for(int i = 1; i <= (1<<N); i++)
58             for(int j = 0; j < N; j++)
59         {
60             scanf("%d", &f[i][j]);
61         }
62         printf("Case #%d: %d\n", ++cnt, dfs(1, (1<<N)));
63     }
64     return 0;
65 }
View Code

 

【电动汽车充电站有序充电调度的分散式优化】基于蒙特卡诺和拉格朗日的电动汽车优化调度(分时电价调度)(Matlab代码实现)内容概要:本文介绍了基于蒙特卡洛和拉格朗日方法的电动汽车充电站有序充电调度优化方案,重点在于采用分散式优化策略应对分时电价机制下的充电需求管理。通过构建数学模型,结合不确定性因素如用户充电行为和电网负荷波动,利用蒙特卡洛模拟生成大量场景,并运用拉格朗日松弛法对复杂问题进行分解求解,从而实现全局最优或近似最优的充电调度计划。该方法有效降低了电网峰值负荷压力,提升了充电站运营效率与经济效益,同时兼顾用户充电便利性。 适合人群:具备一定电力系统、优化算法和Matlab编程基础的高校研究生、科研人员及从事智能电网、电动汽车相关领域的工程技术人员。 使用场景及目标:①应用于电动汽车充电站的日常运营管理,优化充电负荷分布;②服务于城市智能交通系统规划,提升电网与交通系统的协同水平;③作为学术研究案例,用于验证分散式优化算法在复杂能源系统中的有效性。 阅读建议:建议读者结合Matlab代码实现部分,深入理解蒙特卡洛模拟与拉格朗日松弛法的具体实施步骤,重点关注场景生成、约束处理与迭代收敛过程,以便在实际项目中灵活应用与改进。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值