Translate

Views

Thursday, June 15, 2023

Solution UVA: 11286 - Conformity

 

  Last Submissions
  Problem  VerdictLangTimeBestRankSubmit Time
 | discuss11286 - Conformity AcceptedC++110.1100.00029062 mins ago

Problem: 11286
- Summary: Find the row that occurs the most and print that number of occurrences
Sample Input
3
100 101 102 103 488 (x)
100 200 300 101 102
103 102 101 488 100 (xx)
3
200 202 204 206 208 (*)
123 234 345 456 321 (**)
100 200 300 400 444 (***)
0
Sample Output
2     (x + xx) -> row 1 and row 3 have the same values so the number of occurrences is 2
3     (* + ** + ***) -> because each row appears only once, the result will be 3

Suggest:
- Use data struct (map<set<int>, int> and set<int>) to solve: 
+ What we need to do is just count the number of occurrences of the rows based on the data structure
+ Note: for example, the most occurring case is 3. We have 1 2 3 4 5 appearing 3 times, 4 5 6 7 8 also appearing 3 times. Then the result will be 6 (same as case 2 of the problem)

#include<bits/stdc++.h>
using namespace std;

int n;

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
   
    while(cin >> n && n){
       
        map<set<int>, int> popular;
        for(int i=1; i<=n; i++){
            set<int> courses;
            for(int i=1; i<=5; i++){
                int x; cin >> x;
                courses.insert(x);
            }
            popular[courses]++;    
        }
       
        int most_popular= 0;
        for(auto it=popular.begin(); it!=popular.end(); it++)
            most_popular= max(most_popular, it->second);
       
        int frosh= 0;
        for(auto it=popular.begin(); it!=popular.end(); it++)
            if (it->second == most_popular) frosh += most_popular;
       
        cout<<frosh<<"\n";          
    }
}


No comments: