【CODEFORCES】 A. Team Olympiad
2975 단어 Codeforces물이 더 건강해요.
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti:
ti = 1, if the i-th child is good at programming,
ti = 2, if the i-th child is good at maths,
ti = 3, if the i-th child is good at PE
Each child happens to be good at exactly one of these three subjects.
The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.
What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
Input
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn(1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
Output
In the first line output integer w — the largest possible number of teams.
Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them.
If no teams can be compiled, print the only line with value w equal to 0.
Sample test(s)
input
7
1 3 1 3 2 1 2
output
2
3 5 2
6 7 4
Sample test(s)
input
4
2 1 1 2
output
0
문제풀이: 큰물 문제...
#include
#include
#include
#include
using namespace std;
int n,x;
stack s1;
stack s2;
stack s3;
int main()
{
int ans=10000,h1=0,h2=0,h3=0;
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
scanf("%d",&x);
if (x==1) { s1.push(i); h1++; }
if (x==2) { s2.push(i); h2++; }
if (x==3) { s3.push(i); h3++; }
}
ans=min(min(h1,h2),h3);
printf("%d
",ans);
if (!ans) return 0;
while (!s1.empty() && !s2.empty() && !s3.empty())
{
printf("%d %d %d
",s1.top(),s2.top(),s3.top());
s1.pop(); s2.pop(); s3.pop();
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Codeforces 1287C Garland제목 링크:Codeforces 1287C Garland 사고방식: 우리기dp[i][j][0]와 dp[i][j][1]는 각각 i개가 홀수/짝수이고 앞의 i개 안에 j개의 짝수가 있는 상황에서 i개의 최소 복잡도.첫 번...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.