Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Time Limit Exceeded!!!I've written a program to solve it but it Time Limit Exceeded!!! please help me to solve it... #include <iostream> #include <cmath> #include <vector> #include <string> using namespace std; int main () { int RESULT = 28; string ANSWER; string s ( 9 , ' ' ); for ( int i = 0 ; i < 9 ; i++ ) cin >> s[i]; vector <string> str ( 9 ); str[0] = "110110000"; str[1] = "111000000"; str[2] = "011011000"; str[3] = "100100100"; str[4] = "010111010"; str[5] = "001001001"; str[6] = "000110110"; str[7] = "000000111"; str[8] = "000011011"; for ( int i = 0 ; i < pow ( 4. , 9. ) ; i++ ) { int temp = i; int sum = 0; string ss = s; string ans; for ( int j = 0 ; temp != 0 ; j++ ) { int mod = temp % 4; sum += mod; for ( int k = 0 ; k < 9 ; k++ ) ss[k] = '0' + ( ( ( ss[k] - '0' ) + mod * ( str[j][k] - '0' ) ) % 4 ); temp /= 4; for ( int k = 0 ; k < mod ; k++ ) ans.push_back ( '0' + j + 1 ); } if ( ss == "000000000" && sum < RESULT ) { RESULT = sum; ANSWER = ans; } } for ( int i = 0 ; i < ANSWER.length() - 1 ; i++ ) cout << ANSWER[i] << " "; cout << ANSWER[ ANSWER.length()-1 ] << endl; return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator