#include<iostream> #include<iostream> #include<string> #include<vector> using namespace std; int nr; string rul[100][3]; class C{ public: int i; vector<string> s; vector<float> f; bool max(){return i==s.size();} string gets(){return s[i];} float getf(){return f[i];} C():i(0){} }; string apply(int r, vector<string> c); int main(){ cin>>nr; for(int i=0; i<nr; i++){ cin>>rul[i][0]; cin>>rul[i][1]; cin>>rul[i][2]; } int rep; cin>>rep; for(int rrr=0; rrr<rep; rrr++){ int nc; cin>>nc; C* col= new C[nc]; string aux; float fl; for(int i=0; i<nc; i++){ cin>>aux; while(aux != string("END")){ col[i].s.push_back(aux); cin>>fl; col[i].f.push_back(fl); cin>>aux; } } bool end=false; string out="GAMEOVER"; float max=0; string mcol="GAMEOVER"; while(!end){ vector<string> in; for(int i=0;i<nc;i++){ in.push_back(col[i].gets() ); } out="GAMEOVER"; for(int i=0; i<nr; i++){ string res=apply(i, in); if(res!=""){out=res; break;} } float p=1; for(int i=0;i<nc;i++) p*=col[i].getf(); if(p>max && out!="GAMEOVER") {max=p; mcol=out;} col[nc-1].i++; for(int i=nc-1; i>=0; i--){ if(col[i].max()){ if(i==0){end=true; break;} else {col[i].i=0; col[i-1].i++;} } else break; } } cout<<mcol<<endl; } } string apply(int r, vector<string> c){ int cs= c.size(); if(cs==1) return c[0]; for(int i=0; i<cs; i++) for(int j=i+1; j<cs; j++){ if((rul[r][0]==c[i] && rul[r][1]==c[j]) || (rul[r][0]==c[j] && rul[r][1]==c[i])){ vector<string> aux=c; aux.erase(aux.begin()+j); aux.erase(aux.begin()+i); aux.push_back(rul[r][2]); for(int k=0; k<nr; k++){ string res=apply(k,aux); if(res != "") return res; } } } return string(""); }
domingo, 17 de noviembre de 2013
2013 SWERC A
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario