首页 文章 精选 留言 我的

精选列表

搜索[热搜算法],共10000篇文章
优秀的个人博客,低调大师

算法学习之路|日期问题

小明正在整理一批历史文献。这些历史文献中出现了很多日期。小明知道这些日期都在1960年1月1日至2059年12月31日。令小明头疼的是,这些日期采用的格式非常不统一,有采用年/月/日的,有采用月/日/年的,还有采用日/月/年的。更加麻烦的是,年份也都省略了前两位,使得文献上的一个日期,存在很多可能的日期与其对应。 比如02/03/04,可能是2002年03月04日、2004年02月03日或2004年03月02日。 给出一个文献上的日期,你能帮助小明判断有哪些可能的日期对其对应吗? 输入 一个日期,格式是"AA/BB/CC"。 (0 <= A, B, C <= 9) 输出 输出若干个不相同的日期,每个日期一行,格式是"yyyy-MM-dd"。多个日期按从早到晚排列。 样例输入 02/03/04 样例输出 2002-03-04 2004-02-03 2004-03-02 资源约定: 峰值内存消耗(含虚拟机) < 256M CPU消耗 < 1000ms 请严格按要求输出,不要画蛇添足地打印类似:“请您输入...” 的多余内容。 注意: main函数需要返回0; 只使用ANSI C/ANSI C++ 标准; 不要调用依赖于编译环境或操作系统的特殊函数。 所有依赖的函数必须明确地在源文件中 #include 不能通过工程设置而省略常用头文件。 提交程序时,注意选择所期望的语言类型和编译器类型 解题思路: 把每一部分的功能都分开了。 先判断天数,月份,年数是否正确。 注意: 瑞年以及不是瑞年要当心。 #include<iostream> using namespace std; int day(int month,int year); bool isrui(int year);//这两个包用于给其他包用 //剩下的包只给main函数用 bool isyear(int year){ if(year<=2059&&year>=1960){ return true; } else{ return false; } } bool ismonth(int month){ if(month<=12&&month>=1){ return true; } else{ return false; } } bool isday(int year,int month,int yourday){ if(yourday>day(month,year)||yourday==0){ return false; } else return true; } bool isrui(int year){ if ((year%4==0&&year%100!=0)||year%400==0){ return true; } else{ return false; } } int day(int month,int year){ if(month==0){ return 0; } if(month==1||month==3||month==5||month==7||month==8||month==10||month==12){ return 31; } else if(month==2&&isrui(year)){ return 29; } else if(month==2&&!isrui(year)){ return 28; } else{ return 30; } } void abc(int A,int B,int C){//核心函数 if(A<60) A+=2000; else if(A>=60) A+=1900; if(isyear(A)){ if(ismonth(B)){ if(isday(A, B, C)){ printf("%d-%02d-%02d\n",A,B,C); } } } } int main(){ int A,B,C; scanf("%d/%d/%d",&A,&B,&C); abc(A,B,C); abc(C,A,B); abc(C,B,A); }

优秀的个人博客,低调大师

ES 相似度算法设置(续)

