A 小H学语文 (贪心)
题意:给定n个木板,1~n长度为h[i],选则m块木板,使m*m*h(min) 最大
思路:贪心的(将木板降序排列后)从n到1(越多越好)枚举木板数量m,同时记录答案,当取到最大值使记录此时的木板数量,最后输出选择的木板的编号
小tips:使用结构体来维护木板的h和编号
const int N = 2e5 + 9; struct Node
{LL x,i;
}a[N];int n;
vector<int> vec[N];bool cmp(const Node& a,const Node& b)
{return a.x > b.x;
}void solve()
{cin >> n;for (int i = 1;i <= n;i ++) {cin >> a[i].x;a[i].i = i;}sort(a + 1,a + 1 + n,cmp);LL ans = -1;int id = n;for (int i = 1;i <= n;i ++){if (ans < i * i * a[i].x){ans = i * i * a[i].x;id = i;}}cout << id << endl;vector<int> c;for (int i = 1;i <= id;i ++) c.push_back(a[i].i);sort(c.begin(),c.end());for (auto &t : c) cout << t << " ";
}