zoukankan      html  css  js  c++  java
  • poj 2038 Team Rankings 枚举排列

    //poj 2038
    //sep9
    #include <iostream>
    #include <algorithm>
    using namespace std;
    char s[128][8];
    int count(char s1[],char s2[])
    {
    	int cnt=0;
    	for(int i=0;i<5;++i)
    		for(int j=i+1;j<5;++j){
    			int k;
    			for(k=0;k<5;++k)
    				if(s1[i]==s2[k])
    					break;
    			for(int l=0;l<k;++l)
    				if(s1[j]==s2[l])
    					++cnt;
    		}	
    	return cnt;
    }
    int main()
    {
    	int n;
    	while(scanf("%d",&n)==1&&n){
    		for(int i=0;i<n;++i)
    			scanf("%s",s[i]);
    		int ans=INT_MAX;
    		char ans_s[8];
    		char tmp[8]="ABCDE";
    		do{
    			int cnt=0;
    			for(int i=0;i<n;++i)
    				cnt+=count(tmp,s[i]);
    			if(cnt<ans){
    				ans=cnt;
    				strcpy(ans_s,tmp);
    			}	
    		}while(next_permutation(tmp,tmp+5));
    		printf("%s is the median ranking with value %d.
    ",ans_s,ans);
    	}	
    	return 0;
    } 

  • 相关阅读:
    富文本
    管理员状态
    分页
    tp。3.2中的模板基础
    get和post之间的区别
    RegExp
    获取各种类型的节点
    节点的层次关系
    创建元素节点
    JavaScript 正则
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/5111877.html
Copyright © 2011-2022 走看看