zoukankan      html  css  js  c++  java
  • 排列组合

    hdu  题目:http://acm.split.hdu.edu.cn/showproblem.php?pid=1015

    #include<iostream>
    #include<string>
    #include<cmath>
    using namespace std;
    void quickSort(int start,int end,string &s){   //快排 
    	if(start<end){
    		int l=start,r=end;
    		char ch=s[start];
    
    		while(l<r){
    			while(s[r]>ch&&l<r) r--;
    			if(l<r){
    				s[l++]=s[r];
    				}
    			while(s[l]<ch&&l<r) l++;
    			if(l<r){
    				s[r--]=s[l];
    			}
    		}
    
    		s[l]=ch;
    		quickSort(start,l-1,s);
    		quickSort(l+1,end,s);
    	}
    }
    int main(){
    	string s;
    	int target;
    
    	while(cin>>target>>s){
    		if(target==0&&s=="END"){	
    			break;
    		}
    		else{
    			quickSort(0,s.length()-1,s);
    		
    			char temp;
    			string s1;
    
    			for(int a=0;a<s.length();a++){    //排列组合 
    				temp=s[0];
    				s[0]=s[a];
    				s[a]=temp;
    
    				for(int b=1;b<s.length();b++){
    					temp=s[1];
    					s[1]=s[b];
    					s[b]=temp;
    
    					for(int c=2;c<s.length();c++){
    						temp=s[2];
    						s[2]=s[c];
    						s[c]=temp;
    
    						for(int d=3;d<s.length();d++){
    							temp=s[3];
    							s[3]=s[d];
    							s[d]=temp;
    
    							for(int e=4;e<s.length();e++){
    								 if(((int)s[0]-64) - (int)pow((int)s[1]-64,2) + (int)pow((int)s[2]-64,3) - (int)pow((int)s[3]-64,4) + (int)pow((int)s[e]-64,5)==target){
    								 	s1=s.substr(0,4)+s[e];
    
    
    								 }
    							}
    							temp=s[3];
    							s[3]=s[d];
    							s[d]=temp;
    						}
    						temp=s[2];
    						s[2]=s[c];
    						s[c]=temp;
    					}
    					temp=s[1];
    					s[1]=s[b];
    					s[b]=temp;
    				}
    
    			}
    		if(s1==""){
    			cout<<"no solution"<<endl; 
    		}
            else cout<<s1<<endl;
    		}
    
    	}
    }
    

      

  • 相关阅读:
    Python文件相关的操作
    Python运算符
    字符串方法
    Python列表的增删改查和元祖
    压测
    jmeter相关使用
    charles的使用
    接口测试
    编程珠玑之关键字(1)--《c语言深度剖析》整理(转)
    循环单链表操作(转)
  • 原文地址:https://www.cnblogs.com/z-bear/p/7689561.html
Copyright © 2011-2022 走看看