unsigned long long find2(unsigned long long* array,unsigned long long num,unsigned long long begin,unsigned long long end) { if(begin>=end) return array[begin]>=num?array[begin]:array[begin+1]; unsigned long long mid=(begin+end)/2; if(array[mid]==num)return array[mid]; if(array[mid]<num)return find2(array,num,mid+1,end); if(array[mid]>num)return find2(array,num,begin,mid-1); }
void find2(RBtree *tree, RBnode *node, void *k1, void *k2) { if(node->key == NULL) return; find2(tree, node->left, k1, k2); if((tree->compr(node->key, k1) > -1) && (tree->compr(node->key, k2) < 1)) tree->tostr((const void *)node->key, (const void *)node->data); find2(tree, node->right, k1, k2); return; }
// with-sentinel int find2(int array[], int begin, int end, int sentinel) { if (begin == end) return begin; int mid = (begin + end) / 2; printf("begin=%d, mid=%d, end=%d\n", begin, mid, end); if (array[mid] >= sentinel) { int next = mid + 1; if (array[next] < sentinel) return mid; else return find2(array, mid + 1, end, sentinel); } else { return find2(array, begin, mid - 1, sentinel); } }
void work(const int L,const int m,int O) { memset(t,0,sizeof(t)); // the initial color is 1 /* t[1]=1||2 */ ql=1;qr=L;color=1<<1; update(1,1,L+1); while (O--) { char type; while (-1!=(type=getchar()) && (type!='C' && type!='P')); if (type=='C') { scanf("%u%u%u\n",&ql,&qr,&color); color=1<<color; update(1,1,L+1); }else { u32 x; int ans; scanf("%u%u\n",&ql,&qr); x=find2(1,1,L+1)&(~1); for (ans=0;x;ans++,x&=(x-1)); printf("%d\n",ans); } } }
int monster::AIfindpath(HERO *p,short r) { mtime.week=-1; mtime.range=p->range; if(t!=0) deltree(t); if((t=(tree *)malloc(sizeof(tree)))==0)return 0; t->x=p->x; t->y=p->y; t->J=p->job; t->R=p->movement; t->D=i; t->f=0; for(int j=0;j<4;j++) t->c[j]=0; find2(t); if(mtime.week==-1)return 0; else { howtogo(mtime.x,mtime.y); short i=1,dr=mtime.range; while(1) { if((dr-=eff2[maze[pt[i].y][pt[i].x]*4+p->job])<0)break; i++; } moves=i; return 1; } }
int main() { /* MemStat memStat("main"); */ for(int i = 0; i < 1; i++) { input(); copy(); find2(); substring(); find(); replace(); remove(); insert(); compare(); plus(); append(); assign(); reserve(); constuctors(); test1(); // error(); // overflow(); } return 0; }
int main() { #ifndef ONLINE_JUDGE freopen("input/uva253.in", "r", stdin); #endif char cube[13]; while(scanf("%s", cube) != EOF) { printf("%s\n", find2(cube) ? "TRUE" : "FALSE"); } return 0; }
u32 find2(const unsigned i,const unsigned nl,const unsigned nr) { const unsigned nm=(nl+nr)>>1; u32 ans; assert(!(ql>=nr || qr<nl)); if (ql<=nl && qr>=nr-1) return t[i]; assert(nl<nr-1); ans=0; if (needUpdateDown(t[i])) { /* redundant: t[i<<1]=t[1+(i<<1)]=t[i]; return t[i]&=(~1);*/ return t[i]; } if (ql<nm) ans|=find2(i<<1,nl,nm); if (qr>=nm) ans|=find2(1+(i<<1),nm,nr); return ans; }
void RandGame2() { int i, j; for (i = 0; i < N; i++) for (j = 0; j <= N-5; j++) if (find2(matrix, j, i)) { print2(j, i); return; } }
int main() { int ID[10] = {1,2,4,2,4,2,2,2,2,9}; printf("%d\n",find(ID,10)); int ID2[13] = {1,1,2,2,3,3,2,2,1,1,3,3,4}; int candiate[3] = {0,0,0}; find2(ID2,13,candiate); int i; for(i=0;i < 3;i++) printf("%d\n",candiate[i]); }
int main(int argc, char* argv[]) { int array[4][4] = { 1, 2, 8, 9, 2, 4, 9, 12, 4, 7, 10, 13, 6, 8, 11, 15, }; assert(!find1(NULL, 4, 4, 6)); assert(find1(&array[0][0], 4, 4, 6)); assert(find1(&array[0][0], 4, 4, 7)); assert(find1(&array[0][0], 4, 4, 11)); assert(!find1(&array[0][0], 4, 4, 5)); assert(!find1(&array[0][0], 4, 4, 3)); assert(!find2(NULL, 4, 4, 6)); assert(find2(&array[0][0], 4, 4, 6)); assert(find2(&array[0][0], 4, 4, 7)); assert(find2(&array[0][0], 4, 4, 11)); assert(!find2(&array[0][0], 4, 4, 5)); assert(!find2(&array[0][0], 4, 4, 3)); return 0; }
/* Procura pelo elemento KEY na Trie, a partir de pos e com n elementos */ char* find2(Trie *node, const char * key, int pos, int n, int *idx) { if(pos == n) { /* Achou */ *idx = node->idx; return node->elem; } else { if(node->branch[mapChar(key[pos])] == NULL) { /* Não Achou */ return NULL; } else return find2(node->branch[mapChar(key[pos])], key, pos+1, n, idx); } }
void AddPanel(const String& page_name, EvtGroup* pevt) { //ICtl_ribbon_page* p = NULL; //for (size_t i = 0; i < pages.size(); i++) //{ // if (pages[i]->name == page_name) // { // p = pages[i]; // break; // } //} //if (!p) //{ // p = new ICtl_ribbon_page(page_name); // const BitmapBundle& bundle(pevt->GetBundle(16,1)); // p->Create(this, wxID_ANY, str2wx(Translate(page_name)), bundle.bmp_normal); // pages.push_back(p); //} ICtl_ribbon_page* p = find2(page_name); p->AddPanel(pevt); }
void monster::find2(tree *t) { short tx,ty,dr,D; for(int i=0;i<4;i++) if((tx=t->x+cd2[D=(t->D+i)%4])<mapwidth-1 && tx>0 && (ty=t->y+cd2[4+D])<mapheight-1 && ty>0 && massmon[ty][tx]==100 && isgeneration(tx,ty,t,D) && (dr=t->R-eff2[maze[ty][tx]*4+t->J])>=0) { if((t->c[i]=(tree *)malloc(sizeof(tree)))==0)return; t->c[i]->x=tx; t->c[i]->y=ty; t->c[i]->J=t->J; t->c[i]->R=dr; t->c[i]->D=D; t->c[i]->f=t; for(int j=0;j<4;j++) t->c[i]->c[j]=0; att2(t->c[i]); find2(t->c[i]); } }
unsigned long long main() { unsigned long long T,i,j,k,l; scanf("%d",&T); unsigned long long num; unsigned long long n2[61]; for(i=0;i<61;i++) { n2[i]=((unsigned long long)1)<<i; } for(i=0;i<T;i++) { scanf("%lld",&num); unsigned long long n3=1,n5=1,n=LLONG_MAX; while(n5<num*5) { n3=1; while(n5*n3<num*5) { unsigned long long p=num/(n5*n3); unsigned long long p1=num%(n5*n3); if(p==0) n=n<n5*n3?n:n5*n3; else { if(p1!=0)p++; unsigned long long num1=n5*n3*find2(n2,p,0,60); n=n<num1?n:num1; } n3=n3*3; } n5=n5*5; } printf("%lld\n",n>=2?n:2); } return 0; }
int main() { find1(); find2(); }
inline const typename boost::disable_if<boost::is_same<first_type, second_type>, second_type>::type& operator[] (const first_type& key) const { return find2(key); }
int main() { void *data; char *command1, *command2, *def; int result; FILE *fp = fopen("hashlog.txt", "w"); CHTbl *htbl = malloc(sizeof(CHTbl)); chtbl_init(htbl, 4, g3, vstrcmp, NULL); fprintf(fp, "Load factor\tOccupancy\n", (float)(htbl->size/htbl->buckets), htbl->buckets); while(1) { printf(">"); command1 = malloc(sizeof(char)*10); command2 = malloc(sizeof(char)*50); def = malloc(sizeof(char)*1000); result = (parseline(command1, command2, def)); switch(result){ case -1: printf("Error: invalid use of 'add'\n"); free(command2); free(def); break; case -2: printf("Error: invalid use of 'delete'\n"); free(command2); free(def); break; case -3: printf("Error: invalid use of 'find'\n"); free(command2); free(def); break; case -4: printf("Error: command not recognized\n"); free(command2); free(def); break; case -5: printf("Error: no filename given"); free(command2); free(def); case 1: if(!(chtbl_insert(&htbl, command2, def))) { printf("Added %s to dictionary\n", command2); printtolog(fp, htbl); } else printf("Error - %s not added to dictionary\n", command2); break; case 2: free(def); if(!htbl_remove(htbl, command2)) { printf("Deleted %s from dictionary\n", command2); printtolog(fp, htbl); } else printf("Error - %s not found\n", command2); free(command2); break; case 3: free(def); if(!chtbl_lookup(htbl, command2, &data)) { printf("%s\n", command2); printf("%s\n", (char *)data); } else printf("%s not found in dictionary\n", command2); free(command2); break; case 4: free(command2); free(def); print_table(htbl); break; case 5: free(command1); free(command2); free(def); destroy_table(htbl); free(htbl); fclose(fp); return 0; break; case 6: if(!readfile(htbl, command2, fp)) printf("File scanned to dictionary\n"); else printf("Error - file not scanned\n"); free(command2); break; case 7: find2(htbl, command2, def); free(command2); free(def); break; case 8: ptest(htbl, command2, fp); break; } free(command1); } }
int WINAPI WinMain (HINSTANCE hThisInstance,HINSTANCE hPrevInstance,LPSTR lpszArgument,int nFunsterStil) { MSG messages; globallog = new char[1];globallog[0]=32; globallogsize=1; backbar=0; // globallog = (char*)Mrealloc(2); wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; wincl.style = CS_DBLCLKS; wincl.cbSize = sizeof (WNDCLASSEX); wincl.hIcon = LoadIcon( hThisInstance, "A" ); wincl.hIconSm = wincl.hIcon; wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; memset(¬e,0,sizeof(note)); note.cbSize=sizeof(NOTIFYICONDATA); note.hWnd=hwnd; note.uID=0; note.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP; note.hIcon=wincl.hIcon; note.uCallbackMessage=WM_USER+5; lstrcpy(note.szTip,szClassName); if (!RegisterClassEx (&wincl)) return 0; RECT lp; GetWindowRect(GetDesktopWindow(),&lp); int w=GetSystemMetrics(SM_CXSCREEN); int h=GetSystemMetrics(SM_CYSCREEN); hwnd =CreateWindowEx (0,szClassName,"patterns",WS_CAPTION|WS_MINIMIZEBOX|WS_VISIBLE|WS_SYSMENU,lp.right-414,0,414,670,HWND_DESKTOP,NULL,hThisInstance,NULL);//CW_USEDEFAULT hlog =CreateWindowEx (0,"Edit","",WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_AUTOVSCROLL|ES_NOHIDESEL|WS_VSCROLL,0,0,438,630,hwnd,NULL,hThisInstance,NULL); // hcmd =CreateWindowEx (0,"Edit","",WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_AUTOVSCROLL|ES_NOHIDESEL|WS_VSCROLL,0,310,538,20,hwnd,NULL,hThisInstance,NULL); // hcmd =CreateWindowEx (WS_EX_CLIENTEDGE,"ListBox","",WS_CHILD|WS_VISIBLE|WS_VSCROLL|LVS_REPORT | LVS_SHAREIMAGELISTS,0,260,538,70,hwnd,NULL,hThisInstance,NULL); hpro =CreateWindowEx (0,"Static"," ",WS_CHILD | WS_VISIBLE,0,630,380,20,hwnd,NULL,hThisInstance,NULL); /* SendMessage( hcmd, LVM_FIRST+54, 0, 32 | 16 | 2 | 1); ListView_SetTextColor(hcmd,0x00000000); SendMessage( hcmd, LVM_SETTEXTBKCOLOR, 0, 0x00ffffef); ListView_SetBkColor(hcmd,0xffffef); ListBox_InsertString(hcmd,0,"MMCIS-Real"); ListBox_InsertString(hcmd,0,"MMCIS-Demo"); LV_ITEM lvi;//memset(&lvi,0,sizeof(LV_ITEM)); LV_COLUMN lvc; lvc.pszText="dfg"; lvc.cx=44; lvc.iSubItem=0; ListView_InsertColumn(hcmd,1,&lvc); ListBox_SetColumnWidth(hcmd,41); lvi.cchTextMax=22; lvi.iItem=0; lvi.lParam=0; lvi.iSubItem=1; lvi.mask=LVIF_PARAM; lstrcat(lvi.pszText," subitem "); //ListBox_InsertItemData(hcmd,0,&lvi); SendMessage(hcmd, LVM_SETITEM, 0, (LPARAM)&lvi); // lvi.mask=LVIF_TEXT; lvi.cchTextMax=12; lvi.iItem=0; lvi.lParam=1; lvi.iSubItem=1; // lstrcat(lvi.pszText," subitem "); ListBox_InsertItemData(hcmd,0,&lvi); SendMessage(hcmd, LVM_SETTEXTCOLOR, 0, (LPARAM)(COLORREF)0xff0f00ff); ListView_Update(hcmd,0); ListView_RedrawItems(hcmd,0,3); */ //mysqltest(); if(find(lpszArgument,"/quit"))ShowWindow (hwnd, SW_HIDE); else ShowWindow (hwnd, nFunsterStil); UpdateWindow(hwnd); srand(time(0)); if(find(lpszArgument,"/opt"))action=optimizing;else if(find(lpszArgument,"/test")){ action=testing; hbup =CreateWindowEx (0,"Button"," ",WS_CHILD | WS_VISIBLE,40,630,10,10,hwnd,NULL,hThisInstance,NULL); hbdn =CreateWindowEx (0,"Button"," ",WS_CHILD | WS_VISIBLE,40,640,10,10,hwnd,NULL,hThisInstance,NULL); hbackbar =CreateWindowEx (0,"Static"," ",WS_CHILD | WS_VISIBLE,20,630,20,20,hwnd,NULL,hThisInstance,NULL);title(whbackbar,intToStr(backbar)); }else if(find(lpszArgument,"/debug"))action=debuging; if(find(lpszArgument,"/1t"))period=1;else if(find(lpszArgument,"/5t"))period=5;else if(find(lpszArgument,"/15t"))period=15;else if(find(lpszArgument,"/60t"))period=60;else if(find(lpszArgument,"/240t"))period=240;else if(find(lpszArgument,"/1440t"))period=1440;else if(find(lpszArgument,"/10080t"))period=10080;else if(find(lpszArgument,"/43200t"))period=43200; mode=999; if(find2(lpszArgument,"/MMCIS-Demo"))mode=light;else if(find2(lpszArgument,"/MMCIS-Real"))mode=medium;else if(find2(lpszArgument,"/InstaForex-Demo.com"))mode=hard; if(find(lpszArgument,"/quit")){PostMessageA(hwnd,WM_SIZE,SIZE_MINIMIZED,0);GetMessage (&messages, NULL, 0, 0);TranslateMessage(&messages);DispatchMessage(&messages);} // server = new Server; // if(action==optimizing)server->on(false);else server->on(); if(mode==999)wlog("Optimization: patterns.exe /MMCIS-Demo /opt /1440t\r\nTesting: patterns.exe /MMCIS-Demo /test /1440t\r\nDebuging: patterns.exe /MMCIS-Demo /debug /1440t\r\n\r\naction: /opt,/test,/debug\r\nperiod: /1t,/5t,/15t,/60t,/240t,/1440t,/10080t,/43200t\r\nmode: /MMCIS-Demo,/MMCIS-Real,/InstaForex-Demo.com\r\n\r\nExample: mt5\\bases\\MetaQuotes-Demo\\history\\patterns.exe /MMCIS-Demo /opt /1440t\r\n"); else if(action!=optimizing)decode(action,period,mode,donottradecurrentbar,backbar); else decode(action,period,mode,tradecurrentbar,backbar); InvalidateRect(hwnd,0,true); if(!find(lpszArgument,"/quit")) while (GetMessage (&messages, NULL, 0, 0)) {if((messages.hwnd==hcmd)&&(messages.message==WM_KEYUP)&&messages.wParam==VK_RETURN)wcmd(cmdmain); if((messages.hwnd==hcmd)&&(messages.message==WM_LBUTTONDBLCLK))wlog(intToStr(ListBox_GetCurSel(hcmd) )); if((messages.hwnd==hbup)&&(messages.message==WM_LBUTTONUP)){backbar++;if(backbar>21)backbar=21;else title(whbackbar,intToStr(backbar));decode(action,period,mode,donottradecurrentbar,backbar);InvalidateRect(hwnd,0,true);} if((messages.hwnd==hbdn)&&(messages.message==WM_LBUTTONUP)){backbar--;if(backbar<-1)backbar=-1;else title(whbackbar,intToStr(backbar));decode(action,period,mode,donottradecurrentbar,backbar);InvalidateRect(hwnd,0,true);} TranslateMessage(&messages); DispatchMessage(&messages); } wlogsave(); if(find(lpszArgument,"/quit")){Shell_NotifyIcon(NIM_DELETE,¬e);GetMessage (&messages, NULL, 0, 0);TranslateMessage(&messages);DispatchMessage(&messages);} delete[] globallog; return messages.wParam; }
int findRightEnd(int array[], int begin, int end) { return find2(array, begin, end, array[0]); }
int main() { void *data; char *command1, *command2, *def; int result; FILE *fp = fopen("treelog.txt", "w"); RBtree *tree = malloc(sizeof(RBtree)); init_tree(tree, vstrcmp, node_destroy, node_print); fprintf(fp, "Tree Height\n"); while(1) { printf(">"); command1 = malloc(sizeof(char)*10); command2 = malloc(sizeof(char)*50); def = malloc(sizeof(char)*1000); result = (parseline(command1, command2, def)); switch(result) { case -1: printf("Error: invalid use of 'add'\n"); free(command2); free(def); break; case -2: printf("Error: invalid use of 'delete'\n"); free(command2); free(def); break; case -3: printf("Error: invalid use of 'find'\n"); free(command2); free(def); break; case -4: printf("Error: command not recognized\n"); free(command2); free(def); break; case -5: printf("Error: no filename given"); free(command2); free(def); case 1: if(!insert_node(tree, command2, def)) { printf("Added %s to dictionary\n", command2); printtolog(fp, tree); } else printf("Error - %s not added to dictionary\n", command2); break; case 2: free(def); if(!delete_node(tree, command2)) { printf("Deleted %s from dictionary\n", command2); printtolog(fp, tree); } else printf("Error - %s not found\n", command2); free(command2); break; case 3: free(def); if(!find_node(tree, command2, &data)) { printf("%s\n", command2); printf("%s\n", (char *)data); } else printf("%s not found in dictionary\n", command2); free(command2); break; case 4: free(command2); free(def); print_tree(tree, tree->root); break; case 5: free(command1); free(command2); free(def); destroy_tree(tree, tree->root); free(tree); fclose(fp); return 0; break; case 6: if(!readfile(tree, command2, fp)) printf("File scanned to dictionary\n"); else printf("Error - file not scanned\n"); free(command2); break; case 7: find2(tree, tree->root, command2, def); free(command2); free(def); break; case 8: ptest(tree, command2, fp); free(command2); break; } free(command1); } }
int main(int argc, char *argv[]) { bool running = false; TFullName res; TFindProcess find; while(find.Next(res) == KErrNone) { RProcess ph; ph.Open(res); if(ph.SecureId() == 0x2002B30D) if (ph.ExitType() == EExitPending) { running = true; break; } ph.Close(); } if (running == false) { QProcess *myProcess = new QProcess; myProcess->start("whatsapp.exe"); } else { QApplication app(argc, argv); CAknConfirmationNote* run = new (ELeave) CAknConfirmationNote; QT_TRAP_THROWING(run->ExecuteLD(_L("Closed WhatsApp"))); TFullName res1; TFindProcess find1(_L("*[2002B306]*")); while(find1.Next(res1) == KErrNone) { RProcess ph1; ph1.Open(find1); ph1.Kill(KErrNone); ph1.Close(); } TFullName res2; TFindProcess find2(_L("*[2002B310]*")); while(find2.Next(res2) == KErrNone) { RProcess ph2; ph2.Open(find2); ph2.Kill(KErrNone); ph2.Close(); } TFullName res3; TFindProcess find3(_L("*[2002B30D]*")); while(find3.Next(res3) == KErrNone) { RProcess ph3; ph3.Open(find3); ph3.Kill(KErrNone); ph3.Close(); } QTest::qWait(1500); } return 1; }
char* find(Trie *node, const char * key, int *idx) { return find2(node, key, 0, strlen(key), idx); }