void input() { pre(); int i; printf("enter number of process\n"); scanf("%d",&n); for(i=0;i<n;i++) { printf("enter arrival time and head location of %d\n",i+1); scanf("%d%d",&disk[i].arr_time,&disk[i].head_loc); disk[i].process_pid=i+1; done[i]=false; } printf("enter head position\n"); scanf("%d",&head_pos); val=head_pos; }
/* time and memory management outputs */ void timestamp(const char* const fmt, ...) { pre(fmt != NULL); va_list ap; va_start(ap, fmt); fflush(stdout); fputc('\n', stderr); vfprintf(stderr, fmt, ap); fputc('\n', stderr); va_end(ap); // fprintf(stderr, "%s\n", string); time_t t1 = time(0); fprintf(stderr, "%3.2f sec. elapsed\n", difftime(t1,t0)); fprintf(stderr, "--------------------------------------------\n"); }
bool isMatch(string s, string p) { int sLen = s.size(), pLen = p.size(); vector<bool> pre(pLen + 1, false), cur(pLen + 1, false); pre[0] = true; for (int pIter = 2; pIter <= pLen; pIter++) pre[pIter] = p[pIter - 1] == '*' && pre[pIter - 2]; for (int sIter = 1; sIter <= sLen; sIter++) { cur[0] = false; for (int pIter = 1; pIter <= pLen; pIter++) { if (p[pIter - 1] == '*') cur[pIter] = cur[pIter - 2] || pre[pIter] && (s[sIter - 1] == p[pIter - 2] || p[pIter - 2] == '.'); else cur[pIter] = pre[pIter - 1] && (s[sIter - 1] == p[pIter - 1] || p[pIter - 1] == '.'); } pre = cur; } return pre[pLen]; }
void bimWorld::CameraManipulator::enableFirstPersonControl() { bindKeyDownEvent(KEY_W, beginMoveForward); bindKeyUpEvent(KEY_W, endMoveForward); bindKeyDownEvent(KEY_S, beginMoveBackward); bindKeyUpEvent(KEY_S, endMoveBackward); bindKeyDownEvent(KEY_A, beginMoveLeft); bindKeyUpEvent(KEY_A, endMoveLeft); bindKeyDownEvent(KEY_D, beginMoveRight); bindKeyUpEvent(KEY_D, endMoveRight); unbindMouseEvent(MIDDLE_MOUSE_BUTTON); return; //if (m_isFirstPersonManipEnabled) // return; //switchMatrixManipulator(ManipulatorType::Person); //m_isFirstPersonManipEnabled = true; //getBIMCameraManip()->setRotationHandleBtn(osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON); //float totalFrame = 60.0f; bimWorld::CameraOperation operation(getBIMCameraManip()); m_zoomForwardDelta = operation.getZoomDelta(totalFrame_FP); std::function<void(float)> prefunc = [this/*, totalFrame*/](float frame){ //static int frame = 1; //static float newF = 1;//-1 / totalFrame * frame*frame + frame; bimWorld::CameraOperation operation(getBIMCameraManip()); operation.zoomForward(m_zoomForwardDelta, frame); //if (newF < (totalFrame / 2.0f)) //{ // frame++; // newF += frame; //} //else //{ // frame--; // newF -= frame; //} }; core::InstanceFunction<void(float)> pre(prefunc, this, "onPreEnableFirstPersonControl"); std::function<void(float)> postfunc = [](float){}; core::InstanceFunction<void(float)> post(postfunc, this, "onPostEnableFirstPersonControl"); m_host->_RenderingThreads()->setBlockAnimation((unsigned int)totalFrame_FP, pre, post); }
int look() { pre(); printf("performing look\n\n"); int i,curr,j; int tot_time=0; int time_diff; int time; curr=head_pos; time=0; sort_headloc(disk,0,n-1); while(1) { bool check =false; for(i=0;i<n;i++) if(done[i]==false) check=true; if(check==false) break; for(i=0;i<n;i++) { time_diff = disk[i].head_loc - head_pos; if(time_diff + time >= disk[i].arr_time && done[i]==false) { done[i]=true; printf("request serve for %d process\n",disk[i].process_pid); time+=time_diff; head_pos=disk[i].head_loc; } } for(i=n-1;i>=0;i--) { time_diff = abs(head_pos-disk[i].head_loc); if(time_diff + time >= disk[i].arr_time && done[i]==false) { done[i]=true; printf("request serve for %d process\n",disk[i].process_pid); time+=time_diff; head_pos=disk[i].head_loc; } } } tot_time=time; return tot_time; }
/* apply this function to every non-null bin in the hashtable */ void func_hashtable(hashtable* const hash, void (*func)(bin* bin)) { pre(func != NULL); int i; bin* iter; bin* next; for(i = 0; i < hash->size; i++){ iter = hash->bins[i]; while(iter){ next = iter->next; func(iter); iter = next; } } }
EXPORT ICUException::ICUException(UParseError &pe, UErrorCode status) { PyObject *messages = PyObject_GetAttrString(PyExc_ICUError, "messages"); UnicodeString pre((const UChar *) pe.preContext, U_PARSE_CONTEXT_LEN); UnicodeString post((const UChar *) pe.postContext, U_PARSE_CONTEXT_LEN); PyObject *tuple = PyTuple_New(5); ICUException::code = PyInt_FromLong((long) status); PyTuple_SET_ITEM(tuple, 0, PyObject_GetItem(messages, code)); PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(pe.line)); PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(pe.offset)); PyTuple_SET_ITEM(tuple, 3, PyUnicode_FromUnicodeString(&pre)); PyTuple_SET_ITEM(tuple, 4, PyUnicode_FromUnicodeString(&post)); ICUException::msg = tuple; Py_DECREF(messages); }
bool isMatch(const char *s, const char *p) { // Start typing your C/C++ solution below // DO NOT write int main() function if(!s || !p || !initCheck(s, p)) return false; if(!*p) return !*s; int len = strlen(p); vector<bool> pre(len, false); vector<bool> cur(len, false); bool isFirst = true; for(int i = 0; i < len; i++) { if(p[i] == '*') pre[i] = (i == 0) || pre[i-1]; else if((*s == p[i] || p[i] == '?') && isFirst) { isFirst = false; pre[i] = true; } else break; } s++; while(*s) { for(int i = 0; i < len; i++) { if(p[i] == '*') { cur[i] = pre[i] || (i != 0 && cur[i-1]); } else { cur[i] = (i != 0 && pre[i-1] && (p[i] == *s || p[i] == '?')); } } pre.assign(cur.begin(), cur.end()); cur.assign(len, false); s++; } return pre[len-1]; }
/** * specialized version of irg_walk_2, called if only pre callback exists */ static void irg_walk_2_pre(ir_node *node, irg_walk_func *pre, void *env) { ir_graph *irg = get_irn_irg(node); ir_visited_t visited = irg->visited; set_irn_visited(node, visited); pre(node, env); if (!is_Block(node)) { ir_node *pred = get_nodes_block(node); if (pred->visited < visited) irg_walk_2_pre(pred, pre, env); } foreach_irn_in_r(node, i, pred) { if (pred->visited < visited) irg_walk_2_pre(pred, pre, env); } }
// returns the center of the longest palindrome. for its length search for P[ans] int longest_palindrome() { pre(); int c=0; int r=0; for(int i=1; i<N-1; i++) { int mirror = 2*c-i; P[i] = r>i ? min(r-i,P[mirror]) : 0; while(A[i+1+P[i]]==A[i-1-P[i]]) P[i]++; if(i+P[i] > r) { c=i; r=i+P[i]; } } int maxlen=0; int centeri=0; for(int i=1; i<n-1; i++) { if(P[i]>maxlen) { maxlen=P[i]; centeri=i; } } return centeri; }
int main() { int cas, d; cin >> cas; for(int i = 0 ;i < cas;i ++) { cin >> d; a = 2013; b = 3; c = 24; for(int f = 0 ; f < d;f++) next(); printf("%d/%02d/%02d ", a, b, c); a = 2013; b = 3; c = 24; for(int f = 0 ; f < d;f++) pre(); printf("%d/%02d/%02d\n", a, b, c); } return 0; }
int main() { int i, n; scanf("%d", &n); getchar(); for(i=0; i<n; i++) { char s[10];; gets(s); if(s[2] == '.') s[2]=0; if(s[4] == '.') s[4]=0; node[s[0]-'A'][0] = s[2]; node[s[0]-'A'][1] = s[4]; } pre('A'); puts(""); in('A'); puts(""); post('A'); puts(""); return 0; }
/*look up the hash table to see an entry corresponding to the string of length * len exists. Return the bin if it does exist*/ void* lookup_hashtable(hashtable* const hash, const char* const name, const int len) { pre(name != NULL); uint32_t index = hashfunc(name, len); index = index & hash->mask; bin* iter = NULL; bin* bin = NULL; if(hash->bins[index] != NULL){ for(iter = hash->bins[index];iter; iter = iter->next){ if(strncmp(iter->name, name, len) == 0){ bin = iter; } } } return bin; }
void iterate_parallel_cluster(pccluster t, uint tname, uint pardepth, void (*pre) (pccluster t, uint tname, void *data), void (*post) (pccluster t, uint tname, void *data), void *data) { uint *tname1, tname2; #ifdef USE_OPENMP uint nthreads; /* HACK: Solaris workaround */ #endif uint i; if (pre) pre(t, tname, data); if (t->sons > 0) { tname1 = (uint *) allocmem((size_t) sizeof(uint) * t->sons); tname2 = tname + 1; for (i = 0; i < t->sons; i++) { tname1[i] = tname2; tname2 += t->son[i]->desc; } assert(tname2 == tname + t->desc); #ifdef USE_OPENMP nthreads = t->sons; (void) nthreads; #pragma omp parallel for if(pardepth > 0), num_threads(nthreads) #endif for (i = 0; i < t->sons; i++) iterate_parallel_cluster(t->son[i], tname1[i], (pardepth > 0 ? pardepth - 1 : 0), pre, post, data); freemem(tname1); } if (post) post(t, tname, data); }
nemo::Configuration configuration(backend_t backend) { nemo::Configuration conf; std::vector<float> pre(20); std::vector<float> post(20); for(unsigned i = 0; i < 20; ++i) { int dt = i; pre.at(i) = dwPre(-dt); post.at(i) = dwPost(dt); } /* don't allow negative synapses to go much more negative. * This is to avoid having large negative input currents, * which will result in extra firing (by forcing 'u' to * go highly negative) */ conf.setStdpFunction(pre, post, -0.5, 2*initWeight); setBackend(backend, conf); return conf; }
int main(int argc, char* argv[]) { //=====Empeche de lancer COW plusieurs fois QtSingleApplication app(argc, argv); if (app.isRunning()) return 0; //========== QDir::setCurrent(QDir::currentPath()); //=====Informations app.setApplicationName("COW Chat Over the World"); app.setApplicationVersion("2.0.0.0"); app.setOrganizationDomain("the-cow.org"); app.setOrganizationName("Basile Bruneau"); //========== //=====Traductions QString locale = QLocale::system().name(); QTranslator trans; trans.load(QString(":/translations/qt_") + locale); app.installTranslator(&trans); QTranslator translator; translator.load(QString(":/translations/cow-client_") + locale.section('_', 0, 0)); app.installTranslator(&translator); preFen pre("",locale.section('_', 0, 0)); //========== app.setActivationWindow(&pre); //Empeche de lancer COW plusieurs fois /* Bien sur, il ne suffit pas d'enlever certaines parties du code pour pouvoir lancer COW une infinité de fois. Vous vous doutez bien qu'il y a un controle par ip sur le serveur */ pre.show(); return app.exec(); }
bool TreeView::add(const std::string& name, const osg::ref_ptr<osg::Node> node, const bool& enableNode, const bool& showNode, const bool& replace, d3DisplayItem* myParent) { static const std::string splitIndicator("::"); // get the name split point size_t nameSplit( name.find(splitIndicator) ); // see if we have children if ( std::string::npos != nameSplit ) { // the first part is the parent's name std::string pre( name.substr(0, nameSplit) ); // the second part is the children std::string post( name.substr(nameSplit + splitIndicator.size(), name.size()) ); // call the add parent return addParent(pre, post, node, enableNode, showNode, replace, myParent); } // this must be a leaf node... do we already have this child? d3DisplayItem* entry(findChild(myParent, name)); // see if we need to create a new entry if ( nullptr == entry ) { return createNewEntry(name, node, enableNode, showNode, myParent); } else { return addToEntry(entry, node, enableNode, replace, myParent); } return false; };
vector<vector<int> > generate(int numRows) { // Start typing your C/C++ solution below // DO NOT write int main() function vector<int> pre(1, 1); vector<vector<int> > result; for(int i = 0; i< numRows; i++) { vector<int> row(i+1); for(int j = 1; j < i; j++) { row[j] = pre[j-1] + pre[j]; } row[0] = 1; row[i] = 1; result.push_back(row); pre = row; } return result; }
//returns all positions of matched in given text vector<int> kmp(string text, string pattern) { vector<int> pre(pattern.size()); vector<int> ans; if (pattern.size() == 0) return ans; prefix_function(pre, pattern); int j = -1; //Complexity is O(n) for (int i=0 ; i<text.size(); ++i) { while (j>=0 && text[i]!=pattern[j + 1]) { j = pre[j]; } if (text[i] == pattern[j + 1]) { j++; if (j+1 == pattern.size()) { ans.push_back(i - j); j = pre[j]; } } } return ans; }
void combinationSum(vector<int> &candidates, int index, int target, vector<vector<int> > &result) { if(target <= 0) return; while(index<candidates.size() && target>=candidates[index]) { for(int i=1; candidates[index]*i<=target; ++i) { vector<int> pre(i, candidates[index]); vector<vector<int> > res; if(target == candidates[index]*i) { result.push_back(pre); } else { combinationSum(candidates, index+1, target-candidates[index]*i, res); for(int j=0; j<res.size(); ++j) { vector<int> item = pre; item.insert(item.end(), res[j].begin(), res[j].end()); result.push_back(item); } } } ++index; } }
void CompiledGraph::traverse_subgraph (const Walker& walker, InstanceMap::iterator i) { Stack<InstanceMap::iterator> stack; if (i != m_instances.end()) { const std::size_t startSize = (*i).first.get().size(); do { if (i != m_instances.end() && stack.size() < ((*i).first.get().size() - startSize + 1)) { stack.push(i); ++i; if (!pre(walker, stack.top())) { // skip subgraph while (i != m_instances.end() && stack.size() < ((*i).first.get().size() - startSize + 1)) { ++i; } } } else { post(walker, stack.top()); stack.pop(); } } while (!stack.empty()); } }
vector<string> wordBreak(string s, unordered_set<string> &dict) { // Note: The Solution object is instantiated only once and is reused by each test case. int len = s.size(); vector<string> res; if(len == 0) return res; vector<vector<int>> pre(len+1,vector<int>()); for(int i = 0;i < len;i++) { if(pre[i].size() || i == 0) { for(int j = 1;j <= len - i;j++) { string ss = s.substr(i,j); if(dict.find(ss) != dict.end()) pre[i+j].push_back(i); } } } vector<int> tmp; generate(pre,res,s,tmp,len); return res; }
void iterate_cluster(pccluster t, uint tname, void (*pre) (pccluster t, uint tname, void *data), void (*post) (pccluster t, uint tname, void *data), void *data) { uint tname1; uint i; if (pre) pre(t, tname, data); tname1 = tname + 1; for (i = 0; i < t->sons; i++) { iterate_cluster(t->son[i], tname1, pre, post, data); tname1 += t->son[i]->desc; } assert(tname1 == tname + t->desc); if (post) post(t, tname, data); }
int main(){ while(scanf("%d%d%d", &n, &m, &r), n||m||r){ for(int i=0; i<n; i++) scanf("%d%d%d%d", &balloon[i].x, &balloon[i].y, &balloon[i].z, &balloon[i].v); for(int i=0; i<m; i++){ scanf("%d%d%d%d", &light[i].x, &light[i].y, &light[i].z, &light[i].v); } scanf("%d%d%d", E, E+1, E+2); pre(); double result, Max = 0; for(int i=1; i < 1<<m; i++){ for(int j=i, k = 0; j; j>>=1, k++) if(j&1) rm(k); for(int j=0; j<=n/30; j++) for(;cnt[j]; cnt[j]>>=1) if(cnt[j]&1) result++; } } return 0; }
template <class Ostream> Ostream& write(Ostream& os, Dimbo::Clinfo::Platform_Info const& info, int ind) { Autosep<const char*> as("\n"); std::string pre(ind, ' '); std::ostringstream id; id << "0x" << std::hex << info.id(); if(info.has_id()) os << as << pre << "Id (within current process) ....: " << id.str(); if(info.has_profile()) os << as << pre << "Profile ........................: " << info.profile(); if(info.has_version()) os << as << pre << "Version ........................: " << info.version(); if(info.has_name()) os << as << pre << "Name ...........................: " << info.name(); if(info.has_vendor()) os << as << pre << "Vendor .........................: " << info.vendor(); if(info.has_extensions()) os << as << pre << "Extensions .....................: " << info.extensions(); return os; }
int main() { int m,i,j,k; pre(); scanf("%d",&n); if(n<6)goto end; for(m=6;m<=n;m++){ for(i=2;i<=m-3;i++){ if(cube[i]+cube[i+1]+cube[i+2]>cube[m])break; for(j=i+1;j<=m-2;j++){ if(cube[i]+cube[j]+cube[j+1]>cube[m])break; for(k=j+1;k<=m-1;k++) if(cube[i]+cube[j]+cube[k]>cube[m])break; else if(cube[i]+cube[k]+cube[j]==cube[m]) printf("Cube = %d, Triple = (%d,%d,%d)\n",m,i,j,k); } } } end:return 0; }
int sstf() { pre(); printf("performing sstf\n\n"); int i,curr,j,minn; int tot_time=0; int time,time_diff; sort_headloc(disk,0,n-1); curr=head_pos; time=0; while(1) { bool check =false; for(i=0;i<n;i++) if(done[i]==false) check=true; if(check==false) break; minn=100009; for(i=0;i<n;i++) { if(done[i]==false) minn=min(minn,abs(head_pos-disk[i].head_loc)); } for(i=0;i<n;i++) { if(abs(disk[i].head_loc-head_pos)==minn && done[i]==false) { tot_time+=abs(disk[i].head_loc-head_pos); head_pos=disk[i].head_loc; done[i]=true; printf("served request for %d process\n",disk[i].process_pid); } } } return tot_time; }
int main( int argc, char * argv[] ) { if( argc < 3 ){ cerr << "Usage : " << argv[0] << " [n] [thr_pos] " << endl; exit(1); } int n = atoi( argv[1] ); double thr_pos = atof( argv[2] )*n; string line; /** new method with trie/trie interaction */ IDFA<int> Apep; DFA<N_AMINOACIDS> TCR; while( cin ){ getline( cin, line ); if( line.length() >= n ){ Apep.addString( pep2intseq( line.substr( 0, n ) ) ); } } vector<int> pre(n); trie_recurse( TCR, Apep, Apep.initialState(), pre, thr_pos, 0 ); TCR.print(); }
int main() { init(); pre(); int i, j; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) { getchar(); for (j = 0; j < m; j++) map[i][j] = rton[(int)getchar()]; } ans = 5000; for (i = 0; i < n; i++) { memset(v, 0, sizeof(v)); v[i][0]=1; dfs(TREE[1].next[map[i][0]], i, 0, 0); } if (ans == 5000) puts("NO"); else { char roman[20]; number_to_roman(ans, roman); puts(roman); } return 0; }
address AbstractInterpreterGenerator::generate_slow_signature_handler() { address entry = __ pc(); __ andr(esp, esp, -16); __ mov(c_rarg3, esp); // rmethod // rlocals // c_rarg3: first stack arg - wordSize // adjust sp __ sub(sp, c_rarg3, 18 * wordSize); __ str(lr, Address(__ pre(sp, -2 * wordSize))); __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::slow_signature_handler), rmethod, rlocals, c_rarg3); // r0: result handler // Stack layout: // rsp: return address <- sp // 1 garbage // 8 integer args (if static first is unused) // 1 float/double identifiers // 8 double args // stack args <- esp // garbage // expression stack bottom // bcp (NULL) // ... // Restore LR __ ldr(lr, Address(__ post(sp, 2 * wordSize))); // Do FP first so we can use c_rarg3 as temp __ ldrw(c_rarg3, Address(sp, 9 * wordSize)); // float/double identifiers for (int i = 0; i < Argument::n_float_register_parameters_c; i++) { const FloatRegister r = as_FloatRegister(i); Label d, done; __ tbnz(c_rarg3, i, d); __ ldrs(r, Address(sp, (10 + i) * wordSize)); __ b(done); __ bind(d); __ ldrd(r, Address(sp, (10 + i) * wordSize)); __ bind(done); } // c_rarg0 contains the result from the call of // InterpreterRuntime::slow_signature_handler so we don't touch it // here. It will be loaded with the JNIEnv* later. __ ldr(c_rarg1, Address(sp, 1 * wordSize)); for (int i = c_rarg2->encoding(); i <= c_rarg7->encoding(); i += 2) { Register rm = as_Register(i), rn = as_Register(i+1); __ ldp(rm, rn, Address(sp, i * wordSize)); } __ add(sp, sp, 18 * wordSize); __ ret(lr); return entry; }