int main() { char s[11]; long n; int i,j; while(scanf("%s",s)!=EOF) { for(i=0;s[i+1];i++) { if(s[i]>=s[i+1]) break; } if(s[i+1]) printf("0\n"); else { i=strlen(s); for(--i,n=0;i;i--) n+=com(26,i); for(i=0;s[i];i++) { if(i==0)j='a'; else j=s[i-1]+1; for(;j<s[i];j++) { n+=com('z'-j,strlen(s)-i-1); } } printf("%ld\n",n+1); } } return 0; }
int main(int argc, char **argv) { int server_socket, client_socket, forward_socket; struct sockaddr_in server_address, forward_address; struct hostent * forward; int server_port, forward_port; pid_t up, down; signal(SIGCHLD, SIG_IGN); if(argc < 4) {fprintf(stderr,"Not enough arguments\n"); exit(1);} server_socket = socket(AF_INET, SOCK_STREAM, 0); if(server_socket == -1) DIE("socket"); bzero((char *) &server_address, sizeof(server_address)); server_port = atoi(argv[1]); server_address.sin_family = AF_INET; server_address.sin_addr.s_addr = INADDR_ANY; server_address.sin_port = htons(server_port); if(bind(server_socket, (struct sockaddr *)&server_address, sizeof(server_address)) == -1) DIE("bind"); if(listen(server_socket,40) == -1) DIE("listen"); forward_port = atoi(argv[3]); forward = gethostbyname(argv[2]); if(forward == NULL) DIE("gethostbyname"); bzero((char *)&forward_address, sizeof(forward_address)); forward_address.sin_family = AF_INET; bcopy((char *)forward->h_addr, (char *)&forward_address.sin_addr.s_addr, forward->h_length); forward_address.sin_port = htons(forward_port); while(1) { client_socket = accept(server_socket, NULL, NULL); if(client_socket == -1) DIE("accept"); up = fork(); if(up == -1) DIE("fork"); if(up == 0) { forward_socket = socket(AF_INET, SOCK_STREAM, 0); if(forward_socket == -1) DIE("socket"); if(connect(forward_socket, (struct sockaddr *)&forward_address, sizeof(forward_address)) == -1) DIE("connect"); down = fork(); if(down == -1) DIE("fork"); if(down == 0) com(forward_socket, client_socket); else com(client_socket, forward_socket); exit(1); } close(client_socket); } return 0; }
void dgBody::ApplyImpulsesAtPoint (dgInt32 count, dgInt32 strideInBytes, const dgFloat32* const impulseArray, const dgFloat32* const pointArray) { dgInt32 stride = strideInBytes / sizeof (dgFloat32); dgMatrix inertia (CalculateInertiaMatrix()); dgVector impulse (m_veloc.Scale3 (m_mass.m_w)); dgVector angularImpulse (inertia.RotateVector (m_omega)); dgVector com (m_globalCentreOfMass); for (dgInt32 i = 0; i < count; i ++) { dgInt32 index = i * stride; dgVector r (pointArray[index], pointArray[index + 1], pointArray[index + 2], dgFloat32 (0.0f)); dgVector L (impulseArray[index], impulseArray[index + 1], impulseArray[index + 2], dgFloat32 (0.0f)); dgVector Q ((r - com) * L); impulse += L; angularImpulse += Q; } dgMatrix invInertia (CalculateInvInertiaMatrix()); m_veloc = impulse.Scale3(m_invMass.m_w); m_omega = invInertia.RotateVector(angularImpulse); m_sleeping = false; m_equilibrium = false; Unfreeze (); }
void div(int a[],int b[],int ans[]) { int i,j,k; int vvv[28][35]={0}; int chengji[35]={0}; int aans[35]={0}; for(i=1;i<28;i++) vvv[i][i]=1; for(i=1;i<28;i++) { for(;;) { add(aans,vvv[i],aans); for(j=0;j<30;j++) chengji[j]=0; mul(aans,b,chengji); // cout<<i<<" aans: ";coutt(aans);cout<<endl; // cout<<"chengji: ";coutt(chengji);cout<<endl; if(!com(a,chengji)) { for(k=0;k<30;k++) ans[k]=aans[k]; } else { sub(aans,vvv[i],aans); break; } } } }
int main() { int j,t,sc[11],i,k,co,cho,temp; int ans; scanf("%d",&t); while(t--) { for(i=0;i<11;i++) scanf("%d",&sc[i]); for(i=1;i<11;i++) { temp=sc[i]; j=i-1; while((temp<sc[j])&&(j>=0)) { sc[j+1]=sc[j]; j=j-1; } sc[j+1]=temp; } scanf("%d",&k); co=0; for(i=0;i<11;i++) if(sc[i]==sc[11-k]) co++; i=11-k; cho=0; while(i<11&&sc[i]==sc[11-k]) {cho++;i++;} printf("%ld\n",com(co,cho)); } return 0; }
void KVINDRAOnlineDataAnalyser::HandleCommands(TString& ordre, TSocket* theSocket) { // Gestion des ordres // Returns kTRUE if command was understood & executed // Returns kFALSE if command unknown // // STOP will stop the analysis (calls EndRun() and EndAnalysis()) // CLEAR RAZ de tous les spectres // // DUMP=yes start dumping fired data parameters // DUMP=no stop dumping fired data parameters // // SAVE=toto.root will save all histograms in '${ANALYSIS_RESULTS}/toto.root' (does not stop analysis) // SAVE=/home/toto.root will save all histograms in '/home/toto.root' (does not stop analysis) // SAVE will save all histograms in '${ANALYSIS_RESULTS}/[class name]_Run[run number]_[date].root' (does not stop analysis) KVString com(ordre.Data()); com.Begin("="); ordre = com.Next(); ordre.ToUpper(); if (ordre == "STOP") { // arrete l'analyse, en appelant EndRun() et EndAnalysis() fGoEventLoop = kFALSE; theSocket->Send("ok"); return; } else if (ordre == "SAVE") { TString tmp_fil = com.Next(); TString fil; bool send_name = kFALSE; if (tmp_fil.Contains("/")) fil = tmp_fil; else if (tmp_fil == "") { TDatime save_time; save_time.Set(); TString date = save_time.AsString(); date.ReplaceAll(" ", "_"); fil = Form("${ANALYSIS_RESULTS}/%s_Run%d_%s.root", GetName(), GetRunNumber(), date.Data()); send_name = kTRUE; } else fil = Form("${ANALYSIS_RESULTS}/%s", tmp_fil.Data()); SaveSpectra(fil.Data()); if (send_name) theSocket->Send(fil.Data()); else theSocket->Send("ok"); return; } else if (ordre == "CLEAR") { ClearAllHistos(); theSocket->Send("ok"); return; } else if (ordre == "DUMP") { TString tmp_fil = com.Next(); tmp_fil.ToLower(); if (tmp_fil == "yes")fDumpEvents = kTRUE; else if (tmp_fil == "no")fDumpEvents = kFALSE; else { theSocket->Send("unknown command"); return; } theSocket->Send("ok"); return; } theSocket->Send("unknown command"); }
int com(int n, int r) { if(r==0 || r==1) return n; return ((n-r+1)*com(n,r-1)/r); }
/* * prepares the communication maps for remote elements * should be called immediately after load balancing, * before any work transfer. * */ void NonlocalMaterialWTP :: init(Domain *domain) { int ie, gie, nelem = domain->giveNumberOfElements(); EngngModel *emodel = domain->giveEngngModel(); Element *elem; int nproc = emodel->giveNumberOfProcesses(); int myrank = emodel->giveRank(); CommunicatorBuff cb(nproc, CBT_dynamic); Communicator com(emodel, &cb, myrank, nproc, CommMode_Dynamic); this->nonlocElementDependencyMap.clear(); // build nonlocal element dependency array for each element for ( ie = 1; ie <= nelem; ie++ ) { elem = domain->giveElement(ie); if ( ( elem->giveParallelMode() == Element_local ) ) { gie = elem->giveGlobalNumber(); this->giveElementNonlocalDepArry(nonlocElementDependencyMap [ gie ], domain, ie); } } /* send and receive nonlocElementDependencyArry of migrating elements to remote partition */ com.packAllData(this, domain, & NonlocalMaterialWTP :: packMigratingElementDependencies); com.initExchange(MIGRATE_NONLOCALDEP_TAG); com.unpackAllData(this, domain, & NonlocalMaterialWTP :: unpackMigratingElementDependencies); com.finishExchange(); }
void RenderCenterOfMass (NewtonWorld* const world) { glDisable (GL_LIGHTING); glDisable(GL_TEXTURE_2D); glColor3f(0.0f, 0.0f, 1.0f); glBegin(GL_LINES); for (NewtonBody* body = NewtonWorldGetFirstBody(world); body; body = NewtonWorldGetNextBody(world, body)) { dMatrix matrix; dVector com(0.0f); NewtonBodyGetCentreOfMass (body, &com[0]); NewtonBodyGetMatrix (body, &matrix[0][0]); dVector o (matrix.TransformVector (com)); dVector x (o + matrix.RotateVector (dVector (1.0f, 0.0f, 0.0f, 0.0f))); glColor3f (1.0f, 0.0f, 0.0f); glVertex3f (o.m_x, o.m_y, o.m_z); glVertex3f (x.m_x, x.m_y, x.m_z); dVector y (o + matrix.RotateVector (dVector (0.0f, 1.0f, 0.0f, 0.0f))); glColor3f (0.0f, 1.0f, 0.0f); glVertex3f (o.m_x, o.m_y, o.m_z); glVertex3f (y.m_x, y.m_y, y.m_z); dVector z (o + matrix.RotateVector (dVector (0.0f, 0.0f, 1.0f, 0.0f))); glColor3f (0.0f, 0.0f, 1.0f); glVertex3f (o.m_x, o.m_y, o.m_z); glVertex3f (z.m_x, z.m_y, z.m_z); } glEnd(); }
void momentofinertiamatrix(int type, double *MofImatrix) { int i,j,count; double p1[3],massi; std::vector<double> com (3); count=0; updatePartCfg(WITHOUT_BONDS); for(i=0;i<9;i++) MofImatrix[i]=0.; com = centerofmass(type); for (j=0; j<n_part; j++) { if (type == partCfg[j].p.type) { count ++; for (i=0; i<3; i++) { p1[i] = partCfg[j].r.p[i] - com[i]; } massi= (partCfg[j]).p.mass; MofImatrix[0] += massi * (p1[1] * p1[1] + p1[2] * p1[2]) ; MofImatrix[4] += massi * (p1[0] * p1[0] + p1[2] * p1[2]); MofImatrix[8] += massi * (p1[0] * p1[0] + p1[1] * p1[1]); MofImatrix[1] -= massi * (p1[0] * p1[1]); MofImatrix[2] -= massi * (p1[0] * p1[2]); MofImatrix[5] -= massi * (p1[1] * p1[2]); } } /* use symmetry */ MofImatrix[3] = MofImatrix[1]; MofImatrix[6] = MofImatrix[2]; MofImatrix[7] = MofImatrix[5]; return; }
void sub(int a[],int b[],int ans[]) { int jinwei=0; int i,j,k; if(com(a,b)) { ans[35]=1; sub(b,a,ans); return ; } for(i=29;i>=0;i--) { ans[i]=jinwei+a[i]; if(ans[i]<b[i]) { ans[i]+=10; ans[i]-=b[i]; jinwei=-1; } else { ans[i]-=b[i]; jinwei=0; } } }
int main(){ char buf[1024]; while(scanf("%s",buf) != EOF){ printf("%d\n",com(buf)); } return 0; }
const arma::vec& CylindricalBirefringentMaterial::centerOfMass() { com.set_size(3); com.fill(0.0); double mass = 0.0; for ( unsigned int z=0;z<Nz();z++ ) for ( unsigned int y=0;y<Ny();y++ ) for ( unsigned int x=0;x<Nx();x++ ) { com(0) += x*get(x,y,z); com(1) += y*get(x,y,z); com(2) += z*get(x,y,z); mass += get(x,y,z); } com /= mass; return com; }
Vector3d Skeleton::getWorldCOM() { assert(mMass != 0); Vector3d com(0, 0, 0); const int nNodes = getNumNodes(); for(int i = 0; i < nNodes; i++) { BodyNode* node = getNode(i); com += (node->getMass() * node->getWorldCOM()); } return com / mMass; }
vector<vector<int> > combine(int n, int k) { // Start typing your C/C++ solution below // DO NOT write int main() function vector<vector<int> > ret; if(n < k || n <= 0 || k <= 0) return ret; vector<int> com(k); combine(n, k, 0, com, ret); return ret; }
void loop() { float result; int key=resist(); if(key==15) { //LCM CLEAR wlcmd_4('c',0x01); _delay(1600); //student num student_num(); //parameter reset aa=0;bb=0;_status0=0; lcm_num[0]=0; lcm_num[1]=0; lcm_num[2]=0; lcm_num[3]=0; lcm_num[4]=0; lcm_num[5]=0; lcm_num[6]=0; return; } if((key>=0)&&(key<=9)&&(_status0!=4)) { wlcmd_4('d',key); if(_status0==0) { aa=aa*10+key; } if(_status0==2) { bb=bb*10+key; } return; } if((key>=10)&&(key<=13)&&(_status0!=4)) { if(_status0==0) { wlcmd_4('d',key); operand=key; _status0=2; return; } } if((key==14)&&(_status0!=4)) { wlcmd_4('d',key); result=com(aa,bb,operand); divide(result); _status0=4; return; } return; }
tetrahedra (point p1, point p2, point p3, point p4, bool v = false) : p {p1, p2, p3, p4} { label = p1.l; totalPoints = 0; wrongPoints = 0; // create triangles triangle t1(p1, p2, p3); triangle t2(p2, p1, p4); triangle t3(p3, p2, p4); triangle t4(p1, p3, p4); t1.getPlaneEquationCoefficients(a1, b1,c1,d1); t2.getPlaneEquationCoefficients(a2, b2,c2,d2); t3.getPlaneEquationCoefficients(a3, b3,c3,d3); t4.getPlaneEquationCoefficients(a4, b4,c4,d4); calculateSideLength(); if(v) { std::ofstream fpoints("points.dat"); fpoints << p1.x << " " << p1.y << " " << p1.z << std::endl; fpoints << p2.x << " " << p2.y << " " << p2.z << std::endl; fpoints << p3.x << " " << p3.y << " " << p3.z << std::endl; fpoints << p4.x << " " << p4.y << " " << p4.z << std::endl; fpoints.close(); } centerX = (p1.x + p2.x + p3.x + p4.x)/4.0; centerY = (p1.y + p2.y + p3.y + p4.y)/4.0; centerZ = (p1.z + p2.z + p3.z + p4.z)/4.0; if(v) { std::ofstream fnormals("normals.dat"); fnormals << centerX << " " << centerY << " " << centerZ << std::endl; fnormals << centerX - a1 << " " << centerY - b1 << " " << centerZ - c1 << " " << d1 << std::endl << std::endl<< std::endl; fnormals << centerX << " " << centerY << " " << centerZ << std::endl; fnormals << centerX - a2 << " " << centerY - b2 << " " << centerZ - c2 << " " << d2 << std::endl << std::endl<< std::endl; fnormals << centerX << " " << centerY << " " << centerZ << std::endl; fnormals << centerX - a3 << " " << centerY - b3 << " " << centerZ - c3 << " " << d3 << std::endl << std::endl<< std::endl; fnormals << centerX << " " << centerY << " " << centerZ << std::endl; fnormals << centerX - a4 << " " << centerY - b4 << " " << centerZ - c4 << " " << d4 << std::endl << std::endl<< std::endl; fnormals.close(); } point com(centerX, centerY, centerZ +1 , 1); if (!checkPointInside(com)) std::cerr << "ERROR: Center of Mass not inside Tetrahedra!" << std::endl; }
// ----------------------------------------------------------------------------- // Get the current COM location of the suspension subsystem. // ----------------------------------------------------------------------------- ChVector<> ChDoubleWishboneReduced::GetCOMPos() const { ChVector<> com(0, 0, 0); com += getSpindleMass() * m_spindle[LEFT]->GetPos(); com += getSpindleMass() * m_spindle[RIGHT]->GetPos(); com += getUprightMass() * m_upright[LEFT]->GetPos(); com += getUprightMass() * m_upright[RIGHT]->GetPos(); return com / GetMass(); }
//@ Main Function int main() { fac[0] = 1; rep(i, 1, maxn) fac[i] = fac[i - 1] * i % mod; inv[maxn - 1] = csl::inv(fac[maxn - 1], (ll)mod); per(i, 1, maxn) inv[i - 1] = inv[i] * i % mod; std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int _, __ = 1; for(; cin >> n >> s; --_, ++__) { //std::cout << "Case #" << __ <<": "; int l = n >> 1, r = n >> 1; ll ans = 0; if(n & 1) ans = 0; else if(!valid(s, l, r)) ans = 0; else if(!l) ans = 1; else ans = (com(l + r, l) - com(l + r, l - 1) + mod) % mod; cout << ans << endl; } return 0; }
b2Vec2 composite_body::get_com_position() const { b2Vec2 com(0.0f, 0.0f); float sum_mass = 0.0f; for(b2Body const* b : m_bodies) { float mass = b->GetMass(); com += mass * b->GetPosition(); sum_mass += mass; } return (1.0f / sum_mass) * com; }
int main(){ cmnLogger::SetMask( CMN_LOG_ALLOW_ALL ); cmnLogger::SetMaskFunction( CMN_LOG_ALLOW_ALL ); cmnLogger::SetMaskDefaultLog( CMN_LOG_ALLOW_ALL ); // Create the world osaODEWorld* world = new osaODEWorld( 0.001 ); // Create a camera int x = 0, y = 0; int width = 640, height = 480; double Znear = 0.01, Zfar = 10.0; osg::ref_ptr<osaOSGMono> camera; camera = new osaOSGMono( world, x, y, width, height, 55, ((double)width)/((double)height), Znear, Zfar ); camera->Initialize(); // Create objects cmnPath path; path.AddRelativeToCisstShare("/models"); path.AddRelativeToCisstShare("/models/hubble"); // Create a rigid body. Make up some mass + com + moit double mass = 1.0; vctFixedSizeVector<double,3> com( 0.0 ); vctFixedSizeMatrix<double,3,3> moit = vctFixedSizeMatrix<double,3,3>::Eye(); vctFixedSizeVector<double,3> u( 0.780004, 0.620257, 0.082920 ); u.NormalizedSelf(); vctFrame4x4<double> Rtwh( vctAxisAngleRotation3<double>( u, 0.7391 ), vctFixedSizeVector<double,3>( 0.0, 0.0, 1.0 ) ); osg::ref_ptr<osaODEBody> hubble; hubble = new osaODEBody( path.Find("hst.3ds"), world, Rtwh, mass, com, moit ); // Create a static body. This body has no mass and cannot be moved osg::ref_ptr<osaODEBody> background; background = new osaODEBody( path.Find("background.3ds"), world, vctFrm3() ); std::cout << "ESC to quit" << std::endl; while( !camera->done() ){ world->Step(); camera->frame(); } return 0; }
TEST(linear_mixer, destruct_running_mixer) { shared_ptr<linear_communication_stub> com(new linear_communication_stub); jubatus::util::concurrent::rw_mutex mutex; linear_mixer m(com, mutex, 1, 1, 1); my_string_driver s; m.set_driver(&s); m.start(); // destruct without calling m.stop() }
TEST(linear_mixer, mix_order) { shared_ptr<linear_communication_stub> com(new linear_communication_stub); linear_mixer m(com, 1, 1); mixable_string s; m.register_mixable(&s); m.mix(); vector<string> mixed = com->get_mixed(); ASSERT_EQ(1u, mixed.size()); EXPECT_EQ("(4+(3+(2+1)))", mixed[0]); }
__int64 com(int m,int n){ if(str[m][n]>=0)return str[m][n]; if(m==0){ return str[m][n]=n>used[m]?0:1; } str[m][n]=0; int l=n>used[m]?used[m]:n; for(int mm=0;mm<=l;mm++){ str[m][n]+=com(m-1,n-mm); } return str[m][n]; }
AglVector3 CompoundBody::GetCenterOfMass() { AglVector3 com(0, 0, 0); float m = 0; for (unsigned int i = 0; i < mChildren.size(); i++) { com += mChildren[i]->GetLocalCenterOfMass() * mChildren[i]->GetLocalMass(); m += mChildren[i]->GetLocalMass(); } com /= m; return com; }
void com(int pos){ if(record_.size() > k_) return ; if(record_.size() == k_){ res_.push_back(record_); }else{ for(int i = pos; i <= n_; ++i){ record_.push_back(i); com(i + 1); record_.pop_back(); } } }
bool SocketManager::Init() { m_myName = "\0"; m_team = 0; ZeroMemory(m_user, sizeof(UserData)* PLAYER_MAX); ZeroMemory(m_player, sizeof(PlayerData)* PLAYER_MAX); ZeroMemory(m_layer, sizeof(LayerData)* PLAYER_MAX);// 全員分のレイヤー初期化 10*6人 enum { NO_LAYER = -1 }; for (int p = 0; p < PLAYER_MAX; p++) { for (int la = 0; la < LAYER_MAX; la++) { m_layer[p].layerdata[la].kind = NO_LAYER;// NO_DATA 種類だけ-1に } } BYTE com(NEW_USER); m_pClient->Send((char*)&com, sizeof(BYTE)); /*ID取得*/ if (m_pClient->Receive(&m_myID, sizeof(int)) <= 0) { closesocket(m_pClient->m_sock); m_pClient->m_sock = INVALID_SOCKET; return false; } // ※追加 /* セーブしたレイヤーの読み込み */ std::ifstream in("DATA/makePoster/text/Layer.txt"); // バッファに読み込む if (in)//そのファイルがあるなら! { for (int i = 0; i < LAYER_MAX; i++) { in >> m_layer[m_myID].layerdata[i].kind; in >> m_layer[m_myID].layerdata[i].num; in >> m_layer[m_myID].layerdata[i].x; in >> m_layer[m_myID].layerdata[i].y; in >> m_layer[m_myID].layerdata[i].size; in >> m_layer[m_myID].layerdata[i].isHold; } in.close(); } else {
void xl_set_documentation(Tree *node, text doc) // ---------------------------------------------------------------------------- // Attach the documentation to the node as a comment // ---------------------------------------------------------------------------- { if (!doc.empty()) { std::vector<text> com(1,doc); CommentsInfo *cinfo = new CommentsInfo(); cinfo->after = com; node->SetInfo<CommentsInfo> (cinfo); } }
TEST(linear_mixer, mix_order) { shared_ptr<linear_communication_stub> com(new linear_communication_stub); jubatus::util::concurrent::rw_mutex mutex; linear_mixer m(com, mutex, 1, 1, 1); my_string_driver s; m.set_driver(&s); m.mix(); vector<string> mixed = com->get_mixed(); ASSERT_EQ(1u, mixed.size()); EXPECT_EQ("(4+(3+(2+1)))", mixed[0]); }
int DFURequestsCOM::EnumerateBaudRates(const CStringListX &ports, BaudRateList *&baudRates) { // Construct list of standard baud rates unsigned remaining = sizeof(standardBaudRates) / sizeof(*standardBaudRates); SmartPtr<bool, true> rates(new bool[remaining]); unsigned index; for (index = 0; index < remaining; ++index) rates[index]=false; // Try all of the standard rates on each of the ports specified for (CStringListX::POSITION posPort = ports.GetHeadPosition(); (posPort != 0) && remaining;) { // Try selecting each of the standard baud rates in turn DCB dcb; Device com(ports.GetNext(posPort)); if (bool(com) && GetCommState(com, &dcb)) { for (index = 0; index < sizeof(standardBaudRates) / sizeof(*standardBaudRates); ++index) { if(!rates[index]) { dcb.BaudRate = standardBaudRates[index]; if (SetCommState(com, &dcb)) { // it worked. mark it as good. rates[index] = true; --remaining; } } } } } FreeBaudRateList(baudRates); baudRates = 0; for(index = 0; index < sizeof(standardBaudRates) / sizeof(*standardBaudRates); ++index) { if(rates[index]) { BaudRateList *entry = new BaudRateList; entry->baud = standardBaudRates[index]; entry->next = baudRates; baudRates = entry; } } // Return the number of available baud rates return sizeof(standardBaudRates) / sizeof(*standardBaudRates) - remaining; }