double Find3(double l,double r){ // printf("find3(%lf,%lf)\n",l,r); double x=r-l; if(x<eps)return l;x/=3.0; double ll=l+x,rr=r-x; // printf("ll=%lf,rr=%lf\n",ll,rr); double fll=f(ll),frr=f(rr); // printf("fll=%lf,frr=%lf\n\n",fll,frr); if(fll<frr)return Find3(l,rr); else return Find3(ll,r); }
Omega::string_t TreeItemData::Find3(OTL::ObjectPtr<Omega::Registry::IKey>& ptrKey, const Omega::string_t& strFind, bool bKeys, bool bValues, bool bData, bool bMatchAll, bool bIgnoreCase, bool& bKey) { // Check the current sub-keys std::set<Omega::string_t> keys = ptrKey->EnumSubKeys(); for (std::set<Omega::string_t>::const_iterator i=keys.begin();i!=keys.end();++i) { // Check key name if (bKeys) { if (bMatchAll) { if (i->Compare(strFind,0,Omega::string_t::npos,bIgnoreCase) == 0) { // Found it! bKey = true; return *i; } } else if (i->Find(strFind,0,bIgnoreCase) != Omega::string_t::npos) { // Found it! bKey = true; return *i; } } // Check key values OTL::ObjectPtr<Omega::Registry::IKey> ptrSubKey = ptrKey->OpenSubKey(*i); std::set<Omega::string_t> values = ptrSubKey->EnumValues(); for (std::set<Omega::string_t>::const_iterator j=values.begin();j!=values.end();++j) { if (MatchValue(strFind,ptrSubKey,*j,bValues,bData,bMatchAll,bIgnoreCase)) { // Found it! bKey = false; return *i + L"/" + *j; } } // Recurse down... Omega::string_t strNext = Find3(ptrSubKey,strFind,bKeys,bValues,bData,bMatchAll,bIgnoreCase,bKey); if (!strNext.IsEmpty()) { return *i + L"/" + strNext; } } return Omega::string_t(); }
int main(){ while(scanf("%d",&n)!=EOF){ int i; double max=-1e18,min=1e18; for(i=1;i<=n;i++){ scanf("%d%d",&x[i],&p[i]); if(x[i]>max)max=x[i]; if(x[i]<min)min=x[i]; } // printf("%lf %lf\n",max,min); double res=Find3(min,max); printf("%.5lf\n",res); // while(scanf("%lf",&res)!=EOF&&abs(res)>eps)printf("%lf\n",f(res)); } return 0; }
void TreeItemData::Find2(wxTreeCtrl* pTree, wxTreeItemId tree_id, wxListCtrl* pList, const Omega::string_t& strFind, bool bKeys, bool bValues, bool bData, bool bMatchAll, bool bIgnoreCase) { TreeItemData* pItem = (TreeItemData*)pTree->GetItemData(tree_id); bool bKey = false; Omega::string_t strFoundPos = Find3(pItem->m_ptrKey,strFind,bKeys,bValues,bData,bMatchAll,bIgnoreCase,bKey); if (!strFoundPos.IsEmpty()) { // Expand and select the item wxString strSubKey; for (;;) { size_t pos = strFoundPos.Find('/'); if (pos != Omega::string_t::npos) { strSubKey = strFoundPos.Left(pos).c_wstr(); strFoundPos = strFoundPos.Mid(pos+1); } else { strSubKey = strFoundPos.c_wstr(); strFoundPos.Clear(); if (!bKey) break; } //pTree->SelectItem(tree_id); pTree->Expand(tree_id); if (strSubKey == pTree->GetItemText(tree_id)) continue; if (pTree->ItemHasChildren(tree_id)) { wxTreeItemIdValue cookie; wxTreeItemId id_child = pTree->GetFirstChild(tree_id,cookie); while (id_child && strSubKey != pTree->GetItemText(id_child)) { id_child = pTree->GetNextChild(tree_id,cookie); } if (!id_child) { break; } tree_id = id_child; } else { break; } } pTree->SelectItem(tree_id); if (!bKey) { long item; while ((item=pList->GetNextItem(-1,wxLIST_NEXT_ALL,wxLIST_STATE_SELECTED)) != -1) { pList->SetItemState(item,0,wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED ); } item = pList->FindItem(-1,wxString(strSubKey)); pList->SetItemState(item,wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED); pList->SetFocus(); } else { pTree->SetFocus(); } return; } // Try the next sibling wxTreeItemId next_id = pTree->GetNextSibling(tree_id); while (!next_id) { if (tree_id == pTree->GetRootItem()) { wxMessageBox(_("Reached the end of the registry."),_("Find"),wxOK|wxICON_INFORMATION,NULL); return; } tree_id = pTree->GetItemParent(tree_id); next_id = pTree->GetNextSibling(tree_id); } Find2(pTree,next_id,pList,strFind,bKeys,bValues,bData,bMatchAll,bIgnoreCase); }