- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int K, N, R[1001], tmp, most_popular = -1, most_popular_cnt = 0, worst_shop, worst_shop_sells = 10000000;
- cin >> K >> N;//問卷K份 商店N家
- int M[N], sum[N];//
- for (int i = 0; i < 1001; ++i)
- {
- R[i] = 0;//每個商品受歡迎指數初始值
- }
- for (int i = 0; i < K; ++i)
- {
- cin >> tmp;//受歡迎商品編號
- R[tmp]++;//個別累加受歡迎指數
- }
- for (int i = 0; i < 1001; i++)//找出最受歡迎的商品編號
- {
- if (R[i] > most_popular_cnt)
- {
- most_popular_cnt = R[i];
- most_popular = i;
- }
- }
- for (int i = 0; i < N; i++)
- {
- cin >> M[i];//每家商店的商品數量
- }
- for (int i = 0; i < N; i++)
- {
- sum[i] = 0;//
- for (int j = 0; j < M[i]; j++)
- {
- cin >> tmp;//編號i店所擺放的商品編號
- sum[i] += R[tmp];//加總i店商品的受歡迎指數
- }
- if (sum[i] <= worst_shop_sells)//找出哪家店不受歡迎指數最高
- {
- worst_shop_sells = sum[i];
- worst_shop = i + 1;
- }
- }
- cout << most_popular << " " << worst_shop << endl;
- }
- /*
- 6 3
- 56 56 47 23 47 47
- 1 1 1
- 23
- 47
- 56
- 最受歡迎的商品編號
- 商品歡迎指數最低
- 47
- 1
- */
複製代碼 |