E. Best Pair

网友投稿 232 2022-09-14

E. Best Pair

namespace std;#define rep(i,l,r) for(int i=(l);i<=(r);i++)#define per(i,l,r) for(int i=(l);i>=(r);i--)#define ll long long#define pii pair#define mset(s,t) memset(s,t,sizeof(t))#define mcpy(s,t) memcpy(s,t,sizeof(t))#define fir first#define pb push_back#define sec second#define sortall(x) sort((x).begin(),(x).end())inline int read () { int x = 0, f = 0; char ch = getchar(); while (!isdigit(ch)) f |= (ch=='-'),ch= getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return f?-x:x;}template void print(T x) { if (x < 0) putchar('-'), x = -x; if (x >= 10) print(x/10); putchar(x % 10 + '0');}#define int long longconst int N = 1e4 + 10;void solve() { map cnt; int n, m; cin >> n >> m; vector a(n); for (auto &tt : a) { cin >> tt; cnt[tt] ++; } vector bad(m * 2); rep(i, 1, m) { int x, y; cin>> x >> y; bad.pb({x, y}); bad.pb({y, x}); } sort(bad.begin(), bad.end()); vector> occ(n); for (auto &[num, ct] : cnt) { occ[ct].pb(num); } for (auto &t : occ) reverse(t.begin(), t.end()); int ans = 0; for (int cx = 1; cx < n; cx ++) { for (auto x : occ[cx]) { for (int cy = 1; cy <= cx; cy ++) { for (auto y : occ[cy]) { if (y != x && !binary_search(bad.begin(), bad.end(), pair{x, y})) { ans = max (ans, (cx + cy) * (x + y)); break; } } } } } cout << ans << endl;}signed main () { int t; cin >> t; while (t --) solve(); }

这题之前没思路是在想有什么简便的思想可以帮助我寻找这样的答案。实际这题就是对stl的运用,因为是找最大值,所以把所有的数反转过来我们通过枚举次数,可以让复杂度降低,如果枚举,先把次数算出来,然后枚举枚举次数, 更换枚举对象

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:PR人:特斯拉终究逃过315!
下一篇:构造题(构造
相关文章

 发表评论

暂时没有评论,来抢沙发吧~