C++深信服笔试
中位数 #include<bits/stdc++.h> using namespace std; priority_queue<int,vector<int>,less<int>> L; priority_queue<int,vector<int>,greater<int>> R; void up(int x) { if(L.size()<=R.size()) { if(!R.empty()&&R.top()<x) { L.push(R.top());R.pop(); R.push(x); } else L.push(x); } else{ if(!L.empty()&&L.top()>x) { R.push(L.top());L.pop(); L.push(x); } else R.push(x); } } int main() { int n,t; while(cin>>n){ for(int i=1;i<=n;i++) { cin>>t; up(t); } while(L.size()>R.size()+1) { R.push(L.top()); L.pop(); } while(L.size()<R.size()+1) { L.push(R.top()); R.pop(); } cout<<L.top()<<endl; } return 0; }
切蛋糕#include<bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--){ long long x,n; cin>>x>>n; long long s = 0; if(n>=x){ s = max(s,x*(n-x)); } for(int i=1;i<=n;i++){ s = max(s,i*(n-2*i)); } cout<<s<<endl; } return 0; }
剩下两个板子题没搓出来,没板战士等于辣鸡