Repository: zhousoft/TsingHuaDataStructOj Branch: master Commit: ed5687fca61f Files: 45 Total size: 121.2 KB Directory structure: gitextract_8bul494k/ ├── .gitignore ├── BinaryTreeRebuild/ │ ├── BinaryTreeRebuild.pro │ ├── binaryTreeRebuild.cpp │ ├── deployment.pri │ └── 题目.txt ├── BroadCast/ │ ├── BroadCast.pro │ ├── broadcast.cpp │ ├── deployment.pri │ └── 题目.txt ├── DataStructOj.pro ├── Deduplicate/ │ ├── Deduplicate.pro │ ├── Depulicate.cpp │ ├── deployment.pri │ └── 题目.txt ├── KahnTopsort/ │ ├── KahnTopsort.pro │ ├── TSP.txt │ ├── deployment.pri │ └── kahntopsortTSP.cpp ├── LightHouse/ │ ├── LightHouse.cpp │ ├── LightHouse.pro │ └── deployment.pri ├── README.md ├── RangeSearch/ │ ├── RangeSearch.cpp │ ├── RangeSearch.pro │ ├── deployment.pri │ └── 题目.txt ├── TSP/ │ ├── TSP.cpp │ ├── TSP.pro │ ├── TSP.txt │ └── deployment.pri ├── Toy/ │ ├── Toy.pro │ ├── deployment.pri │ └── toy.cpp ├── Train/ │ ├── Train.pro │ ├── deployment.pri │ └── train.cpp ├── Tunel/ │ ├── Tunel.cpp │ ├── Tunel.pro │ └── deployment.pri ├── Zuma2/ │ ├── Zuma2.cpp │ ├── Zuma2.pro │ └── deployment.pri └── testDeom/ ├── deployment.pri ├── main.cpp └── testDeom.pro ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ # C++ objects and libs *.slo *.lo *.o *.a *.la *.lai *.so *.dll *.dylib # Qt-es /.qmake.cache /.qmake.stash *.pro.user *.pro.user.* *.qbs.user *.qbs.user.* *.moc moc_*.cpp qrc_*.cpp ui_*.h Makefile* *build-* # QtCreator *.autosave # QtCtreator Qml *.qmlproject.user *.qmlproject.user.* # QtCtreator CMake CMakeLists.txt.user ================================================ FILE: BinaryTreeRebuild/BinaryTreeRebuild.pro ================================================ TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt SOURCES += \ binaryTreeRebuild.cpp include(deployment.pri) qtcAddDeployment() DISTFILES += \ Ŀ.txt ================================================ FILE: BinaryTreeRebuild/binaryTreeRebuild.cpp ================================================ #include #include #define MAX 10000001 using namespace std; int preOder[MAX]; int postOder[MAX]; char buffer[MAX];//缓冲区,减少IO操作,缩短读入数据时间 int findPos(int source[],int len,int key) { int count; for(count = 0;count < len;count++) { if(source[count] == key) { return count; } } } void rebuild(int preTree[],int postTree[],int len) { int limit; if(len == 1) { printf("%d ",preTree[0]); return; } limit = findPos(postTree,len,preTree[1]);//找到左右子树分界点 rebuild(preTree+1,postTree,limit+1); printf("%d ",preTree[0]); rebuild(preTree+limit+1+1,postTree+limit+1,len - limit -1-1); } int main() { int n; scanf("%d",&n); setvbuf(stdin,buffer,_IOFBF,MAX); for(int i=0;i #include #define MAX 1000000 using namespace std; //使用邻接表存储图 struct EdgeNode /*边表结点*/ { int adjvex; //存储邻接顶点对应下标 struct EdgeNode *nex;//指向下一个邻接点 }; struct VertexNode //顶点表结点 { int castType;//广播状态 1 bool isVisted; int data;//数据 EdgeNode *firstEdge;//边表头指针 }; struct Graph { VertexNode adjList[MAX];//顶点数组 int numVertexs;//顶点数 int numEdges;//边数 }graph; VertexNode queue[MAX];//模拟队列 int head=0; int tail =0; int queuesize=0; int main() { int n,m; scanf("%d%d",&n,&m); graph.numVertexs = n; graph.numEdges = m; if(m<=1) { printf("1"); return 0; } for(int i=0;iadjvex = b-1;//下标从0开始 eb->adjvex = a-1; ea->nex = NULL; eb->nex = NULL; EdgeNode *pa = graph.adjList[a-1].firstEdge;//无向图 一条边更新两个结点 EdgeNode *pb = graph.adjList[b-1].firstEdge; if( pa == NULL) { graph.adjList[a-1].firstEdge = ea; } else { while( pa->nex != NULL) { pa = pa->nex; } pa->nex = ea; } if( pb == NULL) { graph.adjList[b-1].firstEdge = eb; } else { while( pb->nex != NULL) { pb = pb->nex; } pb->nex = eb; } } //BFS for(int i=0;iadjvex].isVisted)//结点未访问过 { graph.adjList[pn->adjvex].isVisted = true; graph.adjList[pn->adjvex].castType = -node.castType;//安装不同类型广播 queue[tail++] = graph.adjList[pn->adjvex];//入队 queuesize++; } else { if(node.castType == graph.adjList[pn->adjvex].castType) { printf("-1");//不可行 return 0; } } pn = pn->nex; } } } } printf("1");//可行 return 0; } ================================================ FILE: BroadCast/deployment.pri ================================================ # This file was generated by an application wizard of Qt Creator. # The code below handles deployment to Android and Maemo, aswell as copying # of the application data to shadow build directories on desktop. # It is recommended not to modify this file, since newer versions of Qt Creator # may offer an updated version of it. defineTest(qtcAddDeployment) { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} greaterThan(QT_MAJOR_VERSION, 4) { itemsources = $${item}.files } else { itemsources = $${item}.sources } $$itemsources = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath= $$eval($${deploymentfolder}.target) export($$itemsources) export($$itempath) DEPLOYMENT += $$item } MAINPROFILEPWD = $$PWD android-no-sdk { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = /data/user/qt/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } target.path = /data/user/qt export(target.path) INSTALLS += target } else:android { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = /assets/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } x86 { target.path = /libs/x86 } else: armeabi-v7a { target.path = /libs/armeabi-v7a } else { target.path = /libs/armeabi } export(target.path) INSTALLS += target } else:win32 { copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, /, \\) sourcePathSegments = $$split(source, \\) target = $$OUT_PWD/$$eval($${deploymentfolder}.target)/$$last(sourcePathSegments) target = $$replace(target, /, \\) target ~= s,\\\\\\.?\\\\,\\, !isEqual(source,$$target) { !isEmpty(copyCommand):copyCommand += && isEqual(QMAKE_DIR_SEP, \\) { copyCommand += $(COPY_DIR) \"$$source\" \"$$target\" } else { source = $$replace(source, \\\\, /) target = $$OUT_PWD/$$eval($${deploymentfolder}.target) target = $$replace(target, \\\\, /) copyCommand += test -d \"$$target\" || mkdir -p \"$$target\" && cp -r \"$$source\" \"$$target\" } } } !isEmpty(copyCommand) { copyCommand = @echo Copying application data... && $$copyCommand copydeploymentfolders.commands = $$copyCommand first.depends = $(first) copydeploymentfolders export(first.depends) export(copydeploymentfolders.commands) QMAKE_EXTRA_TARGETS += first copydeploymentfolders } } else:ios { copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, \\\\, /) target = $CODESIGNING_FOLDER_PATH/$$eval($${deploymentfolder}.target) target = $$replace(target, \\\\, /) sourcePathSegments = $$split(source, /) targetFullPath = $$target/$$last(sourcePathSegments) targetFullPath ~= s,/\\.?/,/, !isEqual(source,$$targetFullPath) { !isEmpty(copyCommand):copyCommand += && copyCommand += mkdir -p \"$$target\" copyCommand += && cp -r \"$$source\" \"$$target\" } } !isEmpty(copyCommand) { copyCommand = echo Copying application data... && $$copyCommand !isEmpty(QMAKE_POST_LINK): QMAKE_POST_LINK += ";" QMAKE_POST_LINK += "$$copyCommand" export(QMAKE_POST_LINK) } } else:unix { maemo5 { desktopfile.files = $${TARGET}.desktop desktopfile.path = /usr/share/applications/hildon icon.files = $${TARGET}64.png icon.path = /usr/share/icons/hicolor/64x64/apps } else:!isEmpty(MEEGO_VERSION_MAJOR) { desktopfile.files = $${TARGET}_harmattan.desktop desktopfile.path = /usr/share/applications icon.files = $${TARGET}80.png icon.path = /usr/share/icons/hicolor/80x80/apps } else { # Assumed to be a Desktop Unix copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, \\\\, /) macx { target = $$OUT_PWD/$${TARGET}.app/Contents/Resources/$$eval($${deploymentfolder}.target) } else { target = $$OUT_PWD/$$eval($${deploymentfolder}.target) } target = $$replace(target, \\\\, /) sourcePathSegments = $$split(source, /) targetFullPath = $$target/$$last(sourcePathSegments) targetFullPath ~= s,/\\.?/,/, !isEqual(source,$$targetFullPath) { !isEmpty(copyCommand):copyCommand += && copyCommand += $(MKDIR) \"$$target\" copyCommand += && $(COPY_DIR) \"$$source\" \"$$target\" } } !isEmpty(copyCommand) { copyCommand = @echo Copying application data... && $$copyCommand copydeploymentfolders.commands = $$copyCommand first.depends = $(first) copydeploymentfolders export(first.depends) export(copydeploymentfolders.commands) QMAKE_EXTRA_TARGETS += first copydeploymentfolders } } !isEmpty(target.path) { installPrefix = $${target.path} } else { installPrefix = /opt/$${TARGET} } for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = $${installPrefix}/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } !isEmpty(desktopfile.path) { export(icon.files) export(icon.path) export(desktopfile.files) export(desktopfile.path) INSTALLS += icon desktopfile } isEmpty(target.path) { target.path = $${installPrefix}/bin export(target.path) } INSTALLS += target } export (ICON) export (INSTALLS) export (DEPLOYMENT) export (LIBS) export (QMAKE_EXTRA_TARGETS) } ================================================ FILE: BroadCast/题目.txt ================================================ 无线广播(Broadcast) 描述 某广播公司要在一个地区架设无线广播发射装置。该地区共有n个小镇,每个小镇都要安装一台发射机并播放各自的节目。 不过,该公司只获得了FM104.2和FM98.6两个波段的授权,而使用同一波段的发射机会互相干扰。已知每台发射机的信号覆盖范围是以它为圆心,20km为半径的圆形区域,因此,如果距离小于20km的两个小镇使用同样的波段,那么它们就会由于波段干扰而无法正常收听节目。现在给出这些距离小于20km的小镇列表,试判断该公司能否使得整个地区的居民正常听到广播节目。 输入 第一行为两个整数n,m,分别为小镇的个数以及接下来小于20km的小镇对的数目。 接下来的m行,每行2个整数,表示两个小镇的距离小于20km(编号从1开始)。 输出 如果能够满足要求,输出1,否则输出-1。 输入样例 4 3 1 2 1 3 2 4 输出样例 1 限制 1 ≤ n ≤ 10000 1 ≤ m ≤ 30000 不需要考虑给定的20km小镇列表的空间特性,比如是否满足三角不等式,是否利用传递性可以推出更多的信息等等。 时间:2 sec 空间:256MB 提示 BFS ================================================ FILE: DataStructOj.pro ================================================ TEMPLATE = subdirs SUBDIRS += \ RangeSearch \ LightHouse \ Zuma2 \ Train \ Tunel \ BinaryTreeRebuild \ testDeom \ TSP \ KahnTopsort \ Deduplicate \ BroadCast \ Toy ================================================ FILE: Deduplicate/Deduplicate.pro ================================================ TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt SOURCES += \ Depulicate.cpp include(deployment.pri) qtcAddDeployment() HEADERS += DISTFILES += \ Ŀ.txt ================================================ FILE: Deduplicate/Depulicate.cpp ================================================ #include #include #include #include #define MAX 400003 char buffer[1000000];//缓冲区,减少IO操作,缩短读入数据时间 using namespace std; struct HashNode { HashNode() { memset(str,'\0',41); isEmpty = true; isDepulicate = false; } char str[41];//保存字符串 bool isEmpty;//是否为空 bool isDepulicate;//是否已有重复 }; struct HashTable { HashNode bullet[MAX];//存储结点的桶数组 unsigned int hash(char *str, int len); bool put(char *str,int len);//添加元素 char *depulist[MAX]; int depulen;//重复字符串数 }; unsigned int HashTable::hash(char *str,int len)//散列函数 { unsigned int keyValue = 0; /* for(int i=0;idepulen = 0; scanf("%d",&n); setvbuf(stdin,buffer,_IOFBF,1000000); for(int i=0;iput(str,strlen(str)); } if(hashtable->depulen > 0) { for(int i=0;idepulen;i++) { printf("%s\n",hashtable->depulist[i]); } } return 0; } ================================================ FILE: Deduplicate/deployment.pri ================================================ # This file was generated by an application wizard of Qt Creator. # The code below handles deployment to Android and Maemo, aswell as copying # of the application data to shadow build directories on desktop. # It is recommended not to modify this file, since newer versions of Qt Creator # may offer an updated version of it. defineTest(qtcAddDeployment) { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} greaterThan(QT_MAJOR_VERSION, 4) { itemsources = $${item}.files } else { itemsources = $${item}.sources } $$itemsources = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath= $$eval($${deploymentfolder}.target) export($$itemsources) export($$itempath) DEPLOYMENT += $$item } MAINPROFILEPWD = $$PWD android-no-sdk { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = /data/user/qt/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } target.path = /data/user/qt export(target.path) INSTALLS += target } else:android { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = /assets/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } x86 { target.path = /libs/x86 } else: armeabi-v7a { target.path = /libs/armeabi-v7a } else { target.path = /libs/armeabi } export(target.path) INSTALLS += target } else:win32 { copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, /, \\) sourcePathSegments = $$split(source, \\) target = $$OUT_PWD/$$eval($${deploymentfolder}.target)/$$last(sourcePathSegments) target = $$replace(target, /, \\) target ~= s,\\\\\\.?\\\\,\\, !isEqual(source,$$target) { !isEmpty(copyCommand):copyCommand += && isEqual(QMAKE_DIR_SEP, \\) { copyCommand += $(COPY_DIR) \"$$source\" \"$$target\" } else { source = $$replace(source, \\\\, /) target = $$OUT_PWD/$$eval($${deploymentfolder}.target) target = $$replace(target, \\\\, /) copyCommand += test -d \"$$target\" || mkdir -p \"$$target\" && cp -r \"$$source\" \"$$target\" } } } !isEmpty(copyCommand) { copyCommand = @echo Copying application data... && $$copyCommand copydeploymentfolders.commands = $$copyCommand first.depends = $(first) copydeploymentfolders export(first.depends) export(copydeploymentfolders.commands) QMAKE_EXTRA_TARGETS += first copydeploymentfolders } } else:ios { copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, \\\\, /) target = $CODESIGNING_FOLDER_PATH/$$eval($${deploymentfolder}.target) target = $$replace(target, \\\\, /) sourcePathSegments = $$split(source, /) targetFullPath = $$target/$$last(sourcePathSegments) targetFullPath ~= s,/\\.?/,/, !isEqual(source,$$targetFullPath) { !isEmpty(copyCommand):copyCommand += && copyCommand += mkdir -p \"$$target\" copyCommand += && cp -r \"$$source\" \"$$target\" } } !isEmpty(copyCommand) { copyCommand = echo Copying application data... && $$copyCommand !isEmpty(QMAKE_POST_LINK): QMAKE_POST_LINK += ";" QMAKE_POST_LINK += "$$copyCommand" export(QMAKE_POST_LINK) } } else:unix { maemo5 { desktopfile.files = $${TARGET}.desktop desktopfile.path = /usr/share/applications/hildon icon.files = $${TARGET}64.png icon.path = /usr/share/icons/hicolor/64x64/apps } else:!isEmpty(MEEGO_VERSION_MAJOR) { desktopfile.files = $${TARGET}_harmattan.desktop desktopfile.path = /usr/share/applications icon.files = $${TARGET}80.png icon.path = /usr/share/icons/hicolor/80x80/apps } else { # Assumed to be a Desktop Unix copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, \\\\, /) macx { target = $$OUT_PWD/$${TARGET}.app/Contents/Resources/$$eval($${deploymentfolder}.target) } else { target = $$OUT_PWD/$$eval($${deploymentfolder}.target) } target = $$replace(target, \\\\, /) sourcePathSegments = $$split(source, /) targetFullPath = $$target/$$last(sourcePathSegments) targetFullPath ~= s,/\\.?/,/, !isEqual(source,$$targetFullPath) { !isEmpty(copyCommand):copyCommand += && copyCommand += $(MKDIR) \"$$target\" copyCommand += && $(COPY_DIR) \"$$source\" \"$$target\" } } !isEmpty(copyCommand) { copyCommand = @echo Copying application data... && $$copyCommand copydeploymentfolders.commands = $$copyCommand first.depends = $(first) copydeploymentfolders export(first.depends) export(copydeploymentfolders.commands) QMAKE_EXTRA_TARGETS += first copydeploymentfolders } } !isEmpty(target.path) { installPrefix = $${target.path} } else { installPrefix = /opt/$${TARGET} } for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = $${installPrefix}/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } !isEmpty(desktopfile.path) { export(icon.files) export(icon.path) export(desktopfile.files) export(desktopfile.path) INSTALLS += icon desktopfile } isEmpty(target.path) { target.path = $${installPrefix}/bin export(target.path) } INSTALLS += target } export (ICON) export (INSTALLS) export (DEPLOYMENT) export (LIBS) export (QMAKE_EXTRA_TARGETS) } ================================================ FILE: Deduplicate/题目.txt ================================================ 重名剔除(Deduplicate) Description Mr. Epicure is compiling an encyclopedia of food. He had collected a long list of candidates nominated by several belly-gods. As candidates in list are nominated by several people, duplication of name is inevitable. Mr. Epicure pay you a visit for help. He request you to remove all duplication, which is thought an easy task for you. So please hold this opportunity to be famous to all belly-gods. Input 1 integer in fist line to denote the length of nomination list. In following n lines, each nomination is given in each line. Output All the duplicated nomination (only output once if duplication appears more multiple times), which is sorted in the order that duplication appears firstly. Example Input 10 brioche camembert cappelletti savarin cheddar cappelletti tortellni croissant brioche mapotoufu Output cappelletti brioche Restrictions 1 < n < 6 * 10^5 All nominations are only in lowercase. No other character is included. Length of each item is not greater than 40. Time: 2 sec Memory: 256 MB Hints Hash 描述 Epicure先生正在编撰一本美食百科全书。为此,他已从众多的同好者那里搜集到了一份冗长的美食提名清单。既然源自多人之手,其中自然不乏重复的提名,故必须予以筛除。Epicure先生因此登门求助,并认定此事对你而言不过是“一碟小菜”,相信你不会错过在美食界扬名立万的这一良机 输入 第1行为1个整数n,表示提名清单的长度。以下n行各为一项提名 输出 所有出现重复的提名(多次重复的仅输出一次),且以其在原清单中首次出现重复(即第二次出现)的位置为序 样例 见英文题面 限制 1 < n < 6 * 10^5 提名均由小写字母组成,不含其它字符,且每项长度不超过40 时间:2 sec 空间:256 MB 提示 散列 ================================================ FILE: KahnTopsort/KahnTopsort.pro ================================================ TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt SOURCES += \ kahntopsortTSP.cpp include(deployment.pri) qtcAddDeployment() DISTFILES += \ TSP.txt ================================================ FILE: KahnTopsort/TSP.txt ================================================ Description Shrek is a postman working in the mountain, whose routine work is sending mail to n villages. Unfortunately, road between villages is out of repair for long time, such that some road is one-way road. There are even some villages that can’t be reached from any other village. In such a case, we only hope as many villages can receive mails as possible. Shrek hopes to choose a village A as starting point (He will be air-dropped to this location), then pass by as many villages as possible. Finally, Shrek will arrived at village B. In the travelling process, each villages is only passed by once. You should help Shrek to design the travel route. Input There are 2 integers, n and m, in first line. Stand for number of village and number of road respectively. In the following m line, m road is given by identity of villages on two terminals. From v1 to v2. The identity of village is in range [1, n]. Output Output maximum number of villages Shrek can pass by. Example Input 4 3 1 4 2 4 4 3 Output 3 Restrictions 1 <= n <= 1,000,000 0 <= m <= 1,000,000 These is no loop road in the input. Time: 2 sec Memory: 256 MB Hints Topological sorting 描述 Shrek是一个大山里的邮递员,每天负责给所在地区的n个村庄派发信件。但杯具的是,由于道路狭窄,年久失修,村庄间的道路都只能单向通过,甚至有些村庄无法从任意一个村庄到达。这样我们只能希望尽可能多的村庄可以收到投递的信件。 Shrek希望知道如何选定一个村庄A作为起点(我们将他空投到该村庄),依次经过尽可能多的村庄,路途中的每个村庄都经过仅一次,最终到达终点村庄B,完成整个送信过程。这个任务交给你来完成。 输入 第一行包括两个整数n,m,分别表示村庄的个数以及可以通行的道路的数目。 以下共m行,每行用两个整数v1和v2表示一条道路,两个整数分别为道路连接的村庄号,道路的方向为从v1至v2,n个村庄编号为[1, n]。 输出 输出一个数字,表示符合条件的最长道路经过的村庄数。 样例 见英文题面 限制 1 ≤ n ≤ 1,000,000 0 ≤ m ≤ 1,000,000 输入保证道路之间没有形成环 时间:2 sec 空间:256 MB 提示 拓扑排序 ================================================ FILE: KahnTopsort/deployment.pri ================================================ # This file was generated by an application wizard of Qt Creator. # The code below handles deployment to Android and Maemo, aswell as copying # of the application data to shadow build directories on desktop. # It is recommended not to modify this file, since newer versions of Qt Creator # may offer an updated version of it. defineTest(qtcAddDeployment) { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} greaterThan(QT_MAJOR_VERSION, 4) { itemsources = $${item}.files } else { itemsources = $${item}.sources } $$itemsources = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath= $$eval($${deploymentfolder}.target) export($$itemsources) export($$itempath) DEPLOYMENT += $$item } MAINPROFILEPWD = $$PWD android-no-sdk { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = /data/user/qt/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } target.path = /data/user/qt export(target.path) INSTALLS += target } else:android { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = /assets/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } x86 { target.path = /libs/x86 } else: armeabi-v7a { target.path = /libs/armeabi-v7a } else { target.path = /libs/armeabi } export(target.path) INSTALLS += target } else:win32 { copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, /, \\) sourcePathSegments = $$split(source, \\) target = $$OUT_PWD/$$eval($${deploymentfolder}.target)/$$last(sourcePathSegments) target = $$replace(target, /, \\) target ~= s,\\\\\\.?\\\\,\\, !isEqual(source,$$target) { !isEmpty(copyCommand):copyCommand += && isEqual(QMAKE_DIR_SEP, \\) { copyCommand += $(COPY_DIR) \"$$source\" \"$$target\" } else { source = $$replace(source, \\\\, /) target = $$OUT_PWD/$$eval($${deploymentfolder}.target) target = $$replace(target, \\\\, /) copyCommand += test -d \"$$target\" || mkdir -p \"$$target\" && cp -r \"$$source\" \"$$target\" } } } !isEmpty(copyCommand) { copyCommand = @echo Copying application data... && $$copyCommand copydeploymentfolders.commands = $$copyCommand first.depends = $(first) copydeploymentfolders export(first.depends) export(copydeploymentfolders.commands) QMAKE_EXTRA_TARGETS += first copydeploymentfolders } } else:ios { copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, \\\\, /) target = $CODESIGNING_FOLDER_PATH/$$eval($${deploymentfolder}.target) target = $$replace(target, \\\\, /) sourcePathSegments = $$split(source, /) targetFullPath = $$target/$$last(sourcePathSegments) targetFullPath ~= s,/\\.?/,/, !isEqual(source,$$targetFullPath) { !isEmpty(copyCommand):copyCommand += && copyCommand += mkdir -p \"$$target\" copyCommand += && cp -r \"$$source\" \"$$target\" } } !isEmpty(copyCommand) { copyCommand = echo Copying application data... && $$copyCommand !isEmpty(QMAKE_POST_LINK): QMAKE_POST_LINK += ";" QMAKE_POST_LINK += "$$copyCommand" export(QMAKE_POST_LINK) } } else:unix { maemo5 { desktopfile.files = $${TARGET}.desktop desktopfile.path = /usr/share/applications/hildon icon.files = $${TARGET}64.png icon.path = /usr/share/icons/hicolor/64x64/apps } else:!isEmpty(MEEGO_VERSION_MAJOR) { desktopfile.files = $${TARGET}_harmattan.desktop desktopfile.path = /usr/share/applications icon.files = $${TARGET}80.png icon.path = /usr/share/icons/hicolor/80x80/apps } else { # Assumed to be a Desktop Unix copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, \\\\, /) macx { target = $$OUT_PWD/$${TARGET}.app/Contents/Resources/$$eval($${deploymentfolder}.target) } else { target = $$OUT_PWD/$$eval($${deploymentfolder}.target) } target = $$replace(target, \\\\, /) sourcePathSegments = $$split(source, /) targetFullPath = $$target/$$last(sourcePathSegments) targetFullPath ~= s,/\\.?/,/, !isEqual(source,$$targetFullPath) { !isEmpty(copyCommand):copyCommand += && copyCommand += $(MKDIR) \"$$target\" copyCommand += && $(COPY_DIR) \"$$source\" \"$$target\" } } !isEmpty(copyCommand) { copyCommand = @echo Copying application data... && $$copyCommand copydeploymentfolders.commands = $$copyCommand first.depends = $(first) copydeploymentfolders export(first.depends) export(copydeploymentfolders.commands) QMAKE_EXTRA_TARGETS += first copydeploymentfolders } } !isEmpty(target.path) { installPrefix = $${target.path} } else { installPrefix = /opt/$${TARGET} } for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = $${installPrefix}/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } !isEmpty(desktopfile.path) { export(icon.files) export(icon.path) export(desktopfile.files) export(desktopfile.path) INSTALLS += icon desktopfile } isEmpty(target.path) { target.path = $${installPrefix}/bin export(target.path) } INSTALLS += target } export (ICON) export (INSTALLS) export (DEPLOYMENT) export (LIBS) export (QMAKE_EXTRA_TARGETS) } ================================================ FILE: KahnTopsort/kahntopsortTSP.cpp ================================================ #include #include #include #define MAX 1000000 #define GETMAX(x,y) ((x) > (y) ? (x):(y)) using namespace std; //使用邻接表存储图 struct EdgeNode /*边表结点*/ { int adjvex; //存储邻接顶点对应下标 int length;//到该结点路径长度 struct EdgeNode *nex;//指向下一个邻接点 }; struct VertexNode //顶点表结点 { int in; //顶点入度 int data;//数据 int length;//到该结点路径长度 EdgeNode *firstEdge;//边表头指针 }; struct Graph { VertexNode adjList[MAX];//顶点数组 int numVertexs;//顶点数 int numEdges;//边数 }graph; int maxLength = 1; VertexNode topSort[MAX];//保存拓扑排序结果 int main() { int n,m,a,b; scanf("%d%d",&n,&m); graph.numEdges = m; graph.numVertexs = n; for(int i=0;iadjvex = b-1;//数组下标从0开始 graph.adjList[b-1].in++;//b结点入度加1 e->nex = NULL; EdgeNode *p = graph.adjList[a-1].firstEdge; if(p == NULL) { graph.adjList[a-1].firstEdge = e; } else { while (p->nex != NULL) { p = p->nex; } p->nex = e; } } int stack[MAX];//拓扑排序时保存入度为0的结点堆栈 int stk[MAX];//保存初始入度为0结点 int top = 0,index,num=0,t=0; EdgeNode *e; for(int i=0;inex)//遍历该结点的边表 { int tempindex = e->adjvex; //动态规划-更新其后继结点的最大路径长度 graph.adjList[tempindex].length = GETMAX(graph.adjList[index].length+1, graph.adjList[tempindex].length); maxLength = GETMAX(graph.adjList[tempindex].length,maxLength); graph.adjList[tempindex].in--;//将邻接点的入度减1 if(graph.adjList[tempindex].in == 0) { stack[top++] = tempindex;//入度为0入栈 } } } printf("%d",maxLength); return 0; } ================================================ FILE: LightHouse/LightHouse.cpp ================================================ #include #include #define MAX 1000001 int point_x[MAX]; int point_y[MAX]; int tempL[MAX]; int tempR[MAX]; char buffer[10000];//缓冲区,减少IO操作,缩短读入数据时间 long sum = 0; using namespace std; void quickSort(int *array_x,int* array_y,int l,int r) { if(l=temp) j--; if(itempR[j])//题意各点互异,不会有相等情况 { array[k] = tempR[j++];//x大y小 不符合条件 } else { array[k] = tempL[i++]; sum += n2 - j; } } while(i>1); MergeSort(array,l,mid); MergeSort(array,mid+1,r); Merge(array,l,mid,r); } int main() { int n; scanf("%d",&n); setvbuf(stdin,buffer,_IOFBF,10000); for(int i=0;i #include #include using namespace std; int cmp(const void*a, const void *b) { return *((int *)a) - *((int*)b); } int binarySearch(int *array, int e, int lo, int hi, int &flag)//二分查找,左开右闭-返回最接近的 { int mid; flag = 0; while (lo < hi) { mid = (lo + hi)>>1; // (e> pointNum >> cmpNum; int* array = new int[pointNum]; int* leftArray = new int[cmpNum]; int* rightArray = new int[cmpNum]; for (int i = 0; i < pointNum; i++) scanf("%d",&array[i]); for (int i = 0; i < cmpNum; i++) scanf("%d %d",&leftArray[i],&rightArray[i]); qsort(array, pointNum, sizeof(int), cmp);//调用系统快排 while (cmpNum-- > 0) { int tem1, tem2,temflag; if (leftArray[count] > array[pointNum - 1] || rightArray[count] < array[0]) { printf("0\n"); } else { tem1 = binarySearch(array, leftArray[count], 0, pointNum,temflag); if(temflag == 1) { tem1--; } tem2 = binarySearch(array, rightArray[count], 0, pointNum,temflag); printf("%d\n",tem2 - tem1); } count++; } return 0; } ================================================ FILE: RangeSearch/RangeSearch.pro ================================================ TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt SOURCES += \ RangeSearch.cpp include(deployment.pri) qtcAddDeployment() ================================================ FILE: RangeSearch/deployment.pri ================================================ # This file was generated by an application wizard of Qt Creator. # The code below handles deployment to Android and Maemo, aswell as copying # of the application data to shadow build directories on desktop. # It is recommended not to modify this file, since newer versions of Qt Creator # may offer an updated version of it. defineTest(qtcAddDeployment) { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} greaterThan(QT_MAJOR_VERSION, 4) { itemsources = $${item}.files } else { itemsources = $${item}.sources } $$itemsources = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath= $$eval($${deploymentfolder}.target) export($$itemsources) export($$itempath) DEPLOYMENT += $$item } MAINPROFILEPWD = $$PWD android-no-sdk { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = /data/user/qt/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } target.path = /data/user/qt export(target.path) INSTALLS += target } else:android { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = /assets/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } x86 { target.path = /libs/x86 } else: armeabi-v7a { target.path = /libs/armeabi-v7a } else { target.path = /libs/armeabi } export(target.path) INSTALLS += target } else:win32 { copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, /, \\) sourcePathSegments = $$split(source, \\) target = $$OUT_PWD/$$eval($${deploymentfolder}.target)/$$last(sourcePathSegments) target = $$replace(target, /, \\) target ~= s,\\\\\\.?\\\\,\\, !isEqual(source,$$target) { !isEmpty(copyCommand):copyCommand += && isEqual(QMAKE_DIR_SEP, \\) { copyCommand += $(COPY_DIR) \"$$source\" \"$$target\" } else { source = $$replace(source, \\\\, /) target = $$OUT_PWD/$$eval($${deploymentfolder}.target) target = $$replace(target, \\\\, /) copyCommand += test -d \"$$target\" || mkdir -p \"$$target\" && cp -r \"$$source\" \"$$target\" } } } !isEmpty(copyCommand) { copyCommand = @echo Copying application data... && $$copyCommand copydeploymentfolders.commands = $$copyCommand first.depends = $(first) copydeploymentfolders export(first.depends) export(copydeploymentfolders.commands) QMAKE_EXTRA_TARGETS += first copydeploymentfolders } } else:ios { copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, \\\\, /) target = $CODESIGNING_FOLDER_PATH/$$eval($${deploymentfolder}.target) target = $$replace(target, \\\\, /) sourcePathSegments = $$split(source, /) targetFullPath = $$target/$$last(sourcePathSegments) targetFullPath ~= s,/\\.?/,/, !isEqual(source,$$targetFullPath) { !isEmpty(copyCommand):copyCommand += && copyCommand += mkdir -p \"$$target\" copyCommand += && cp -r \"$$source\" \"$$target\" } } !isEmpty(copyCommand) { copyCommand = echo Copying application data... && $$copyCommand !isEmpty(QMAKE_POST_LINK): QMAKE_POST_LINK += ";" QMAKE_POST_LINK += "$$copyCommand" export(QMAKE_POST_LINK) } } else:unix { maemo5 { desktopfile.files = $${TARGET}.desktop desktopfile.path = /usr/share/applications/hildon icon.files = $${TARGET}64.png icon.path = /usr/share/icons/hicolor/64x64/apps } else:!isEmpty(MEEGO_VERSION_MAJOR) { desktopfile.files = $${TARGET}_harmattan.desktop desktopfile.path = /usr/share/applications icon.files = $${TARGET}80.png icon.path = /usr/share/icons/hicolor/80x80/apps } else { # Assumed to be a Desktop Unix copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, \\\\, /) macx { target = $$OUT_PWD/$${TARGET}.app/Contents/Resources/$$eval($${deploymentfolder}.target) } else { target = $$OUT_PWD/$$eval($${deploymentfolder}.target) } target = $$replace(target, \\\\, /) sourcePathSegments = $$split(source, /) targetFullPath = $$target/$$last(sourcePathSegments) targetFullPath ~= s,/\\.?/,/, !isEqual(source,$$targetFullPath) { !isEmpty(copyCommand):copyCommand += && copyCommand += $(MKDIR) \"$$target\" copyCommand += && $(COPY_DIR) \"$$source\" \"$$target\" } } !isEmpty(copyCommand) { copyCommand = @echo Copying application data... && $$copyCommand copydeploymentfolders.commands = $$copyCommand first.depends = $(first) copydeploymentfolders export(first.depends) export(copydeploymentfolders.commands) QMAKE_EXTRA_TARGETS += first copydeploymentfolders } } !isEmpty(target.path) { installPrefix = $${target.path} } else { installPrefix = /opt/$${TARGET} } for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = $${installPrefix}/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } !isEmpty(desktopfile.path) { export(icon.files) export(icon.path) export(desktopfile.files) export(desktopfile.path) INSTALLS += icon desktopfile } isEmpty(target.path) { target.path = $${installPrefix}/bin export(target.path) } INSTALLS += target } export (ICON) export (INSTALLS) export (DEPLOYMENT) export (LIBS) export (QMAKE_EXTRA_TARGETS) } ================================================ FILE: RangeSearch/题目.txt ================================================ 范围查询(Range) Descriptioin Let S be a set of n integral points on the x-axis. For each given interval [a, b], you are asked to count the points lying inside. Input The first line contains two integers: n (size of S) and m (the number of queries). The second line enumerates all the n points in S. Each of the following m lines consists of two integers a and b and defines an query interval [a, b]. Output The number of points in S lying inside each of the m query intervals. Example Input 5 2 1 3 7 9 11 4 6 7 12 Output 0 3 Restrictions 0 <= n, m <= 5 * 10^5 For each query interval [a, b], it is guaranteed that a <= b. Points in S are distinct from each other. Coordinates of each point as well as the query interval boundaries a and b are non-negative integers not greater than 10^7. Time: 2 sec Memory: 256 MB 描述 数轴上有n个点,对于任一闭区间 [a, b],试计算落在其内的点数。 输入 第一行包括两个整数:点的总数n,查询的次数m。 第二行包含n个数,为各个点的坐标。 以下m行,各包含两个整数:查询区间的左、右边界a和b。 输出 对每次查询,输出落在闭区间[a, b]内点的个数。 样例 见英文题面 限制 0 ≤ n, m ≤ 5×105 对于每次查询的区间[a, b],都有a ≤ b 各点的坐标互异 各点的坐标、查询区间的边界a、b,均为不超过10^7的非负整数 时间:2 sec 内存:256 MB ================================================ FILE: TSP/TSP.cpp ================================================ #include #include #include #define MAX 100 using namespace std; //使用邻接表存储图-基于DFS的拓扑排序 enum STATUS { UNVISTED, VISTED }; struct EdgeNode /*边表结点*/ { int adjvex; //存储邻接顶点对应下标 struct EdgeNode *nex;//指向下一个邻接点 }; struct VertexNode //顶点表结点 { int out; //顶点出度 int data;//数据 // STATUS status;//是否被访问过 EdgeNode *firstEdge;//边表头指针 }; struct Graph //图结构 { VertexNode adjList[MAX];//顶点数组 int numVertexs;//顶点数 int numEdges;//边数 }graph; int viste(VertexNode *node);//拓扑排序中从后向前访问结点 int main() { int n,m,a,b; scanf("%d%d",&n,&m); graph.numVertexs = n; graph.numEdges = m; for(int i=0;iadjvex = a-1;//数组下标从0开始 graph.adjList[a-1].out++;//a结点出度加1 e->nex = NULL; EdgeNode *p = graph.adjList[b-1].firstEdge; if(p == NULL) { graph.adjList[b-1].firstEdge = e; } else { while (p->nex != NULL) { p = p->nex; } p->nex = e; } } int stack[MAX];//保存出度为0的结点堆栈 int top = 0,index,sum=0,len=0; for(int i=0;istatus == UNVISTED)//输出拓扑排序时需要该判断 // { // node->status = VISTED; EdgeNode* e; for(e=graph.adjList[node->data-1].firstEdge;e!=NULL;e=e->nex) { sublen = viste(&graph.adjList[e->adjvex]); if(maxsublen data); // } return len+maxsublen; } ================================================ FILE: TSP/TSP.pro ================================================ TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt SOURCES += \ TSP.cpp include(deployment.pri) qtcAddDeployment() DISTFILES += \ TSP.txt ================================================ FILE: TSP/TSP.txt ================================================ Description Shrek is a postman working in the mountain, whose routine work is sending mail to n villages. Unfortunately, road between villages is out of repair for long time, such that some road is one-way road. There are even some villages that can’t be reached from any other village. In such a case, we only hope as many villages can receive mails as possible. Shrek hopes to choose a village A as starting point (He will be air-dropped to this location), then pass by as many villages as possible. Finally, Shrek will arrived at village B. In the travelling process, each villages is only passed by once. You should help Shrek to design the travel route. Input There are 2 integers, n and m, in first line. Stand for number of village and number of road respectively. In the following m line, m road is given by identity of villages on two terminals. From v1 to v2. The identity of village is in range [1, n]. Output Output maximum number of villages Shrek can pass by. Example Input 4 3 1 4 2 4 4 3 Output 3 Restrictions 1 <= n <= 1,000,000 0 <= m <= 1,000,000 These is no loop road in the input. Time: 2 sec Memory: 256 MB Hints Topological sorting 描述 Shrek是一个大山里的邮递员,每天负责给所在地区的n个村庄派发信件。但杯具的是,由于道路狭窄,年久失修,村庄间的道路都只能单向通过,甚至有些村庄无法从任意一个村庄到达。这样我们只能希望尽可能多的村庄可以收到投递的信件。 Shrek希望知道如何选定一个村庄A作为起点(我们将他空投到该村庄),依次经过尽可能多的村庄,路途中的每个村庄都经过仅一次,最终到达终点村庄B,完成整个送信过程。这个任务交给你来完成。 输入 第一行包括两个整数n,m,分别表示村庄的个数以及可以通行的道路的数目。 以下共m行,每行用两个整数v1和v2表示一条道路,两个整数分别为道路连接的村庄号,道路的方向为从v1至v2,n个村庄编号为[1, n]。 输出 输出一个数字,表示符合条件的最长道路经过的村庄数。 样例 见英文题面 限制 1 ≤ n ≤ 1,000,000 0 ≤ m ≤ 1,000,000 输入保证道路之间没有形成环 时间:2 sec 空间:256 MB 提示 拓扑排序 ================================================ FILE: TSP/deployment.pri ================================================ # This file was generated by an application wizard of Qt Creator. # The code below handles deployment to Android and Maemo, aswell as copying # of the application data to shadow build directories on desktop. # It is recommended not to modify this file, since newer versions of Qt Creator # may offer an updated version of it. defineTest(qtcAddDeployment) { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} greaterThan(QT_MAJOR_VERSION, 4) { itemsources = $${item}.files } else { itemsources = $${item}.sources } $$itemsources = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath= $$eval($${deploymentfolder}.target) export($$itemsources) export($$itempath) DEPLOYMENT += $$item } MAINPROFILEPWD = $$PWD android-no-sdk { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = /data/user/qt/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } target.path = /data/user/qt export(target.path) INSTALLS += target } else:android { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = /assets/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } x86 { target.path = /libs/x86 } else: armeabi-v7a { target.path = /libs/armeabi-v7a } else { target.path = /libs/armeabi } export(target.path) INSTALLS += target } else:win32 { copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, /, \\) sourcePathSegments = $$split(source, \\) target = $$OUT_PWD/$$eval($${deploymentfolder}.target)/$$last(sourcePathSegments) target = $$replace(target, /, \\) target ~= s,\\\\\\.?\\\\,\\, !isEqual(source,$$target) { !isEmpty(copyCommand):copyCommand += && isEqual(QMAKE_DIR_SEP, \\) { copyCommand += $(COPY_DIR) \"$$source\" \"$$target\" } else { source = $$replace(source, \\\\, /) target = $$OUT_PWD/$$eval($${deploymentfolder}.target) target = $$replace(target, \\\\, /) copyCommand += test -d \"$$target\" || mkdir -p \"$$target\" && cp -r \"$$source\" \"$$target\" } } } !isEmpty(copyCommand) { copyCommand = @echo Copying application data... && $$copyCommand copydeploymentfolders.commands = $$copyCommand first.depends = $(first) copydeploymentfolders export(first.depends) export(copydeploymentfolders.commands) QMAKE_EXTRA_TARGETS += first copydeploymentfolders } } else:ios { copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, \\\\, /) target = $CODESIGNING_FOLDER_PATH/$$eval($${deploymentfolder}.target) target = $$replace(target, \\\\, /) sourcePathSegments = $$split(source, /) targetFullPath = $$target/$$last(sourcePathSegments) targetFullPath ~= s,/\\.?/,/, !isEqual(source,$$targetFullPath) { !isEmpty(copyCommand):copyCommand += && copyCommand += mkdir -p \"$$target\" copyCommand += && cp -r \"$$source\" \"$$target\" } } !isEmpty(copyCommand) { copyCommand = echo Copying application data... && $$copyCommand !isEmpty(QMAKE_POST_LINK): QMAKE_POST_LINK += ";" QMAKE_POST_LINK += "$$copyCommand" export(QMAKE_POST_LINK) } } else:unix { maemo5 { desktopfile.files = $${TARGET}.desktop desktopfile.path = /usr/share/applications/hildon icon.files = $${TARGET}64.png icon.path = /usr/share/icons/hicolor/64x64/apps } else:!isEmpty(MEEGO_VERSION_MAJOR) { desktopfile.files = $${TARGET}_harmattan.desktop desktopfile.path = /usr/share/applications icon.files = $${TARGET}80.png icon.path = /usr/share/icons/hicolor/80x80/apps } else { # Assumed to be a Desktop Unix copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, \\\\, /) macx { target = $$OUT_PWD/$${TARGET}.app/Contents/Resources/$$eval($${deploymentfolder}.target) } else { target = $$OUT_PWD/$$eval($${deploymentfolder}.target) } target = $$replace(target, \\\\, /) sourcePathSegments = $$split(source, /) targetFullPath = $$target/$$last(sourcePathSegments) targetFullPath ~= s,/\\.?/,/, !isEqual(source,$$targetFullPath) { !isEmpty(copyCommand):copyCommand += && copyCommand += $(MKDIR) \"$$target\" copyCommand += && $(COPY_DIR) \"$$source\" \"$$target\" } } !isEmpty(copyCommand) { copyCommand = @echo Copying application data... && $$copyCommand copydeploymentfolders.commands = $$copyCommand first.depends = $(first) copydeploymentfolders export(first.depends) export(copydeploymentfolders.commands) QMAKE_EXTRA_TARGETS += first copydeploymentfolders } } !isEmpty(target.path) { installPrefix = $${target.path} } else { installPrefix = /opt/$${TARGET} } for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = $${installPrefix}/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } !isEmpty(desktopfile.path) { export(icon.files) export(icon.path) export(desktopfile.files) export(desktopfile.path) INSTALLS += icon desktopfile } isEmpty(target.path) { target.path = $${installPrefix}/bin export(target.path) } INSTALLS += target } export (ICON) export (INSTALLS) export (DEPLOYMENT) export (LIBS) export (QMAKE_EXTRA_TARGETS) } ================================================ FILE: Toy/Toy.pro ================================================ TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt SOURCES += \ toy.cpp include(deployment.pri) qtcAddDeployment() ================================================ FILE: Toy/deployment.pri ================================================ # This file was generated by an application wizard of Qt Creator. # The code below handles deployment to Android and Maemo, aswell as copying # of the application data to shadow build directories on desktop. # It is recommended not to modify this file, since newer versions of Qt Creator # may offer an updated version of it. defineTest(qtcAddDeployment) { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} greaterThan(QT_MAJOR_VERSION, 4) { itemsources = $${item}.files } else { itemsources = $${item}.sources } $$itemsources = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath= $$eval($${deploymentfolder}.target) export($$itemsources) export($$itempath) DEPLOYMENT += $$item } MAINPROFILEPWD = $$PWD android-no-sdk { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = /data/user/qt/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } target.path = /data/user/qt export(target.path) INSTALLS += target } else:android { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = /assets/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } x86 { target.path = /libs/x86 } else: armeabi-v7a { target.path = /libs/armeabi-v7a } else { target.path = /libs/armeabi } export(target.path) INSTALLS += target } else:win32 { copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, /, \\) sourcePathSegments = $$split(source, \\) target = $$OUT_PWD/$$eval($${deploymentfolder}.target)/$$last(sourcePathSegments) target = $$replace(target, /, \\) target ~= s,\\\\\\.?\\\\,\\, !isEqual(source,$$target) { !isEmpty(copyCommand):copyCommand += && isEqual(QMAKE_DIR_SEP, \\) { copyCommand += $(COPY_DIR) \"$$source\" \"$$target\" } else { source = $$replace(source, \\\\, /) target = $$OUT_PWD/$$eval($${deploymentfolder}.target) target = $$replace(target, \\\\, /) copyCommand += test -d \"$$target\" || mkdir -p \"$$target\" && cp -r \"$$source\" \"$$target\" } } } !isEmpty(copyCommand) { copyCommand = @echo Copying application data... && $$copyCommand copydeploymentfolders.commands = $$copyCommand first.depends = $(first) copydeploymentfolders export(first.depends) export(copydeploymentfolders.commands) QMAKE_EXTRA_TARGETS += first copydeploymentfolders } } else:ios { copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, \\\\, /) target = $CODESIGNING_FOLDER_PATH/$$eval($${deploymentfolder}.target) target = $$replace(target, \\\\, /) sourcePathSegments = $$split(source, /) targetFullPath = $$target/$$last(sourcePathSegments) targetFullPath ~= s,/\\.?/,/, !isEqual(source,$$targetFullPath) { !isEmpty(copyCommand):copyCommand += && copyCommand += mkdir -p \"$$target\" copyCommand += && cp -r \"$$source\" \"$$target\" } } !isEmpty(copyCommand) { copyCommand = echo Copying application data... && $$copyCommand !isEmpty(QMAKE_POST_LINK): QMAKE_POST_LINK += ";" QMAKE_POST_LINK += "$$copyCommand" export(QMAKE_POST_LINK) } } else:unix { maemo5 { desktopfile.files = $${TARGET}.desktop desktopfile.path = /usr/share/applications/hildon icon.files = $${TARGET}64.png icon.path = /usr/share/icons/hicolor/64x64/apps } else:!isEmpty(MEEGO_VERSION_MAJOR) { desktopfile.files = $${TARGET}_harmattan.desktop desktopfile.path = /usr/share/applications icon.files = $${TARGET}80.png icon.path = /usr/share/icons/hicolor/80x80/apps } else { # Assumed to be a Desktop Unix copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, \\\\, /) macx { target = $$OUT_PWD/$${TARGET}.app/Contents/Resources/$$eval($${deploymentfolder}.target) } else { target = $$OUT_PWD/$$eval($${deploymentfolder}.target) } target = $$replace(target, \\\\, /) sourcePathSegments = $$split(source, /) targetFullPath = $$target/$$last(sourcePathSegments) targetFullPath ~= s,/\\.?/,/, !isEqual(source,$$targetFullPath) { !isEmpty(copyCommand):copyCommand += && copyCommand += $(MKDIR) \"$$target\" copyCommand += && $(COPY_DIR) \"$$source\" \"$$target\" } } !isEmpty(copyCommand) { copyCommand = @echo Copying application data... && $$copyCommand copydeploymentfolders.commands = $$copyCommand first.depends = $(first) copydeploymentfolders export(first.depends) export(copydeploymentfolders.commands) QMAKE_EXTRA_TARGETS += first copydeploymentfolders } } !isEmpty(target.path) { installPrefix = $${target.path} } else { installPrefix = /opt/$${TARGET} } for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = $${installPrefix}/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } !isEmpty(desktopfile.path) { export(icon.files) export(icon.path) export(desktopfile.files) export(desktopfile.path) INSTALLS += icon desktopfile } isEmpty(target.path) { target.path = $${installPrefix}/bin export(target.path) } INSTALLS += target } export (ICON) export (INSTALLS) export (DEPLOYMENT) export (LIBS) export (QMAKE_EXTRA_TARGETS) } ================================================ FILE: Toy/toy.cpp ================================================ #include #include #include /* * 思路:将一串数字看做是一个字符串,其全排列总共有8!,每种排列对应一个状态 * 有的状态能够通过题目所给的操作到达,注意题目要求的是从目标状态恢复初始状态 * 所需步数不是从初始状态到达目标状态所需步数,所以要将题目所给的操作逆转过来, * 才是计算从目标状态返回初始状态的步数。具体做法是利用康拓变换+BFS搜索遍历, * 提前将所需步数存储在一个输出数组中,数组的秩就是对应状态的康拓变换值,利用 * BFS不断搜索当前状态的下一状态,没有搜索过的状态步长加1,保存到输出数组中, * 直至搜索完毕。 */ #define MAX 40320//8! 全部排列方式有8!种 int outMap[MAX]= {0};//输出数组 int factor[8] = {1,1,2,6,24,120,720,5040};//阶乘数组 struct TOY { char str[9]; int hashVal;//康托变换后的散列值 TOY() { hashVal = 0; } TOY(char *s) { strcpy(str,s); contor(); } void downUpChange(char *s)//下上交换 { for(int i=0;i<8;i++) { str[7-i] = s[i]; } str[8] = '\0'; contor(); } void cycleLeftMove(char *s)//循环左移 { for(int i=0;i<4;i++) { str[i] = s[(i+1)%4]; } for(int i=4;i<8;i++) { str[i] = s[(i+3)%4+4]; } str[8] = '\0'; contor(); } void centerMove(char *s)//中心逆时针旋转 { strcpy(str,s); str[1] = s[2]; str[2] = s[5]; str[5] = s[6]; str[6] = s[1]; str[8] = '\0'; contor(); } void contor() { hashVal = 0; for(int i=0;i<8;i++) { int temp = 0; for(int j=i+1;j<8;j++) { if(str[j]0) { TOY tempHead = queue.pop();//取出第一个节点 TOY temptail; //题目问的是由目标返回初始的步数,因此采取逆操作 //下上交换 temptail.downUpChange(tempHead.str); if(outMap[temptail.hashVal] == 0 && temptail.hashVal != 0)//未访问过&&不是初始状态 { queue.push(temptail); outMap[temptail.hashVal] = outMap[tempHead.hashVal]+1;//步数加1 } //循环左移 temptail.cycleLeftMove(tempHead.str); if(outMap[temptail.hashVal] == 0 && temptail.hashVal != 0)//未访问过&&不是初始状态 { queue.push(temptail); outMap[temptail.hashVal] = outMap[tempHead.hashVal]+1;//步数加1 } //中心逆时针旋转 temptail.centerMove(tempHead.str); if(outMap[temptail.hashVal] == 0 && temptail.hashVal != 0)//未访问过&&不是初始状态 { queue.push(temptail); outMap[temptail.hashVal] = outMap[tempHead.hashVal]+1;//步数加1 } } } int main() { Init(); int n,num; char s[9] ={'\0'}; scanf("%d",&n); while(n--) { for(int i=0;i<8;i++) { scanf("%d",&num); s[i] = num + '0'; } TOY tempToy(s); if(tempToy.hashVal == 0) { printf("%d\n",0); } else { printf("%d\n",outMap[tempToy.hashVal]>0?outMap[tempToy.hashVal]:-1); } } return 0; } ================================================ FILE: Train/Train.pro ================================================ TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt SOURCES += \ train.cpp include(deployment.pri) qtcAddDeployment() ================================================ FILE: Train/deployment.pri ================================================ # This file was generated by an application wizard of Qt Creator. # The code below handles deployment to Android and Maemo, aswell as copying # of the application data to shadow build directories on desktop. # It is recommended not to modify this file, since newer versions of Qt Creator # may offer an updated version of it. defineTest(qtcAddDeployment) { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} greaterThan(QT_MAJOR_VERSION, 4) { itemsources = $${item}.files } else { itemsources = $${item}.sources } $$itemsources = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath= $$eval($${deploymentfolder}.target) export($$itemsources) export($$itempath) DEPLOYMENT += $$item } MAINPROFILEPWD = $$PWD android-no-sdk { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = /data/user/qt/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } target.path = /data/user/qt export(target.path) INSTALLS += target } else:android { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = /assets/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } x86 { target.path = /libs/x86 } else: armeabi-v7a { target.path = /libs/armeabi-v7a } else { target.path = /libs/armeabi } export(target.path) INSTALLS += target } else:win32 { copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, /, \\) sourcePathSegments = $$split(source, \\) target = $$OUT_PWD/$$eval($${deploymentfolder}.target)/$$last(sourcePathSegments) target = $$replace(target, /, \\) target ~= s,\\\\\\.?\\\\,\\, !isEqual(source,$$target) { !isEmpty(copyCommand):copyCommand += && isEqual(QMAKE_DIR_SEP, \\) { copyCommand += $(COPY_DIR) \"$$source\" \"$$target\" } else { source = $$replace(source, \\\\, /) target = $$OUT_PWD/$$eval($${deploymentfolder}.target) target = $$replace(target, \\\\, /) copyCommand += test -d \"$$target\" || mkdir -p \"$$target\" && cp -r \"$$source\" \"$$target\" } } } !isEmpty(copyCommand) { copyCommand = @echo Copying application data... && $$copyCommand copydeploymentfolders.commands = $$copyCommand first.depends = $(first) copydeploymentfolders export(first.depends) export(copydeploymentfolders.commands) QMAKE_EXTRA_TARGETS += first copydeploymentfolders } } else:ios { copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, \\\\, /) target = $CODESIGNING_FOLDER_PATH/$$eval($${deploymentfolder}.target) target = $$replace(target, \\\\, /) sourcePathSegments = $$split(source, /) targetFullPath = $$target/$$last(sourcePathSegments) targetFullPath ~= s,/\\.?/,/, !isEqual(source,$$targetFullPath) { !isEmpty(copyCommand):copyCommand += && copyCommand += mkdir -p \"$$target\" copyCommand += && cp -r \"$$source\" \"$$target\" } } !isEmpty(copyCommand) { copyCommand = echo Copying application data... && $$copyCommand !isEmpty(QMAKE_POST_LINK): QMAKE_POST_LINK += ";" QMAKE_POST_LINK += "$$copyCommand" export(QMAKE_POST_LINK) } } else:unix { maemo5 { desktopfile.files = $${TARGET}.desktop desktopfile.path = /usr/share/applications/hildon icon.files = $${TARGET}64.png icon.path = /usr/share/icons/hicolor/64x64/apps } else:!isEmpty(MEEGO_VERSION_MAJOR) { desktopfile.files = $${TARGET}_harmattan.desktop desktopfile.path = /usr/share/applications icon.files = $${TARGET}80.png icon.path = /usr/share/icons/hicolor/80x80/apps } else { # Assumed to be a Desktop Unix copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, \\\\, /) macx { target = $$OUT_PWD/$${TARGET}.app/Contents/Resources/$$eval($${deploymentfolder}.target) } else { target = $$OUT_PWD/$$eval($${deploymentfolder}.target) } target = $$replace(target, \\\\, /) sourcePathSegments = $$split(source, /) targetFullPath = $$target/$$last(sourcePathSegments) targetFullPath ~= s,/\\.?/,/, !isEqual(source,$$targetFullPath) { !isEmpty(copyCommand):copyCommand += && copyCommand += $(MKDIR) \"$$target\" copyCommand += && $(COPY_DIR) \"$$source\" \"$$target\" } } !isEmpty(copyCommand) { copyCommand = @echo Copying application data... && $$copyCommand copydeploymentfolders.commands = $$copyCommand first.depends = $(first) copydeploymentfolders export(first.depends) export(copydeploymentfolders.commands) QMAKE_EXTRA_TARGETS += first copydeploymentfolders } } !isEmpty(target.path) { installPrefix = $${target.path} } else { installPrefix = /opt/$${TARGET} } for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = $${installPrefix}/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } !isEmpty(desktopfile.path) { export(icon.files) export(icon.path) export(desktopfile.files) export(desktopfile.path) INSTALLS += icon desktopfile } isEmpty(target.path) { target.path = $${installPrefix}/bin export(target.path) } INSTALLS += target } export (ICON) export (INSTALLS) export (DEPLOYMENT) export (LIBS) export (QMAKE_EXTRA_TARGETS) } ================================================ FILE: Train/train.cpp ================================================ #include #include #include #define MAX 20000000 //#define DEBUG using namespace std; int outArray[MAX]; char resultBuffer[50000000]; int resultLen = 0; class MyStack { public: MyStack(int capacity) { this->capacity = capacity; currentSize = 0; st = new int[capacity]; } bool push(int e) { if(currentSize r) { while(outArray[i] > r) { if(stack.full()) { printf("No\n"); return 0; } #ifdef DEBUG cout<<"push "< #include #define MAX 20000000 using namespace std; char resultBuff[10000000]; char buffer[1000000];//缓冲区,减少IO操作,缩短读入数据时间 int resultLen = 0; class Queue { public: Queue(int capacity) { this->capacity = capacity; data = new int[capacity]; currentSize = 0; front = 0; rear = 0; } void enQueue(int e) { data[rear] = e; rear = (rear +1) % capacity; currentSize++; } int deQueue() { int val = data[front]; front = (front+1) % capacity; currentSize--; printf("%d\n",val); return val; } bool empty() { return currentSize == 0; } bool full() { return currentSize == capacity; } private: int front; int rear; int currentSize; int capacity; int *data; }; struct dataNode { int val; int counter; }; class DQueue { public: DQueue(int capacity) { this->capacity = capacity; data = new dataNode[capacity]; front = 0; rear = 0; currentSize = 0; } int removeFront() { int val = data[front].val; front = (front+1)%capacity; currentSize--; return val; } dataNode removeRear() { if(rear == 0) { rear = capacity -1; } else { rear--; } dataNode temNode = data[rear]; currentSize--; return temNode; } void insertRear(int e) { dataNode temNode; temNode.val = e; data[rear] = temNode; rear = (rear + 1)%capacity; currentSize++; } dataNode& getRear() { int pos; if(rear == 0) { pos = capacity - 1; } else { pos = rear -1; } return data[pos]; } dataNode& getFront() { return data[front]; } bool empty() { return currentSize == 0; } bool full() { return currentSize == capacity; } private: int front; int rear; int currentSize; int capacity; dataNode *data; }; int main() { int n,x; char buf[16]; Queue queue(MAX); DQueue dqueue(MAX); scanf("%d",&n); setvbuf(stdin,buffer,_IOFBF,1000000); while (n-->0) { scanf("%s",buf); if(buf[0] == 'E') { scanf("%d",&x); if(!queue.full()) { queue.enQueue(x); int a = 1; while(!dqueue.empty() && dqueue.getRear().val <= x) { a += dqueue.removeRear().counter; } dqueue.insertRear(x); dqueue.getRear().counter = a; } } else { if(buf[0] == 'D') { if(!queue.empty()) { queue.deQueue(); if(!(--dqueue.getFront().counter)) { dqueue.removeFront(); } } } else { int val = dqueue.getFront().val; printf("%d\n",val); } } } return 0; } ================================================ FILE: Tunel/Tunel.pro ================================================ TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt SOURCES += \ Tunel.cpp include(deployment.pri) qtcAddDeployment() ================================================ FILE: Tunel/deployment.pri ================================================ # This file was generated by an application wizard of Qt Creator. # The code below handles deployment to Android and Maemo, aswell as copying # of the application data to shadow build directories on desktop. # It is recommended not to modify this file, since newer versions of Qt Creator # may offer an updated version of it. defineTest(qtcAddDeployment) { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} greaterThan(QT_MAJOR_VERSION, 4) { itemsources = $${item}.files } else { itemsources = $${item}.sources } $$itemsources = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath= $$eval($${deploymentfolder}.target) export($$itemsources) export($$itempath) DEPLOYMENT += $$item } MAINPROFILEPWD = $$PWD android-no-sdk { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = /data/user/qt/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } target.path = /data/user/qt export(target.path) INSTALLS += target } else:android { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = /assets/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } x86 { target.path = /libs/x86 } else: armeabi-v7a { target.path = /libs/armeabi-v7a } else { target.path = /libs/armeabi } export(target.path) INSTALLS += target } else:win32 { copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, /, \\) sourcePathSegments = $$split(source, \\) target = $$OUT_PWD/$$eval($${deploymentfolder}.target)/$$last(sourcePathSegments) target = $$replace(target, /, \\) target ~= s,\\\\\\.?\\\\,\\, !isEqual(source,$$target) { !isEmpty(copyCommand):copyCommand += && isEqual(QMAKE_DIR_SEP, \\) { copyCommand += $(COPY_DIR) \"$$source\" \"$$target\" } else { source = $$replace(source, \\\\, /) target = $$OUT_PWD/$$eval($${deploymentfolder}.target) target = $$replace(target, \\\\, /) copyCommand += test -d \"$$target\" || mkdir -p \"$$target\" && cp -r \"$$source\" \"$$target\" } } } !isEmpty(copyCommand) { copyCommand = @echo Copying application data... && $$copyCommand copydeploymentfolders.commands = $$copyCommand first.depends = $(first) copydeploymentfolders export(first.depends) export(copydeploymentfolders.commands) QMAKE_EXTRA_TARGETS += first copydeploymentfolders } } else:ios { copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, \\\\, /) target = $CODESIGNING_FOLDER_PATH/$$eval($${deploymentfolder}.target) target = $$replace(target, \\\\, /) sourcePathSegments = $$split(source, /) targetFullPath = $$target/$$last(sourcePathSegments) targetFullPath ~= s,/\\.?/,/, !isEqual(source,$$targetFullPath) { !isEmpty(copyCommand):copyCommand += && copyCommand += mkdir -p \"$$target\" copyCommand += && cp -r \"$$source\" \"$$target\" } } !isEmpty(copyCommand) { copyCommand = echo Copying application data... && $$copyCommand !isEmpty(QMAKE_POST_LINK): QMAKE_POST_LINK += ";" QMAKE_POST_LINK += "$$copyCommand" export(QMAKE_POST_LINK) } } else:unix { maemo5 { desktopfile.files = $${TARGET}.desktop desktopfile.path = /usr/share/applications/hildon icon.files = $${TARGET}64.png icon.path = /usr/share/icons/hicolor/64x64/apps } else:!isEmpty(MEEGO_VERSION_MAJOR) { desktopfile.files = $${TARGET}_harmattan.desktop desktopfile.path = /usr/share/applications icon.files = $${TARGET}80.png icon.path = /usr/share/icons/hicolor/80x80/apps } else { # Assumed to be a Desktop Unix copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, \\\\, /) macx { target = $$OUT_PWD/$${TARGET}.app/Contents/Resources/$$eval($${deploymentfolder}.target) } else { target = $$OUT_PWD/$$eval($${deploymentfolder}.target) } target = $$replace(target, \\\\, /) sourcePathSegments = $$split(source, /) targetFullPath = $$target/$$last(sourcePathSegments) targetFullPath ~= s,/\\.?/,/, !isEqual(source,$$targetFullPath) { !isEmpty(copyCommand):copyCommand += && copyCommand += $(MKDIR) \"$$target\" copyCommand += && $(COPY_DIR) \"$$source\" \"$$target\" } } !isEmpty(copyCommand) { copyCommand = @echo Copying application data... && $$copyCommand copydeploymentfolders.commands = $$copyCommand first.depends = $(first) copydeploymentfolders export(first.depends) export(copydeploymentfolders.commands) QMAKE_EXTRA_TARGETS += first copydeploymentfolders } } !isEmpty(target.path) { installPrefix = $${target.path} } else { installPrefix = /opt/$${TARGET} } for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = $${installPrefix}/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } !isEmpty(desktopfile.path) { export(icon.files) export(icon.path) export(desktopfile.files) export(desktopfile.path) INSTALLS += icon desktopfile } isEmpty(target.path) { target.path = $${installPrefix}/bin export(target.path) } INSTALLS += target } export (ICON) export (INSTALLS) export (DEPLOYMENT) export (LIBS) export (QMAKE_EXTRA_TARGETS) } ================================================ FILE: Zuma2/Zuma2.cpp ================================================ #include #include #include #include #define MAX 100000000 using namespace std; //链表节点 struct ZumaNode { char data; ZumaNode *pred; ZumaNode *succ; ZumaNode(){} ZumaNode(char name):data(name){} }*header,*trailer; char buffer[MAX]; char resultBuffer[150000000];//不足够大无法通过最后一个测试用例 int listSize = 0; //将输入字符串转成列表 void createList(char *str,int len) { header = new ZumaNode(); header->pred = NULL; ZumaNode *rear = header; // rear = header; for(int i= 0;isucc = temNode; temNode->pred = rear; rear = temNode; listSize++; } trailer = new ZumaNode(); trailer->pred = rear; rear->succ = trailer; trailer->succ = NULL; } ZumaNode *findNode(int position) { int num = 0; ZumaNode *p = header->succ; while( num < position && p->succ != NULL) { p = p->succ; num++; } return p; } ZumaNode *delRepet(ZumaNode *currentNode,char data) { ZumaNode *preNode; while(1) { preNode = currentNode->pred; int num = 0; while(currentNode != trailer && currentNode->data == data) { currentNode = currentNode->succ; num++; } while(preNode->succ != header && preNode->data == data) { preNode = preNode->pred; num++; } if(num >= 3) { listSize -= num; ZumaNode *p1,*p2; p1 = preNode->succ; while(p1 != currentNode) { p2 = p1->succ; delete p1; p1 = p2; } preNode->succ = currentNode; currentNode->pred = preNode; if(currentNode != trailer) data = currentNode->data;//关键点,合并后再次删除 } else { break;//退出循环 } } return preNode; } void insertNode(ZumaNode *currentNode,char c) { ZumaNode *temNode = new ZumaNode(c); if(currentNode->pred != NULL) { temNode->succ = currentNode; temNode->pred = currentNode->pred; currentNode->pred->succ = temNode; currentNode->pred = temNode; } listSize++; } int main() { int n,counter,resultLen = 0; gets(buffer); createList(buffer,strlen(buffer)); scanf("%d",&n); int *arrayposition = new int[n]; char *arrayBall = new char[n]; for(int i=0;i0) { ZumaNode *temNode = findNode(arrayposition[counter]); insertNode(temNode,arrayBall[counter]); delRepet(temNode,arrayBall[counter]); ZumaNode* result = header; if(listSize == 0) { // printf("-\n"); resultBuffer[resultLen++] = '-'; resultBuffer[resultLen++] = '\n'; } else { for(int i=0;isucc->data); resultBuffer[resultLen++] = result->succ->data; result = result->succ; } resultBuffer[resultLen++] = '\n'; // printf("\n"); } counter++; } printf("%s",resultBuffer); return 0; } ================================================ FILE: Zuma2/Zuma2.pro ================================================ TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt SOURCES += \ Zuma2.cpp include(deployment.pri) qtcAddDeployment() ================================================ FILE: Zuma2/deployment.pri ================================================ # This file was generated by an application wizard of Qt Creator. # The code below handles deployment to Android and Maemo, aswell as copying # of the application data to shadow build directories on desktop. # It is recommended not to modify this file, since newer versions of Qt Creator # may offer an updated version of it. defineTest(qtcAddDeployment) { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} greaterThan(QT_MAJOR_VERSION, 4) { itemsources = $${item}.files } else { itemsources = $${item}.sources } $$itemsources = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath= $$eval($${deploymentfolder}.target) export($$itemsources) export($$itempath) DEPLOYMENT += $$item } MAINPROFILEPWD = $$PWD android-no-sdk { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = /data/user/qt/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } target.path = /data/user/qt export(target.path) INSTALLS += target } else:android { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = /assets/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } x86 { target.path = /libs/x86 } else: armeabi-v7a { target.path = /libs/armeabi-v7a } else { target.path = /libs/armeabi } export(target.path) INSTALLS += target } else:win32 { copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, /, \\) sourcePathSegments = $$split(source, \\) target = $$OUT_PWD/$$eval($${deploymentfolder}.target)/$$last(sourcePathSegments) target = $$replace(target, /, \\) target ~= s,\\\\\\.?\\\\,\\, !isEqual(source,$$target) { !isEmpty(copyCommand):copyCommand += && isEqual(QMAKE_DIR_SEP, \\) { copyCommand += $(COPY_DIR) \"$$source\" \"$$target\" } else { source = $$replace(source, \\\\, /) target = $$OUT_PWD/$$eval($${deploymentfolder}.target) target = $$replace(target, \\\\, /) copyCommand += test -d \"$$target\" || mkdir -p \"$$target\" && cp -r \"$$source\" \"$$target\" } } } !isEmpty(copyCommand) { copyCommand = @echo Copying application data... && $$copyCommand copydeploymentfolders.commands = $$copyCommand first.depends = $(first) copydeploymentfolders export(first.depends) export(copydeploymentfolders.commands) QMAKE_EXTRA_TARGETS += first copydeploymentfolders } } else:ios { copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, \\\\, /) target = $CODESIGNING_FOLDER_PATH/$$eval($${deploymentfolder}.target) target = $$replace(target, \\\\, /) sourcePathSegments = $$split(source, /) targetFullPath = $$target/$$last(sourcePathSegments) targetFullPath ~= s,/\\.?/,/, !isEqual(source,$$targetFullPath) { !isEmpty(copyCommand):copyCommand += && copyCommand += mkdir -p \"$$target\" copyCommand += && cp -r \"$$source\" \"$$target\" } } !isEmpty(copyCommand) { copyCommand = echo Copying application data... && $$copyCommand !isEmpty(QMAKE_POST_LINK): QMAKE_POST_LINK += ";" QMAKE_POST_LINK += "$$copyCommand" export(QMAKE_POST_LINK) } } else:unix { maemo5 { desktopfile.files = $${TARGET}.desktop desktopfile.path = /usr/share/applications/hildon icon.files = $${TARGET}64.png icon.path = /usr/share/icons/hicolor/64x64/apps } else:!isEmpty(MEEGO_VERSION_MAJOR) { desktopfile.files = $${TARGET}_harmattan.desktop desktopfile.path = /usr/share/applications icon.files = $${TARGET}80.png icon.path = /usr/share/icons/hicolor/80x80/apps } else { # Assumed to be a Desktop Unix copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, \\\\, /) macx { target = $$OUT_PWD/$${TARGET}.app/Contents/Resources/$$eval($${deploymentfolder}.target) } else { target = $$OUT_PWD/$$eval($${deploymentfolder}.target) } target = $$replace(target, \\\\, /) sourcePathSegments = $$split(source, /) targetFullPath = $$target/$$last(sourcePathSegments) targetFullPath ~= s,/\\.?/,/, !isEqual(source,$$targetFullPath) { !isEmpty(copyCommand):copyCommand += && copyCommand += $(MKDIR) \"$$target\" copyCommand += && $(COPY_DIR) \"$$source\" \"$$target\" } } !isEmpty(copyCommand) { copyCommand = @echo Copying application data... && $$copyCommand copydeploymentfolders.commands = $$copyCommand first.depends = $(first) copydeploymentfolders export(first.depends) export(copydeploymentfolders.commands) QMAKE_EXTRA_TARGETS += first copydeploymentfolders } } !isEmpty(target.path) { installPrefix = $${target.path} } else { installPrefix = /opt/$${TARGET} } for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = $${installPrefix}/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } !isEmpty(desktopfile.path) { export(icon.files) export(icon.path) export(desktopfile.files) export(desktopfile.path) INSTALLS += icon desktopfile } isEmpty(target.path) { target.path = $${installPrefix}/bin export(target.path) } INSTALLS += target } export (ICON) export (INSTALLS) export (DEPLOYMENT) export (LIBS) export (QMAKE_EXTRA_TARGETS) } ================================================ FILE: testDeom/deployment.pri ================================================ # This file was generated by an application wizard of Qt Creator. # The code below handles deployment to Android and Maemo, aswell as copying # of the application data to shadow build directories on desktop. # It is recommended not to modify this file, since newer versions of Qt Creator # may offer an updated version of it. defineTest(qtcAddDeployment) { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} greaterThan(QT_MAJOR_VERSION, 4) { itemsources = $${item}.files } else { itemsources = $${item}.sources } $$itemsources = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath= $$eval($${deploymentfolder}.target) export($$itemsources) export($$itempath) DEPLOYMENT += $$item } MAINPROFILEPWD = $$PWD android-no-sdk { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = /data/user/qt/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } target.path = /data/user/qt export(target.path) INSTALLS += target } else:android { for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = /assets/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } x86 { target.path = /libs/x86 } else: armeabi-v7a { target.path = /libs/armeabi-v7a } else { target.path = /libs/armeabi } export(target.path) INSTALLS += target } else:win32 { copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, /, \\) sourcePathSegments = $$split(source, \\) target = $$OUT_PWD/$$eval($${deploymentfolder}.target)/$$last(sourcePathSegments) target = $$replace(target, /, \\) target ~= s,\\\\\\.?\\\\,\\, !isEqual(source,$$target) { !isEmpty(copyCommand):copyCommand += && isEqual(QMAKE_DIR_SEP, \\) { copyCommand += $(COPY_DIR) \"$$source\" \"$$target\" } else { source = $$replace(source, \\\\, /) target = $$OUT_PWD/$$eval($${deploymentfolder}.target) target = $$replace(target, \\\\, /) copyCommand += test -d \"$$target\" || mkdir -p \"$$target\" && cp -r \"$$source\" \"$$target\" } } } !isEmpty(copyCommand) { copyCommand = @echo Copying application data... && $$copyCommand copydeploymentfolders.commands = $$copyCommand first.depends = $(first) copydeploymentfolders export(first.depends) export(copydeploymentfolders.commands) QMAKE_EXTRA_TARGETS += first copydeploymentfolders } } else:ios { copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, \\\\, /) target = $CODESIGNING_FOLDER_PATH/$$eval($${deploymentfolder}.target) target = $$replace(target, \\\\, /) sourcePathSegments = $$split(source, /) targetFullPath = $$target/$$last(sourcePathSegments) targetFullPath ~= s,/\\.?/,/, !isEqual(source,$$targetFullPath) { !isEmpty(copyCommand):copyCommand += && copyCommand += mkdir -p \"$$target\" copyCommand += && cp -r \"$$source\" \"$$target\" } } !isEmpty(copyCommand) { copyCommand = echo Copying application data... && $$copyCommand !isEmpty(QMAKE_POST_LINK): QMAKE_POST_LINK += ";" QMAKE_POST_LINK += "$$copyCommand" export(QMAKE_POST_LINK) } } else:unix { maemo5 { desktopfile.files = $${TARGET}.desktop desktopfile.path = /usr/share/applications/hildon icon.files = $${TARGET}64.png icon.path = /usr/share/icons/hicolor/64x64/apps } else:!isEmpty(MEEGO_VERSION_MAJOR) { desktopfile.files = $${TARGET}_harmattan.desktop desktopfile.path = /usr/share/applications icon.files = $${TARGET}80.png icon.path = /usr/share/icons/hicolor/80x80/apps } else { # Assumed to be a Desktop Unix copyCommand = for(deploymentfolder, DEPLOYMENTFOLDERS) { source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) source = $$replace(source, \\\\, /) macx { target = $$OUT_PWD/$${TARGET}.app/Contents/Resources/$$eval($${deploymentfolder}.target) } else { target = $$OUT_PWD/$$eval($${deploymentfolder}.target) } target = $$replace(target, \\\\, /) sourcePathSegments = $$split(source, /) targetFullPath = $$target/$$last(sourcePathSegments) targetFullPath ~= s,/\\.?/,/, !isEqual(source,$$targetFullPath) { !isEmpty(copyCommand):copyCommand += && copyCommand += $(MKDIR) \"$$target\" copyCommand += && $(COPY_DIR) \"$$source\" \"$$target\" } } !isEmpty(copyCommand) { copyCommand = @echo Copying application data... && $$copyCommand copydeploymentfolders.commands = $$copyCommand first.depends = $(first) copydeploymentfolders export(first.depends) export(copydeploymentfolders.commands) QMAKE_EXTRA_TARGETS += first copydeploymentfolders } } !isEmpty(target.path) { installPrefix = $${target.path} } else { installPrefix = /opt/$${TARGET} } for(deploymentfolder, DEPLOYMENTFOLDERS) { item = item$${deploymentfolder} itemfiles = $${item}.files $$itemfiles = $$eval($${deploymentfolder}.source) itempath = $${item}.path $$itempath = $${installPrefix}/$$eval($${deploymentfolder}.target) export($$itemfiles) export($$itempath) INSTALLS += $$item } !isEmpty(desktopfile.path) { export(icon.files) export(icon.path) export(desktopfile.files) export(desktopfile.path) INSTALLS += icon desktopfile } isEmpty(target.path) { target.path = $${installPrefix}/bin export(target.path) } INSTALLS += target } export (ICON) export (INSTALLS) export (DEPLOYMENT) export (LIBS) export (QMAKE_EXTRA_TARGETS) } ================================================ FILE: testDeom/main.cpp ================================================ #include #include using namespace std; int main() { int count,h; cin>>h; count = 1; while(1) { if((count + count *count) < h) { count++; } else { cout << count - 1; return 0; } } } ================================================ FILE: testDeom/testDeom.pro ================================================ TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt CONFIG += C++11 SOURCES += main.cpp include(deployment.pri) qtcAddDeployment()