Created
September 15, 2018 10:10
-
-
Save completejavascript/74361998f50239aea489018abc6f190a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
//freopen("input.txt","r",stdin); | |
int Testcase = 0; | |
cin >> Testcase; | |
for(int tc = 0; tc < Testcase; tc++) | |
{ | |
int n = 0; | |
cin >> n; | |
// Mảng đếm số lượng người có lượng hot i của của nam và nữ | |
int cnt_men[11], cnt_wen[11]; | |
for(int i = 0; i < 11; i++) | |
{ | |
cnt_men[i] = 0; | |
cnt_wen[i] = 0; | |
} | |
// Nhập đầu vào và đếm số người ứng với độ hot đã cho | |
// nam | |
for(int i = 0; i < n; i++) | |
{ | |
int temp = 0; | |
cin >> temp; | |
cnt_men[temp]++; | |
} | |
// nữ | |
for(int i = 0; i < n; i++) | |
{ | |
int temp = 0; | |
cin >> temp; | |
cnt_wen[temp]++; | |
} | |
// Sắp xếp độ hot cho n người nam dùng counting sort | |
int *men = new int[n]; | |
int id_men = 0; | |
for(int i = 0; i <= 10; i++) | |
for(int j = 0; j < cnt_men[i]; j++) | |
men[id_men++] = i; | |
// Sắp xếp độ hot cho n người nữ dùng counting sort | |
int *wen = new int[n]; | |
int id_wen = 0; | |
for(int i = 0; i <= 10; i++) | |
for(int j = 0; j < cnt_wen[i]; j++) | |
wen[id_wen++] = i; | |
// Tính độ hot tổng | |
int sum = 0; | |
for(int i = 0; i < n; i++) | |
sum += men[i] * wen[i]; | |
cout << sum << endl; | |
delete[] wen; | |
delete[] men; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment