codeforces C. Two Teams Composing
题目
题意:
给你一个序列aaa,然后你可以将里面的元素进行分组,第一组的元素全部都要不同的,第二组全部都要相同的最后两组的数量要一样,问最大的数量是多少。
思路:
我们可以用数组cntcntcnt记录出现的次数,然后q1,q2q1,q2q1,q2分别记录不一样的人数和一样的人数,最后的时候肯定会出现有一个人要么在左边,要么在右边的情况,所以可以列出式子max(min(q1−1,q2),min(q1,q2−1))max(min(q1 - 1, q2), min(q1, q2 - 1))max(min(q1−1,q2),min(q1,q2−1))。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
template <class T>
inline void read(T &ret) {char c;int sgn;if (c = getchar(), c == EOF) return ;while (c != '-' && (c < '0' || c > '9')) c = getchar();sgn = (c == '-') ? -1:1;ret = (c == '-') ? 0:(c - '0');while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');ret *= sgn;return ;
}
inline void out(int x) {if (x > 9) out(x / 10);putchar(x % 10 + '0');
}
const int maxn = 2e5 + 10;
int cnt[maxn];
int main() {int t;read(t);while (t--) {memset(cnt, 0, sizeof(cnt));int n, q1 = 0, q2 = 0, x;read(n);for (int i = 0; i < n; i++) {read(x);if (cnt[x] == 0) q1++;cnt[x]++;q2 = max(q2, cnt[x]);}int zz = max(min(q1 - 1, q2), min(q1, q2 - 1));out(zz);putchar('\n');}return 0;
}
codeforces C. Two Teams Composing相关推荐
- Codeforce 1335C - Two Teams Composing 统计技能种类数量+统计同一技能最大数量
[codeforces 1335C] Two Teams Composing 统计技能种类数量+统计同一技能最大数量 https://codeforces.com/contest/1335/probl ...
- Two Teams Composing
https://codeforces.com/problemset/problem/1335/C 题意:给定 n 个学生的技能,将其中的学生分为两组,两组的学生人数应该相等,且第一组的学生技能值应互不 ...
- Codeforces Round #634 (Div. 3)ABCD
传送门 这场div3全都是模拟暴力题,第一次打到E1题,E2我tle了后面再补把,a.a 看见t神22分钟ak 文章目录 A.Candies and Two Sisters B.Construct t ...
- Codeforces Round #598 (Div. 3) E. Yet Another Division Into Teams dp + 输出方案
传送门 文章目录 题意: 思路: 题意: 给你一个长度为nnn的序列aaa,你需要将其分成若干组,每组的价值为max(ai)−min(ai)\max(a_i)-min(a_i)max(ai)−mi ...
- Educational Codeforces Round 9 B. Alice, Bob, Two Teams 前缀和
B. Alice, Bob, Two Teams 题目连接: http://www.codeforces.com/contest/632/problem/B Description Alice and ...
- 【CodeForces - 632B】Alice, Bob, Two Teams (预处理,思维,前缀和后缀和)
题干: Alice and Bob are playing a game. The game involves splitting up game pieces into two teams. The ...
- Codeforces Round #552 (Div. 3) E. Two Teams 暴力+双向链表
传送 题意:将n个人分成2个队,每次选取队伍中未被选取的最大值,然后顺便选取左边相邻的k个数(有多少拿多少) 问你最后队伍的分配情况. #include<bits/stdc++.h>usi ...
- Codeforces Round #246 (Div. 2) B. Football Kit
<传送门> http://codeforces.com/contest/432/problem/B B. Football Kit Consider a football tourna ...
- [Codeforces] Round #320 (Div.2)
1.前言 虽然这次我依旧没有参加正式比赛,但是事后还是看了看题目的...一般不怎么刷Codeforces. A.Raising Bacteria You are a lover of bacteria ...
最新文章
- 企业互联网应用高性能解决之道
- MyEclipse9.0正式版汉化
- Job Processing 工序安排
- SAP Fiori Elements - how is sap-label annotation inserted to odata request
- JulyNovel-React
- 服务器迁移虚拟化实施方案,虚拟化实施方案
- JSP页面是否需要重新编译--checkInterval
- 光芒国际——我的面试(二)
- Q89:全局光照(Global Illumination)——Path Tracing(只用于间接光照)
- C++编程语言中异常处理(try-catch-throw)介绍
- 计算机网络应用基础试题6,计算机网络应用基础试题
- php pager,fleaphp常用方法分页之Pager使用方法
- 【历史上的今天】9 月 16 日:乔布斯的归来;苹果崛起;易语言发布
- 设备树学习之(一)GPIO中断
- 个人用游戏设计框架图
- 【Unity3D】枪战游戏—弹孔设置
- Nexus默认账号密码
- top邮箱怎么登录,解决方案
- Win10怎么隐藏任务栏时间 如何看不到右下角时间
- SQL 链接 (代码)