[网易笔试]Difficult Player Grouping
2015-09-23 16:57
627 查看
题目链接:http://hihocoder.com/contest/ntest2015septdev/problem/4
The 3v3 mode is a new PvP mode in Battle to the West. In this mode, a player needs to choose a hero to play first. And then all online players are randomly grouped in sixes. Each group has exactly 6 players and corresponds to a new game. In the new game, the 6 players are further randomly divided into 2 opposing teams, each of which has 3 players.
To make the gameplay fair and fun, no two players choosing the same hero should appear in a single team. As a developer of this game, you may design the way of grouping all online players, and the way of dividing players into teams. Then a problem arises. What is the maximum number of games (or groups) that could possibly be generated from online players satisfying all above constraints?
To make the problem clear, we assume that there are H distinct heroes, named from hero1 to heroH. A player must choose exactly one from the H heroes. The number of players choosing heroi is ai. Given H and ai, you need to write a program to find the maximum number of games that could be grouped by these players.
输入
The input contains several test cases.
The first line contains T(T ≤ 100), the number of the test cases.
The following T lines each start with an integer H(1 ≤ H ≤ 1000), which is the number of possible choices for hero. Then H integers (a1 … aH) follow, where ai (ai > 0) is the number of players who choose the i-th hero. It is guaranteed that the sum of ai will no more than 200000.
输出
For each test case, please output the maximum number of games that could be grouped by the players.
提示
For the 1st test case, there are 6 online players choosing 6 different heroes. So 1 game can be formed.
For the 2nd test case, we can divide the 6 heroes into 2 teams: (1, 2, 3) and (1, 2, 3). So no 2 heroes appear in a single team, and 1 game can be formed.
There are 7 players in the 3rd test case, but a game has exactly 6 players. The extra player is in no team.
For the 4th test case, there are 3 players choosing the hero3. So no game could be formed.
样例输入
4
6 1 1 1 1 1 1
3 2 2 2
3 2 2 3
3 1 2 3
样例输出
1
1
1
0
The 3v3 mode is a new PvP mode in Battle to the West. In this mode, a player needs to choose a hero to play first. And then all online players are randomly grouped in sixes. Each group has exactly 6 players and corresponds to a new game. In the new game, the 6 players are further randomly divided into 2 opposing teams, each of which has 3 players.
To make the gameplay fair and fun, no two players choosing the same hero should appear in a single team. As a developer of this game, you may design the way of grouping all online players, and the way of dividing players into teams. Then a problem arises. What is the maximum number of games (or groups) that could possibly be generated from online players satisfying all above constraints?
To make the problem clear, we assume that there are H distinct heroes, named from hero1 to heroH. A player must choose exactly one from the H heroes. The number of players choosing heroi is ai. Given H and ai, you need to write a program to find the maximum number of games that could be grouped by these players.
输入
The input contains several test cases.
The first line contains T(T ≤ 100), the number of the test cases.
The following T lines each start with an integer H(1 ≤ H ≤ 1000), which is the number of possible choices for hero. Then H integers (a1 … aH) follow, where ai (ai > 0) is the number of players who choose the i-th hero. It is guaranteed that the sum of ai will no more than 200000.
输出
For each test case, please output the maximum number of games that could be grouped by the players.
提示
For the 1st test case, there are 6 online players choosing 6 different heroes. So 1 game can be formed.
For the 2nd test case, we can divide the 6 heroes into 2 teams: (1, 2, 3) and (1, 2, 3). So no 2 heroes appear in a single team, and 1 game can be formed.
There are 7 players in the 3rd test case, but a game has exactly 6 players. The extra player is in no team.
For the 4th test case, there are 3 players choosing the hero3. So no game could be formed.
样例输入
4
6 1 1 1 1 1 1
3 2 2 2
3 2 2 3
3 1 2 3
样例输出
1
1
1
0
#include <iostream> #include <vector> #include <string> #include <iomanip> using namespace std; bool check(int *a, int len) { int n = 0; int i = 0; while (i < len && n < 3) { while (i < len && a[i] <= 0) ++i; if (i >= len) return false; a[i] -= 1; ++n; ++i; } if (n == 3) return true; else return false; } int main() { int n; cin >> n; while (n > 0) { int m; cin >> m; int *a = new int[m]; for (int i = 0; i < m; ++i) { cin >> a[i]; } int i = 0; while (true) { if (check(a, m) && check(a, m)) i++; else break; } cout << i << endl; delete a; --n; } return 0; }
相关文章推荐
- 查询域名对应的IP
- mysql命令集锦
- 去掉导航栏阴影
- C# --2007Access链接字符串
- SharePoint自动化系列——通过PowerShell创建SharePoint Lists
- 直接拿来用的15个jQuery代码片段
- 文章标题
- 杰出人士的七种共性之6-独自精彩
- html5 video
- Qt后台窗口
- Android Studio快捷键设置
- Git之版本控制工具进阶
- CSS鼠标悬停图片加边框效果,不位移的方法
- Spring种常见异常解决方法
- crontab not running
- easyui form 方式提交数据
- Centos6.4下双网卡bond配置
- OPENGL在VC中的配置及出现“无法定位程序输入点_glutInitWithExit于动态链接库glut32.dll上”的解决方案
- Android视频分享-初学者你必须知道的那些事儿
- PAT(甲级)1016