每日一题——P4715 【深基16.例1】淘汰赛

Eureka.. 2022-04-15 20:46:24
加精

把结构体换成两个数组就会超时

#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
struct Country{
    int power;
    int index;
}bicountry[138];
bool cmp(Country x,Country y)
{
    return x.power < y.power;
}
int main()
{
    int n;
    int s = 0,t = 0;
    cin >> n;
    int cnt = pow(2,n);
    for(int i = 1;i <= cnt;i++)
    {
        int aa;
        cin >> aa;
        bicountry[i].power = aa;
        bicountry[i].index = i;
    }
    sort(bicountry+1,bicountry+cnt/2+1,cmp);
    sort(bicountry+cnt/2+1,bicountry+cnt+1,cmp);
//    for(int i = 1;i <= cnt;i++)
//        cout << bicountry[i].power << " " << bicountry[i].index << endl;
    if(bicountry[cnt/2].power > bicountry[cnt].power)
        cout << bicountry[cnt].index;
    else
        cout << bicountry[cnt/2].index;
    return 0;
}

 

...全文
67 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

51,712

社区成员

发帖
与我相关
我的任务
社区描述
和众多高校算法内卷分子,一起学习和交流算法那。浓郁的算法交流氛围,拒绝躺平,有效内卷。加入我们,私信我拉你入核心内卷群。
算法数据结构leetcode 个人社区
社区管理员
  • 执 梗
  • Dream-Y.ocean
  • ღCauchyོꦿ࿐
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

 刷题!

试试用AI创作助手写篇文章吧