zoukankan      html  css  js  c++  java
  • 【例题 7-6 UVA

    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    暴力做就好。 O(8!*26^2)

    【代码】

    /*
      	1.Shoud it use long long ?
      	2.Have you ever test several sample(at least therr) yourself?
      	3.Can you promise that the solution is right? At least,the main ideal
      	4.use the puts("") or putchar() or printf and such things?
      	5.init the used array or any value?
      	6.use error MAX_VALUE?
      	7.use scanf instead of cin/cout?
      	8.whatch out the detail input require
    */
    #include <bits/stdc++.h>
    using namespace std;
    
    const int N = 300;
    
    string s;
    bool bo[N][N],ex[N];
    int A[N],pos[N];
    vector <int> v;
    int n;
    
    int main(){
    	#ifdef LOCAL_DEFINE
    	    freopen("F:\c++source\rush_in.txt", "r", stdin);
    	#endif
    	ios::sync_with_stdio(0),cin.tie(0);
    	while (getline(cin,s)){
    	 	if (s[0]=='#') break;
    	 	memset(bo,0,sizeof bo);
    	 	memset(ex,0,sizeof ex);
    	 	int len = s.size();
    	 	for (int i = 0;i < len;i++)
    	 		if (s[i]==';')
    	 			s[i] = ' ';
    		stringstream ss(s);
    		while (ss>>s){
    			int len = s.size();
    			ex[s[0]] = true;
    			for (int i = 2;i < len;i++){
    				bo[s[0]][s[i]] = true;
    				bo[s[i]][s[0]] = true;
    				ex[s[i]] = true;
    			}
    		}
    		n = 0;
    		for (int i = 'A';i <='Z';i++)
    			if (ex[i]){
    				A[++n] = i; 	
    			}
    		v.resize(n+1);	
    		int ans = 1000;
    	  	do{
    			for (int i = 1;i <= n;i++) pos[A[i]] = i;
    			int temp = 0;
    			for (int x = 'A';x<='Z';x++)
    				for (int y = 'A';y <= 'Z';y++)
    					if (bo[x][y]==true){
    					 	temp = max(temp,abs(pos[x]-pos[y]));
    				 	}
    			if (temp < ans ){
    				for (int i = 1;i <= n;i++) v[i] = A[i];				
    				ans = temp;
    			}
    	  	}while (next_permutation(A+1,A+1+n));
    
    	  	for (int i = 1;i <= n;i++){
    	  		cout << (char)v[i]<<' ';			
    	  	}
    	  	cout <<"-> "<< ans << endl;
    	}
    	return 0;
    }
    
  • 相关阅读:
    HDU 1402 A * B Problem Plus FFT
    HDU 4609 3-idiots FFT
    Hihocoder #1527 : 快速乘法 DP
    Codeforces Round #420 (Div. 2) E. Okabe and El Psy Kongroo DP+矩阵快速幂加速
    Codeforces 8VC Venture Cup 2016
    FFT做题记录
    Hackrank Candies DP
    git submodule update --init --recursive
    慢慢长大
    protobuf
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7990905.html
Copyright © 2011-2022 走看看