tuket
domingo, 22 de febrero de 2015
viernes, 20 de febrero de 2015
pthreads exemple
#include <stdio.h> #include <stdlib.h> #include <pthread.h> using namespace std; void* function1(void* data) { printf( "Vine al cole: %s\n", (char*)data ); return 0; } int main() { int thread1ID, thread2ID; pthread_t thread1, thread2; char rufol[] = "rufol"; char lucky[] = "lucky"; thread1ID = pthread_create ( &thread1, // the thread 0, // attributes function1, // function to call (void*)rufol // parameter pointer for the called function ); thread2ID = pthread_create ( &thread2, // the thread 0, // attributes function1, // function to call (void*)lucky // parameter pointer for the called function ); pthread_join(thread1, 0); pthread_join(thread2, 0); }
jueves, 19 de febrero de 2015
Vec3d
#include#ifndef VEC3D #define VEC3D class Vec3d { private: float vec[3]; public: Vec3d(); Vec3d(float x, float y, float z); Vec3d(const float vec[3]); Vec3d(const Vec3d& vec); float getX()const; float getY()const; float getZ()const; void setX(float x); void setY(float y); void setZ(float z); const Vec3d& operator=(const Vec3d& vec); float getLength()const; float getSquaredLength()const; Vec3d getUnit()const; Vec3d operator+(const Vec3d& vec)const; Vec3d operator-(const Vec3d& vec)const; Vec3d operator*(float x)const; Vec3d operator/(float x)const; float operator[](unsigned int i)const; float& operator[](unsigned int i); std::string toString()const; // friends friend Vec3d operator*(float x, const Vec3d& vec); }; Vec3d operator*(float x, const Vec3d& vec); #endif
#include "vec3d.hpp" #include#include using namespace std; Vec3d::Vec3d() { vec[0] = vec[1] = vec[2] = 0; } Vec3d::Vec3d(float x, float y, float z) { vec[0] = x; vec[1] = y; vec[2] = z; } Vec3d::Vec3d(const float vec[3]) { this->vec[0] = vec[0]; this->vec[1] = vec[1]; this->vec[2] = vec[2]; } Vec3d::Vec3d(const Vec3d& vec) { this->vec[0] = vec.vec[0]; this->vec[1] = vec.vec[1]; this->vec[2] = vec.vec[2]; } float Vec3d::getX()const { return vec[0]; } float Vec3d::getY()const { return vec[1]; } float Vec3d::getZ()const { return vec[2]; } void Vec3d::setX(float x) { vec[0] = x; } void Vec3d::setY(float y) { vec[1] = y; } void Vec3d::setZ(float z) { vec[2] = z; } const Vec3d& Vec3d::operator=(const Vec3d& vec) { this->vec[0] = vec.vec[0]; this->vec[1] = vec.vec[1]; this->vec[2] = vec.vec[2]; return *this; } float Vec3d::getSquaredLength()const { return ( vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2] ); } float Vec3d::getLength()const { return sqrt ( vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2] ); } Vec3d Vec3d::getUnit()const { Vec3d res(*this); float length = getLength(); res.vec[0] /= length; res.vec[1] /= length; res.vec[2] /= length; return res; } Vec3d Vec3d::operator+(const Vec3d& vec)const { Vec3d res(*this); res.vec[0] += vec[0]; res.vec[1] += vec[1]; res.vec[2] += vec[2]; return res; } Vec3d Vec3d::operator-(const Vec3d& vec)const { Vec3d res(*this); res.vec[0] -= vec[0]; res.vec[1] -= vec[1]; res.vec[2] -= vec[2]; return res; } Vec3d Vec3d::operator*(float x)const { Vec3d res(*this); res.vec[0] *= x; res.vec[1] *= x; res.vec[2] *= x; return res; } Vec3d Vec3d::operator/(float x)const { Vec3d res(*this); res.vec[0] /= x; res.vec[1] /= x; res.vec[2] /= x; return res; } float Vec3d::operator[](unsigned int i)const { return vec[i]; } float& Vec3d::operator[](unsigned int i) { return vec[i]; } string Vec3d::toString()const { stringstream ss; ss << "(" << vec[0] << "," << vec[1] << "," << vec[2] << ")"; return ss.str(); } Vec3d operator*(float x, const Vec3d& vec) { Vec3d res(vec); res.vec[0] *= x; res.vec[1] *= x; res.vec[2] *= x; return res; }
g++ bullet physics dpk
pkg-config --cflags bullet
-I/usr/local/include/bullet -I/usr/local/include
pkg-config --libs bullet
-L/usr/local/lib -lBulletSoftBody -lBulletDynamics -lBulletCollision -lLinearMath
-I/usr/local/include/bullet -I/usr/local/include
pkg-config --libs bullet
-L/usr/local/lib -lBulletSoftBody -lBulletDynamics -lBulletCollision -lLinearMath
domingo, 17 de noviembre de 2013
Lavabit has been closed.
Lavabit was an email account provider that assured privacy to the users.
It seems that the creator of Lavabit was forced to close by an external agent. May be people is not allowed to have privacy.
Lavabit had another name before.
2013 SWERC D
One exercise about Full Metal Alchemist!
#include<iostream> #include<string> #include<vector> using namespace std; string hall(string); int main(){ int nn; cin>>nn; for(int z=0;z<nn;z++){ int n; cin>>n; string s; cin>>s; string t=""; for (int i=0;i<n;i++){ t=hall(t); } cout<< ((t.find(s)==string::npos)?"no":"yes")<<endl; } } string hall(string s){ if(s=="") return string("L"); string res="L"; char toca='R'; for(int i=0;i<s.size();i++){ res+=s[i]+string("")+toca; toca=(toca=='L'?'R':'L'); } return res; }
2013 SWERC A
#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(""); }
Suscribirse a:
Entradas (Atom)