求助

P4715 【深基16.例1】淘汰赛

@[穆春旭](/user/148582) T or W
by HPCat @ 2020-01-22 06:25:40


@[穆春旭](/user/148582) WA 在这里 ``` cout<<(maxn1<maxn2?maxi1:maxi2); ```
by HPCat @ 2020-01-22 06:30:00


@[穆春旭](/user/148582) 您直接一遍循环不就完事了呗,用一下cmath里的pow也可以啊
by judgejudge @ 2020-01-22 08:01:09


```cpp #include <iostream> #include <cmath> #define N 1000 using namespace std; typedef long long ll; ll a[N]; ll n,maxl1=-1,maxt1,maxl2=-1,maxt2; int main(){ register int i,j; cin>>n; n=pow(2,n); for(i=1;i<=n;i++){ cin>>a[i]; if(i<=n/2){ if(a[i]>maxl1)maxl1=a[i],maxt1=i; } else{ if(a[i]>maxl2)maxl2=a[i],maxt2=i; } } if(maxl1>maxl2)cout<<maxt2<<endl; else cout<<maxt1<<endl; return 0; } ```
by judgejudge @ 2020-01-22 08:01:23


我AC了
by Robertspot @ 2020-01-22 12:16:34


这题用队列做特别简单: ```cpp #include<bits/stdc++.h> using namespace std; //p4715 int n,num; int tmp; struct node{ int a; int b; }; node tmp1,tmp2,ans; int a[130],name[130]; queue < node > q; int main(){ scanf("%d",&n); num=pow(2,n); for(int i=1;i<=num;i++){ scanf("%d",&tmp); q.push({tmp,i}); } while(q.size()!=2){ tmp1=q.front();q.pop(); tmp2=q.front();q.pop(); if(tmp1.a>tmp2.a){ q.push(tmp1); } else{ q.push(tmp2); } } tmp1=q.front();q.pop(); tmp2=q.front();q.pop(); if(tmp1.a>tmp2.a){ ans=tmp2; } else{ ans=tmp1; } printf("%d",ans.b); return 0; } ```
by Robertspot @ 2020-01-22 12:17:07


输出那句有问题不能输出两者中编号更小的那个而是能力更小的那个的编号
by Robertspot @ 2020-01-22 12:25:16


@[Robertspot](/user/236476) 简单???sort才简单吧
by cnyzz @ 2020-01-26 12:45:38


|