Tuning BM25 One of the nice features of BM25 is that, unlike TF/IDF, it has two parameters that allow it to be tuned: k1 This parameter controls how quickly an increase in term frequency results in term-frequency saturation. The default value is 1.2. Lower values result in quicker saturation, and higher values in slower saturation. b This parameter controls how much effect field-length normalization should have.A value of 0.0disables normalization completely, and a value of 1.0normalizes fully. The default is 0.75. The practicalities of tuning BM25 are another matter. The default values fork1andbshould be suitable for most document collections, but the optimal values really depend on the collection. Finding good values for your collection is a matter of adjusting, checking, and adjusting again. The similarity algorithm can be set on a per-field basis.It’s just a matter of specifying the chosen algorithmin the field’s mapping: PUT /my_index { "mappings": { "doc": { "properties": { "title": { "type": "string", "similarity": "BM25" }, "body": { "type": "string", "similarity": "default" } } } } Thetitlefield uses BM25 similarity. Thebodyfield uses the default similarity (seeLucene’s Practical Scoring Function). Currently, it is not possible to change thesimilaritymapping for an existing field. You would need to reindex your data in order to do that. Configuring BM25 Configuring a similarity is muchlike configuring an analyzer. Custom similarities can be specified when creating an index. For instance: PUT /my_index { "settings": { "similarity": { "my_bm25": { "type": "BM25", "b": 0 } } }, "mappings": { "doc": { "properties": { "title": { "type": "string", "similarity": "my_bm25" }, "body": { "type": "string", "similarity": "BM25" } } } } } 参考:https://www.elastic.co/guide/en/elasticsearch/guide/current/changing-similarities.html 本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/6472828.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

【20160924】GOCVHelper MFC增强算法(5)

CStringExportListToExcel(CStringsExcelFile,CListCtrl*pList,CStringstrTitle) { CStringwarningStr; if(pList->GetItemCount()>0){ CDatabasedatabase; CStringsSql; CStringtableName=strTitle; //检索是否安装有Excel驱动"MicrosoftExcelDriver(*.xls)" CStringsDriver; sDriver=GetExcelDriver(); if(sDriver.IsEmpty()) { //没有发现Excel驱动 AfxMessageBox("没有安装Excel!\n请先安装Excel软件才能使用导出功能!"); returnNULL; } ///默认文件名 /*CStringsExcelFile; if(!GetDefaultXlsFileName(sExcelFile)) returnNULL;*/ //创建进行存取的字符串 sSql.Format("DRIVER={%s};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\"%s\";DBQ=%s",sDriver,sExcelFile,sExcelFile); //创建数据库(既Excel表格文件) if(database.OpenEx(sSql,CDatabase::noOdbcDialog)) { //创建表结构 inti; LVCOLUMNcolumnData; CStringcolumnName; intcolumnNum=0; CStringstrH; CStringstrV; sSql=""; strH=""; columnData.mask=LVCF_TEXT; columnData.cchTextMax=100; columnData.pszText=columnName.GetBuffer(100); for(i=0;pList->GetColumn(i,&columnData);i++) { if(i!=0) { sSql=sSql+","; strH=strH+","; } sSql=sSql+""+columnData.pszText+"TEXT"; strH=strH+""+columnData.pszText+""; } columnName.ReleaseBuffer(); columnNum=i; sSql="CREATETABLE"+tableName+"("+sSql+")"; database.ExecuteSQL(sSql); //插入数据项 intnItemIndex; for(nItemIndex=0;nItemIndex<pList->GetItemCount();nItemIndex++){ strV=""; for(i=0;i<columnNum;i++) { if(i!=0) { strV=strV+","; } strV=strV+"'"+pList->GetItemText(nItemIndex,i)+"'"; } sSql="INSERTINTO"+tableName +"("+strH+")" +"VALUES("+strV+")"; database.ExecuteSQL(sSql); } } //关闭数据库 database.Close(); returnsExcelFile; } } 图像处理生成了结果,如果需要保存为报表文件,或者想进一步存入数据库中,Excel都是非常好的选择。在这里集成了vc知识库中提供的代码。版权为 ////////////////////////////////////////////////////////////////////////////// //名称:GetExcelDriver //功能:获取ODBC中Excel驱动 //作者:徐景周(jingzhou_xu@163.net) //组织:未来工作室(FutureStudio) //日期:2002.9.1 ///////////////////////////////////////////////////////////////////////////// 使用的时候,只需要将生成的结果填入 CListCtrl 控件中,而后直接到处就可以。也就是把excel输出的问题变成了向 CListCtrl 控件输出的问题。同时代码中还提供了能够直接写到两个sheet中的方法,可供参考 来自为知笔记(Wiz) 目前方向:图像拼接融合、图像识别 联系方式:jsxyhelu@foxmail.com

优秀的个人博客,低调大师

【20160924】GOCVHelper MFC增强算法(2)

//创建或续写目录下的csv文件,填写“文件位置-分类”对 intwriteCsv(conststring&filename,constVector<pair<string,string>>srcVect,charseparator){ ofstreamfile(filename.c_str(),ofstream::app); if(!file) return0; for(inti=0;i<srcVect.size();i++){ file<<srcVect[i].first<<separator<<srcVect[i].second<<endl; } returnsrcVect.size(); } //读取目录下的csv文件,获得“文件位置-分类”对 vector<pair<string,string>>readCsv(conststring&filename,charseparator){ pair<string,string>apair; stringline,path,classlabel; vector<pair<string,string>>retVect; ifstreamfile(filename.c_str(),ifstream::in); if(!file) returnretVect; while(getline(file,line)){ stringstreamliness(line); getline(liness,path,separator); getline(liness,classlabel); if(!path.empty()&&!classlabel.empty()){ apair.first=path; apair.second=classlabel; retVect.push_back(apair); } } returnretVect; } csv文件是最为简单的带格式文件。这种格式在opencv的人脸识别教程中得到了使用,这里是扣的它的代码。 //获得ini文件中的值 CStringGetInitString(CStringName1,CStringName2){ charc[100]; memset(c,0,100); CStringcsCfgFilePath; GetModuleFileName(NULL,csCfgFilePath.GetBufferSetLength(MAX_PATH+1),MAX_PATH); csCfgFilePath.ReleaseBuffer(); intnPos=csCfgFilePath.ReverseFind('\\'); csCfgFilePath=csCfgFilePath.Left(nPos); csCfgFilePath+="\\Config"; BOOLbr=GetPrivateProfileString(Name1,Name2,"0",c,100,csCfgFilePath); CStringrstr; rstr.Format("%s",c); returnrstr; } //写入ini问价中的值 voidWriteInitString(CStringName1,CStringName2,CStringstrvalue){ CStringcsCfgFilePath; GetModuleFileName(NULL,csCfgFilePath.GetBufferSetLength(MAX_PATH+1),MAX_PATH); csCfgFilePath.ReleaseBuffer(); intnPos=csCfgFilePath.ReverseFind('\\'); csCfgFilePath=csCfgFilePath.Left(nPos); csCfgFilePath+="\\Config"; BOOLbr=WritePrivateProfileString(Name1,Name2,strvalue,csCfgFilePath); if(!br) TRACE("savewrong"); } 这两个函数主要是用来保存和修改配置文件的。通过直接将配置文件写入.ini中达到这个目标。 来自为知笔记(Wiz) 目前方向:图像拼接融合、图像识别 联系方式:jsxyhelu@foxmail.com

优秀的个人博客,低调大师

【20160924】GOCVHelper MFC增强算法(3)

//获得当前目录路径 staticCStringGetLocalPath(){ CStringcsCfgFilePath; GetModuleFileName(NULL,csCfgFilePath.GetBufferSetLength(MAX_PATH+1),MAX_PATH); csCfgFilePath.ReleaseBuffer(); intnPos=csCfgFilePath.ReverseFind('\\'); csCfgFilePath=csCfgFilePath.Left(nPos); returncsCfgFilePath; } //获得.exe路径 staticCStringGetExePath() { CStringstrPath; GetModuleFileName(NULL,strPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH); strPath.ReleaseBuffer(); returnstrPath; } MFC程序涉及的时候存在一个问题,就是某些操作会修改自动"当前路径"的值。这两个函数能够获得当前的路径。 //开机自动运行 staticBOOLSetAutoRun(CStringstrPath,boolflag) { CStringstr; HKEYhRegKey; BOOLbResult; str=_T("Software\\Microsoft\\Windows\\CurrentVersion\\Run"); if(RegOpenKey(HKEY_LOCAL_MACHINE,str,&hRegKey)!=ERROR_SUCCESS) bResult=FALSE; else { _splitpath(strPath.GetBuffer(0),NULL,NULL,str.GetBufferSetLength(MAX_PATH+1),NULL); strPath.ReleaseBuffer(); str.ReleaseBuffer();//str是键的名字 if(flag){ if(::RegSetValueEx(hRegKey,str,0,REG_SZ,(CONSTBYTE*)strPath.GetBuffer(0),strPath.GetLength())!=ERROR_SUCCESS) bResult=FALSE; else bResult=TRUE; }else{ if(::RegDeleteValue(hRegKey,str)!=ERROR_SUCCESS) bResult=FALSE; else bResult=TRUE; } strPath.ReleaseBuffer(); } returnbResult; } 这个无需更多说明。 来自为知笔记(Wiz) 目前方向:图像拼接融合、图像识别 联系方式:jsxyhelu@foxmail.com

优秀的个人博客,低调大师

【20160924】GOCVHelper MFC增强算法(4)

//string替换 voidstring_replace(string&strBig,conststring&strsrc,conststring&strdst) { string::size_typepos=0; string::size_typesrclen=strsrc.size(); string::size_typedstlen=strdst.size(); while((pos=strBig.find(strsrc,pos))!=string::npos) { strBig.replace(pos,srclen,strdst); pos+=dstlen; } } 字符串操作一直都是重要的基础操作。在图像处理的过程中,涉及到文件名等变换都需要字符串操作。string_replace中能够成块地换字符。虽然在std中可能已经有相关函数,不过既然我自己的这个用的比较熟悉,就是使用了。 //C++的spilt函数 voidSplitString(conststring&s,vector<string>&v,conststring&c){ std::string::size_typepos1,pos2; pos2=s.find(c); pos1=0; while(std::string::npos!=pos2){ v.push_back(s.substr(pos1,pos2-pos1)); pos1=pos2+c.size(); pos2=s.find(c,pos1); } if(pos1!=s.length()) v.push_back(s.substr(pos1)); } 依然是增强了std中的相关功能,实际使用的时候非常有用。 //!通过文件夹名称获取文件名,不包括后缀 voidgetFileName(conststring&filepath,string&name,string&lastname){ vector<string>spilt_path; SplitString(filepath,spilt_path,"\\"); intspiltsize=spilt_path.size(); stringfilename=""; if(spiltsize!=0){ filename=spilt_path[spiltsize-1]; vector<string>spilt_name; SplitString(filename,spilt_name,"."); intname_size=spilt_name.size(); if(name_size!=0) name=spilt_name[0]; lastname=spilt_name[name_size-1]; } } 前面的函数getfiles能够获得文件的真实路径。那么getFileName能够进一步处理,直接获得图片的名称。很多时候,图片读取了,需要处理一下,这个都是需要的。 来自为知笔记(Wiz) 目前方向:图像拼接融合、图像识别 联系方式:jsxyhelu@foxmail.com

资源下载

更多资源
Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册