Skip to content

Commit 491e2ce

Browse files
authored
Update README.md
#include <iostream> #include<map> using namespace std; int main() { map<int ,int > m; int n,v; cin>>n; //建立map红黑二叉树并且正确-排序 for(int i=0;i<n;i++) { cin>>v; m[v]++; } //找出中间数左边和右边数量的算法 int ans,left,right=0,midnum; midnum=(n+1)/2; for(map<int ,int >::iterator it=m.begin();it!=m.end();it++) { if(right+it->second>=midnum) { left=right; right=0; ans=it->first; } else { right+=it->second; } } if(right==left) cout<<ans<<endl; else cout<<-1<<endl; return 0; }
1 parent 09f1dfb commit 491e2ce

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@
2929
  在序列中的5个数都不满足中间数的定义。
3030
评测用例规模与约定
3131
  对于所有评测用例,1 ≤ n ≤ 1000,1 ≤ ai ≤ 1000。
32+

0 commit comments

Comments
 (0)