Sicily 1006. team rankings in full Arrangement

Source: Internet
Author: User

water question: list all the questions and find the smallest rank.

# Include <iostream> # include <string> # include <memory. h> using namespace STD; string hold = "ABCDE"; string result; string a [101]; int total; void all_permutation (INT current); int calculate (); int find (char); int Mini, N; bool used [5]; int main () {While (CIN> N & N) {memset (used, false, 5 * sizeof (bool); For (INT I = 0; I <n; I ++) CIN> A [I]; Mini = calculate (); result = hold; all_permutation (0); cout <result <"Is the median ranking with value" <mini <". "<Endl;} return 0;} void all_permutation (INT current) {If (current> = 5) {Total = calculate (); If (total <mini) {mini = total; Result = hold ;}} else {for (INT I = 0; I <5; I ++) if (! Used [I]) {used [I] = true; hold [current] = I + 'a'; all_permutation (current + 1 ); used [I] = false ;}} int calculate () {int result = 0; For (INT I = 0; I <n; I ++) {for (Int J = 0; j <4; j ++) {for (int K = J + 1; k <5; k ++) {If (find (A [I] [J])> Find (A [I] [k]) Result ++ ;}} return result ;} int find (char X) {int index; For (INT I = 0; I <5; I ++) {If (hold [I] = X) {Index = I; Return Index ;}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.