https://www.luogu.com.cn/problem/P8587
模拟
黄色题
思路:直接枚举高度相同的柱子的高度,枚举过程中统计个数,枚举结束后,排序(按柱子数量从大往小排),然后找数量相同但高度不同的柱子方案
#include<bits/stdc++.h> using namespace std; const int maxn=5005; int n,shu[maxn*2],minn,maxx,h[maxn*2]; bool cmp(int a,int b) { return a>b; } int main() { cin>>n; for(int i=1; i<=n; i++) { int h; cin>>h; shu[h]++; minn=min(minn,h); maxx=max(maxx,h); } for(int i=minn*2; i<=maxx*2; i++) { for(int j=1; j<=i/2; j++) { if(j==i-j) { h[i]+=shu[j]/2; } else h[i]+=min(shu[j],shu[i-j]); } } sort(h+1,h+maxx*2+1,cmp); cout<<h[1]<<" "; int ans=1; for(int i=2; i<=maxx*2+1; i++) { if(h[i]!=h[i-1]) break; ans++; } cout<<ans; return 0; }
标签:家乡,maxx,minn,int,P8587,枚举,maxn From: https://www.cnblogs.com/2elaina/p/16796354.html