题目

题意:

给你一个序列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相关推荐

  1. Codeforce 1335C - Two Teams Composing 统计技能种类数量+统计同一技能最大数量

    [codeforces 1335C] Two Teams Composing 统计技能种类数量+统计同一技能最大数量 https://codeforces.com/contest/1335/probl ...

  2. Two Teams Composing

    https://codeforces.com/problemset/problem/1335/C 题意:给定 n 个学生的技能,将其中的学生分为两组,两组的学生人数应该相等,且第一组的学生技能值应互不 ...

  3. Codeforces Round #634 (Div. 3)ABCD

    传送门 这场div3全都是模拟暴力题,第一次打到E1题,E2我tle了后面再补把,a.a 看见t神22分钟ak 文章目录 A.Candies and Two Sisters B.Construct t ...

  4. 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 ...

  5. 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 ...

  6. 【CodeForces - 632B】Alice, Bob, Two Teams (预处理,思维,前缀和后缀和)

    题干: Alice and Bob are playing a game. The game involves splitting up game pieces into two teams. The ...

  7. Codeforces Round #552 (Div. 3) E. Two Teams 暴力+双向链表

    传送 题意:将n个人分成2个队,每次选取队伍中未被选取的最大值,然后顺便选取左边相邻的k个数(有多少拿多少) 问你最后队伍的分配情况. #include<bits/stdc++.h>usi ...

  8. Codeforces Round #246 (Div. 2) B. Football Kit

    <传送门> http://codeforces.com/contest/432/problem/B B. Football Kit   Consider a football tourna ...

  9. [Codeforces] Round #320 (Div.2)

    1.前言 虽然这次我依旧没有参加正式比赛,但是事后还是看了看题目的...一般不怎么刷Codeforces. A.Raising Bacteria You are a lover of bacteria ...

最新文章

  1. 企业互联网应用高性能解决之道
  2. MyEclipse9.0正式版汉化
  3. Job Processing 工序安排
  4. SAP Fiori Elements - how is sap-label annotation inserted to odata request
  5. JulyNovel-React
  6. 服务器迁移虚拟化实施方案,虚拟化实施方案
  7. JSP页面是否需要重新编译--checkInterval
  8. 光芒国际——我的面试(二)
  9. Q89:全局光照(Global Illumination)——Path Tracing(只用于间接光照)
  10. C++编程语言中异常处理(try-catch-throw)介绍
  11. 计算机网络应用基础试题6,计算机网络应用基础试题
  12. php pager,fleaphp常用方法分页之Pager使用方法
  13. 【历史上的今天】9 月 16 日:乔布斯的归来;苹果崛起;易语言发布
  14. 设备树学习之(一)GPIO中断
  15. 个人用游戏设计框架图
  16. 【Unity3D】枪战游戏—弹孔设置
  17. Nexus默认账号密码
  18. top邮箱怎么登录,解决方案
  19. Win10怎么隐藏任务栏时间 如何看不到右下角时间
  20. SQL 链接 (代码)

热门文章

  1. matlab直角坐标方程,MATLAB 笛卡尔坐标系制图
  2. 医疗器械行业按下“加速键”,华瑭医疗的总代生意却并不好做
  3. C语言中Const指针变量(常指针)
  4. js 判断字符串是否全是数字
  5. 四、软件概要设计说明书-模板
  6. 数据处理之标准化/归一化方法
  7. 九十年代 计算机课,九十年代的计算机体系结构
  8. 学习USART自闭实录(stm32F411RE)Stm32cubemx
  9. [生存志] 第93节 孟子齐魏立说
  10. xmmi - 晨星半导体公司MSTAR平台