Last active
December 15, 2015 09:59
-
-
Save c4rias/5242280 to your computer and use it in GitHub Desktop.
Maraton 25-03-2013
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Autor: Carlos Arias | |
Problema: Nim-B Sum V2 | |
Link: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=402&page=show_problem&problem=2875 | |
*/ | |
#include<iostream> | |
#include<string> | |
#include<cstdio> | |
#include<map> | |
#include<vector> | |
#include<algorithm> | |
#include<cmath> | |
using namespace std; | |
long long solve(int a,int b,int base){ | |
long long sum=0; | |
int ex=0,r; | |
while(a != 0 or b != 0){ | |
r = (((a%base)+(b%base))%base)*(int)pow(base,ex); | |
a /= base; | |
b /= base; | |
sum += r; | |
ex++; | |
} | |
return sum; | |
} | |
int main(){ | |
int n,ncas=0; | |
scanf("%d",&n); | |
while(n--){ | |
int a,b,base; | |
scanf("%d %d %d %d",&ncas,&base,&a,&b); | |
printf("%d %lld\n",ncas,solve(a,b,base)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Problema: Penney Game | |
Link: https://icpcarchive.ecs.baylor.edu/index.php?option=onlinejudge&page=show_problem&problem=2874 | |
*/ | |
#include<iostream> | |
#include<string> | |
#include<cstdio> | |
#include<map> | |
/* | |
No es una solucion muy elaborada pero se implementa rapido en tiempo de | |
maraton | |
*/ | |
using namespace std; | |
int main(){ | |
int T,ncon; | |
scanf("%d",&T); | |
while(T--){ | |
int TTT,TTH,THT,THH,HTT,HTH,HHT,HHH; | |
TTT=TTH=THT=THH=HTT=HTH=HHT=HHH=0; | |
string C; | |
cin>>ncon>>C; | |
for(int i=0;i<C.size()-2;i++){ | |
string tmp; | |
for(int j=0;j<3;j++) | |
tmp.push_back(C[i+j]); | |
if(tmp == "TTT") | |
TTT++; | |
else if(tmp == "TTH") | |
TTH++; | |
else if(tmp == "THT") | |
THT++; | |
else if(tmp == "THH") | |
THH++; | |
else if(tmp == "HTT") | |
HTT++; | |
else if(tmp == "HTH") | |
HTH++; | |
else if(tmp == "HHT") | |
HHT++; | |
else if(tmp == "HHH") | |
HHH++; | |
} | |
printf("%d %d %d %d %d %d %d %d %d\n",ncon,TTT,TTH,THT,THH,HTT,HTH,HHT,HHH); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Problema: Nim-B Sum | |
Link: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=402&page=show_problem&problem=2875 | |
*/ | |
#include<iostream> | |
#include<string> | |
#include<cstdio> | |
#include<map> | |
#include<vector> | |
#include<algorithm> | |
#include<cmath> | |
using namespace std; | |
/* funcion que convierte un numero decimal a una base dada | |
y me devuelve el vector r que contiene todos los digitos | |
de un numero A en una base X | |
*/ | |
vector<int> conB(int a,int base){ | |
vector<int> r; | |
while(a){ | |
r.push_back(a%base); | |
a /=base; | |
} | |
return r; | |
} | |
/*funcion que suma cada componente del numero A & B y me saca el modulo Base, | |
de una vez convierte el resultado a decimal y lo va sumando | |
por ultimo lo retorna | |
*/ | |
long long xorV(vector<int> a,vector<int> b,int base){ | |
long long sum=0; | |
int i=0,ex=0; | |
if(a.size()> b.size()){ | |
for(i=0;i<b.size();i++){ | |
sum += ((a[i]+b[i])%base)*(int)pow(base,ex); | |
ex++; | |
} | |
for(i;i<a.size();i++){ | |
sum += (a[i])*(int)pow(base,ex); | |
ex++; | |
} | |
} | |
else if(a.size()== b.size()){ | |
for(i=0;i<a.size();i++){ | |
sum += ((a[i]+b[i])%base)*(int)pow(base,ex); | |
ex++; | |
} | |
} | |
else { | |
for(i=0;i<a.size();i++){ | |
sum += ((a[i]+b[i])%base)*(int)pow(base,ex); | |
ex++; | |
} | |
for(i;i<b.size();i++){ | |
sum += (b[i])*(int)pow(base,ex); | |
ex++; | |
} | |
} | |
return sum; | |
} | |
int main(){ | |
int n,ncas=0; | |
scanf("%d",&n); | |
while(n--){ | |
int a,b,base; | |
//leemos la entrada | |
scanf("%d %d %d %d",&ncas,&base,&a,&b); | |
//almacenamos lo que nos devuelve la función de convertir un numero binario a cualquier base | |
vector<int> a1=conB(a,base); | |
vector<int> b1 = conB(b,base); | |
/*le mandamos esto a la función que nos suma cada componente de los vectores anteriores | |
y de una vez me pasael resultado a decimal otra vez. | |
e imprimimos como nos dice el archivo*/ | |
cout<<ncas<<" "<<xorV(a1,b1,base)<<endl; | |
//cout<<++ncas<<" "<<xorV(a1,b1,base)<<endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment