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 <iostream>
#include <cstdio>
#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<n;i++)
{
scanf("%d",&preOder[i]);
}
for(int i=0;i<n;i++)
{
scanf("%d",&postOder[i]);
}
rebuild(preOder,postOder,n);
return 0;
}
================================================
FILE: BinaryTreeRebuild/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: BinaryTreeRebuild/题目.txt
================================================
真二叉树重构(Proper Rebuild)
Description
In general, given the preorder traversal sequence and postorder traversal sequence of a binary tree, we cannot determine the binary tree.
Figure 1
In Figure 1 for example, although they are two different binary tree, their preorder traversal sequence and postorder traversal sequence are both of the same.
But for one proper binary tree, in which each internal node has two sons, we can uniquely determine it through its given preorder traversal sequence and postorder traversal sequence.
Label n nodes in one binary tree using the integers in [1, n], we would like to output the inorder traversal sequence of a binary tree through its preorder and postorder traversal sequence.
Input
The 1st line is an integer n, i.e., the number of nodes in one given binary tree,
The 2nd and 3rd lines are the given preorder and postorder traversal sequence respectively.
Output
The inorder traversal sequence of the given binary tree in one line.
Example
Input
5
1 2 4 5 3
4 5 2 3 1
Output
4 2 5 1 3
Restrictions
For 95% of the estimation, 1 <= n <= 1,000,00
For 100% of the estimation, 1 <= n <= 4,000,000
The input sequence is a permutation of {1,2...n}, corresponding to a legal binary tree.
Time: 2 sec
Memory: 256 MB
Hints
Figure 2
In Figure 2, observe the positions of the left and right children in preorder and postorder traversal sequence.
描述
一般来说,给定二叉树的先序遍历序列和后序遍历序列,并不能确定唯一确定该二叉树。
(图一)
比如图一中的两棵二叉树,虽然它们是不同二叉树,但是它们的先序、后序遍历序列都是相同的。
但是对于“真二叉树”(每个内部节点都有两个孩子的二叉树),给定它的先序、后序遍历序列足以完全确定它的结构。
将二叉树的n个节点用[1, n]内的整数进行编号,输入一棵真二叉树的先序、后序遍历序列,请输出它的中序遍历序列。
输入
第一行为一个整数n,即二叉树中节点的个数。
第二、三行为已知的先序、后序遍历序列。
输出
仅一行,给定真二叉树的中序遍历序列。
样例
见英文题面
限制
对于95%的测例:1 ≤ n ≤ 1,000,000
对于100%的测例:1 ≤ n ≤ 4,000,000
输入的序列是{1,2...n}的排列,且对应于一棵合法的真二叉树
时间:2 sec
空间:256 MB
提示
观察左、右孩子在先序、后序遍历序列中的位置
================================================
FILE: BroadCast/BroadCast.pro
================================================
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
broadcast.cpp
include(deployment.pri)
qtcAddDeployment()
DISTFILES += \
Ŀ.txt
================================================
FILE: BroadCast/broadcast.cpp
================================================
#include <iostream>
#include <cstdio>
#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;i<n;i++)//初始化顶点数组
{
graph.adjList[i].data = i+1;//顶点从1开始
graph.adjList[i].isVisted = false;
graph.adjList[i].firstEdge = NULL;
}
int a,b;
for(int i=0;i<m;i++)//输入信息并构建邻接表
{
scanf("%d%d",&a,&b);//距离小于20km的结点(村庄)视为有边连通
EdgeNode *ea = new EdgeNode;
EdgeNode *eb = new EdgeNode;
ea->adjvex = 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;i<graph.numVertexs;i++)
{
if(!graph.adjList[i].isVisted)
{
graph.adjList[i].isVisted = true;
graph.adjList[i].castType = 1;//广播类型
queue[tail++] = graph.adjList[i];//结点入队
queuesize++;
while(queuesize!=0)
{
VertexNode node = queue[head++];//取出队列中第一个结点
queuesize--;
EdgeNode *pn = node.firstEdge;
while( pn != NULL)
{
if(!graph.adjList[pn->adjvex].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 <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#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;i<len;i++)//hash函数版本1
{
keyValue += str[i]*((int)pow(33,len-i));//将字符出现顺序也考虑进去
}
keyValue = (keyValue*3 + 7)%MAX;*/
unsigned int seed = 131;
unsigned int hash = 0;
for(int i=0;i<len;i++)//版本2 BKDhash
{
hash = hash*seed+str[i];
}
keyValue = hash&0x7fffffff;
return keyValue;
}
bool HashTable::put(char *str, int len)
{
int index = hash(str,len)%MAX;
int pre = 1,step = 1;
while(!bullet[index].isEmpty)
{
if(strcmp(bullet[index].str,str) == 0)//相等 重复字符串
{
if(!bullet[index].isDepulicate)//多次重复的字符串最后只输出一次
{
bullet[index].isDepulicate = true;//已经保存了该重复字符串
depulist[depulen] = new char[41];
strcpy(depulist[depulen++],str);
}
return false;
}
else
{
index = (index + pre*step*step)%MAX;
while(index<0)
{
index += MAX;
}
pre = -pre;
step++;
}
}
//存入空桶
strcpy(bullet[index].str,str);
bullet[index].isEmpty = false;
return true;
}
int main()
{
int n;
HashTable *hashtable = new HashTable;
char str[41];
hashtable->depulen = 0;
scanf("%d",&n);
setvbuf(stdin,buffer,_IOFBF,1000000);
for(int i=0;i<n;i++)
{
scanf("%s",str);
hashtable->put(str,strlen(str));
}
if(hashtable->depulen > 0)
{
for(int i=0;i<hashtable->depulen;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 <iostream>
#include <cstdio>
#include <cstdlib>
#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;i<n;i++)//初始化顶点数组
{
graph.adjList[i].data = i+1;
graph.adjList[i].in = 0;
graph.adjList[i].length = 1;
graph.adjList[i].firstEdge = NULL;
}
for(int i = 0;i<m;i++)//输入边信息并构建邻接表(拓扑排序) -邻接矩阵(最长路径)
{
scanf("%d%d",&a,&b);//输入边的端点
EdgeNode *e = new EdgeNode;
e->adjvex = 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;i<graph.numVertexs;i++)
{
if(graph.adjList[i].in == 0)
{
stack[top++] = i;//保存结点在数组中的下标
stk[num++] = i;//入度为0结点数
}
}
while(top!=0)//进行拓扑排序
{
index = stack[--top];//出栈,取出入度为零的结点
for(e = graph.adjList[index].firstEdge;e!=NULL;e=e->nex)//遍历该结点的边表
{
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 <iostream>
#include <cstdio>
#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<r)
{
int i=l,j=r;
int temp = array_x[l];
int temp1 = array_y[l];
while(i<j)
{
while(i<j && array_x[j]>=temp)
j--;
if(i<j)
{
array_x[i] = array_x[j];
array_y[i] = array_y[j];
++i;
}
while(i<j && array_x[i]<=temp)
i++;
if(i<j)
{
array_x[j] = array_x[i];
array_y[j] = array_y[i];
--j;
}
}
array_x[i] = temp;
array_y[i] = temp1;
quickSort(array_x,array_y,l,i-1);
quickSort(array_x,array_y,i+1,r);
}
}
void Merge(int* array,int l,int mid,int r)
{
int i,j,k,n1,n2;
n1 = mid - l +1;
n2 = r - mid;
for(i = 0;i<n1;i++)
{
tempL[i] = array[l+i];
}
for(i=0;i<n2;i++)
{
tempR[i] = array[mid+1+i];
}
i = 0;
j = 0;
for(k=l;k<r && i<n1 && j<n2;k++)
{
if(tempL[i]>tempR[j])//题意各点互异,不会有相等情况
{
array[k] = tempR[j++];//x大y小 不符合条件
}
else
{
array[k] = tempL[i++];
sum += n2 - j;
}
}
while(i<n1)
{
array[k++] = tempL[i++];
}
while(j<n2)
{
array[k++] = tempR[j++];
}
}
void MergeSort(int *array,int l,int r)
{
int mid;
if(l == r)
return;
mid = l+((r-l)>>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<n;++i)
{
scanf("%d %d",&point_x[i],&point_y[i]);
}
quickSort(point_x,point_y,0,n-1);
MergeSort(point_y,0,n-1);
printf("%ld",sum);
return 0;
}
================================================
FILE: LightHouse/LightHouse.pro
================================================
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
LightHouse.cpp
include(deployment.pri)
qtcAddDeployment()
================================================
FILE: LightHouse/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: README.md
================================================
# TsingHuaDataStructOj
学堂在线mooc-清华数据结构与算法(邓俊辉) OJ习题
全部满分AC
================================================
FILE: RangeSearch/RangeSearch.cpp
================================================
#include <iostream>
#include <cstdlib>
#include <cstdio>
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<array[mid]) ? (hi = mid ):(flag = 1,lo = mid + 1);//[lo,mid) 或 [mid+1,hi)
if(e<array[mid])
{
hi = mid;
}
else
{
if(e == array[mid])
flag = 1;
lo = mid +1;
}
}
return --lo;//返回最后一个不大于e的下标
}
int main()
{
int pointNum, cmpNum,count = 0;
cin >> 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 <iostream>
#include <cstdio>
#include <cstdlib>
#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;i<n;i++)//初始化顶点数组
{
graph.adjList[i].data = i+1;
graph.adjList[i].out = 0;
// graph.adjList[i].status = UNVISTED;//输出拓扑排序时需要
graph.adjList[i].firstEdge = NULL;
}
for(int i = 0;i<m;i++)//输入边信息并构建逆邻接表(拓扑排序) -邻接矩阵(最长路径)
{
scanf("%d%d",&a,&b);//输入边的端点
EdgeNode *e = new EdgeNode;
e->adjvex = 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;i<graph.numVertexs;i++)
{
if(graph.adjList[i].out == 0)
{
stack[top++] = i;//保存结点在数组中的下标
}
}
while(top!=0)//拓扑排序
{
index = stack[--top];
sum = viste(&graph.adjList[index]);
if(len<sum)
{
len = sum;
}
}
printf("%d",len);
return 0;
}
//深度优先访问结点-清华OJ超时-未用到拓扑排序结果?待优化
int viste(VertexNode *node)
{
int len = 1,sublen = 0,maxsublen=0;
// if(node->status == 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 <sublen)//求出经过结点最多的子结点
{
maxsublen = sublen;
}
}
printf("%d ",node->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 <iostream>
#include <cstdio>
#include <cstring>
/*
* 思路:将一串数字看做是一个字符串,其全排列总共有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]<str[i])
{
temp++;
}
}
hashVal += temp*factor[7-i];
}
}
};
struct Queue
{
Queue()
{
head = 0;
tail = 0;
length = 0;
}
void push(TOY t)
{
_elem[tail++] = t;
length++;
}
TOY pop()
{
length--;
return _elem[head++];
}
TOY _elem[MAX*2];//模拟队列
int head;
int tail;
int length;
}queue;
void Init()//初始化,计算所有情况并将步数保存到输出数组中
{
TOY firstToy("12345678");//初始状态-康托展开hashVal为0
queue.push(firstToy);//入队
//BFS
while(queue.length>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 <iostream>
#include <cstdio>
#include <cstring>
#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<capacity)
{
strcpy(resultBuffer+resultLen,"push\n");
resultLen += 5;
st[currentSize++] = e;
return true;
}
else
{
return false;
}
}
int top()
{
return st[currentSize-1];
}
int pop()
{
strcpy(resultBuffer+resultLen,"pop\n");
resultLen += 4;
currentSize--;
return st[currentSize-1];
}
bool empty()
{
return (currentSize == 0);
}
bool full()
{
return (currentSize == capacity);
}
private:
int *st;
int currentSize;
int capacity;
};
int main()
{
int m,n,i,j,r;
scanf("%d%d",&n,&m);
if(m == 0)
{
printf("No\n");
return 0;
}
for(i=0;i<n;i++)
{
scanf("%d",&outArray[i]);
}
MyStack stack(m);
i=0,j=0,r=1;
while(i<n)
{
if(outArray[i] == r)
{
if(stack.full())
{
printf("No\n");
return 0;
}
#ifdef DEBUG
cout<<"push "<<r<<endl<<"pop "<<r<<endl;
#endif
strcpy(resultBuffer+resultLen,"push\npop\n");
resultLen += 9;
i++;
r++;
continue;
}
if(outArray[i]<r)
{
if(outArray[i] == stack.top())
{
#ifdef DEBUG
cout<<"pop "<<outArray[i]<<endl;
#endif
stack.pop();
i++;
continue;
}
else
{
printf("No\n");
return 0;
}
}
if(outArray[i] > r)
{
while(outArray[i] > r)
{
if(stack.full())
{
printf("No\n");
return 0;
}
#ifdef DEBUG
cout<<"push "<<r<<endl;
#endif
stack.push(r++);
}
if(stack.full())
{
printf("No\n");
return 0;
}
#ifdef DEBUG
cout<<"push "<<r<<endl<<"pop "<<r<<endl;
#endif
strcpy(resultBuffer+resultLen,"push\npop\n");
resultLen += 9;
r++;
i++;
}
}
printf("%s",resultBuffer);
return 0;
}
================================================
FILE: Tunel/Tunel.cpp
================================================
#include <iostream>
#include <cstdio>
#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 <iostream>
#include <cstring>
#include <cstdio>
#include <iostream>
#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;i<len;++i)
{
ZumaNode *temNode = new ZumaNode(str[i]);
rear->succ = 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;i<n;i++)
{
scanf("%d %c",&arrayposition[i],&arrayBall[i]);
}
counter = 0;
while(n-->0)
{
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;i<listSize;i++)
{
// printf("%c",result->succ->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<iostream>
#include<math.h>
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()
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
SYMBOL INDEX (78 symbols across 12 files)
FILE: BinaryTreeRebuild/binaryTreeRebuild.cpp
function findPos (line 11) | int findPos(int source[],int len,int key)
function rebuild (line 23) | void rebuild(int preTree[],int postTree[],int len)
function main (line 38) | int main()
FILE: BroadCast/broadcast.cpp
type EdgeNode (line 7) | struct EdgeNode /*边表结点*/
type EdgeNode (line 10) | struct EdgeNode
type VertexNode (line 13) | struct VertexNode //顶点表结点
type Graph (line 20) | struct Graph
function main (line 31) | int main()
FILE: Deduplicate/Depulicate.cpp
type HashNode (line 8) | struct HashNode
method HashNode (line 10) | HashNode()
type HashTable (line 20) | struct HashTable
function main (line 80) | int main()
FILE: KahnTopsort/kahntopsortTSP.cpp
type EdgeNode (line 9) | struct EdgeNode /*边表结点*/
type EdgeNode (line 13) | struct EdgeNode
type VertexNode (line 16) | struct VertexNode //顶点表结点
type Graph (line 23) | struct Graph
function main (line 32) | int main()
FILE: LightHouse/LightHouse.cpp
function quickSort (line 11) | void quickSort(int *array_x,int* array_y,int l,int r)
function Merge (line 44) | void Merge(int* array,int l,int mid,int r)
function MergeSort (line 81) | void MergeSort(int *array,int l,int r)
function main (line 92) | int main()
FILE: RangeSearch/RangeSearch.cpp
function cmp (line 5) | int cmp(const void*a, const void *b)
function binarySearch (line 9) | int binarySearch(int *array, int e, int lo, int hi, int &flag)//二分查找,左开右...
function main (line 30) | int main()
FILE: TSP/TSP.cpp
type STATUS (line 8) | enum STATUS
type EdgeNode (line 13) | struct EdgeNode /*边表结点*/
type EdgeNode (line 16) | struct EdgeNode
type VertexNode (line 19) | struct VertexNode //顶点表结点
type Graph (line 26) | struct Graph //图结构
function main (line 36) | int main()
function viste (line 93) | int viste(VertexNode *node)
FILE: Toy/toy.cpp
type TOY (line 18) | struct TOY
method TOY (line 22) | TOY()
method TOY (line 26) | TOY(char *s)
method downUpChange (line 31) | void downUpChange(char *s)//下上交换
method cycleLeftMove (line 40) | void cycleLeftMove(char *s)//循环左移
method centerMove (line 53) | void centerMove(char *s)//中心逆时针旋转
method contor (line 63) | void contor()
type Queue (line 81) | struct Queue
method Queue (line 83) | Queue()
method push (line 89) | void push(TOY t)
method TOY (line 94) | TOY pop()
function Init (line 108) | void Init()//初始化,计算所有情况并将步数保存到输出数组中
function main (line 144) | int main()
FILE: Train/train.cpp
class MyStack (line 11) | class MyStack
method MyStack (line 14) | MyStack(int capacity)
method push (line 20) | bool push(int e)
method top (line 34) | int top()
method pop (line 39) | int pop()
method empty (line 46) | bool empty()
method full (line 50) | bool full()
function main (line 60) | int main()
FILE: Tunel/Tunel.cpp
class Queue (line 8) | class Queue
method Queue (line 11) | Queue(int capacity)
method enQueue (line 19) | void enQueue(int e)
method deQueue (line 25) | int deQueue()
method empty (line 33) | bool empty()
method full (line 37) | bool full()
type dataNode (line 48) | struct dataNode
class DQueue (line 53) | class DQueue
method DQueue (line 56) | DQueue(int capacity)
method removeFront (line 64) | int removeFront()
method dataNode (line 72) | dataNode removeRear()
method insertRear (line 87) | void insertRear(int e)
method dataNode (line 95) | dataNode& getRear()
method dataNode (line 108) | dataNode& getFront()
method empty (line 113) | bool empty()
method full (line 117) | bool full()
function main (line 130) | int main()
FILE: Zuma2/Zuma2.cpp
type ZumaNode (line 8) | struct ZumaNode
method ZumaNode (line 13) | ZumaNode(){}
method ZumaNode (line 14) | ZumaNode(char name):data(name){}
function createList (line 20) | void createList(char *str,int len)
function ZumaNode (line 40) | ZumaNode *findNode(int position)
method ZumaNode (line 13) | ZumaNode(){}
method ZumaNode (line 14) | ZumaNode(char name):data(name){}
function ZumaNode (line 52) | ZumaNode *delRepet(ZumaNode *currentNode,char data)
method ZumaNode (line 13) | ZumaNode(){}
method ZumaNode (line 14) | ZumaNode(char name):data(name){}
function insertNode (line 93) | void insertNode(ZumaNode *currentNode,char c)
function main (line 106) | int main()
FILE: testDeom/main.cpp
function main (line 5) | int main()
Condensed preview — 45 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (142K chars).
[
{
"path": ".gitignore",
"chars": 367,
"preview": "# C++ objects and libs\r\n\r\n*.slo\r\n*.lo\r\n*.o\r\n*.a\r\n*.la\r\n*.lai\r\n*.so\r\n*.dll\r\n*.dylib\r\n\r\n# Qt-es\r\n\r\n/.qmake.cache\r\n/.qmake."
},
{
"path": "BinaryTreeRebuild/BinaryTreeRebuild.pro",
"chars": 192,
"preview": "TEMPLATE = app\r\nCONFIG += console\r\nCONFIG -= app_bundle\r\nCONFIG -= qt\r\n\r\nSOURCES += \\\r\n binaryTreeRebuild.cpp\r\n\r\nincl"
},
{
"path": "BinaryTreeRebuild/binaryTreeRebuild.cpp",
"chars": 1023,
"preview": "#include <iostream>\r\n#include <cstdio>\r\n\r\n#define MAX 10000001\r\nusing namespace std;\r\n\r\n\r\nint preOder[MAX];\r\nint postOde"
},
{
"path": "BinaryTreeRebuild/deployment.pri",
"chars": 7008,
"preview": "# This file was generated by an application wizard of Qt Creator.\r\n# The code below handles deployment to Android and Ma"
},
{
"path": "BinaryTreeRebuild/题目.txt",
"chars": 1825,
"preview": "真二叉树重构(Proper Rebuild)\nDescription\nIn general, given the preorder traversal sequence and postorder traversal sequence of"
},
{
"path": "BroadCast/BroadCast.pro",
"chars": 184,
"preview": "TEMPLATE = app\r\nCONFIG += console\r\nCONFIG -= app_bundle\r\nCONFIG -= qt\r\n\r\nSOURCES += \\\r\n broadcast.cpp\r\n\r\ninclude(depl"
},
{
"path": "BroadCast/broadcast.cpp",
"chars": 3157,
"preview": "#include <iostream>\r\n#include <cstdio>\r\n#define MAX 1000000\r\n\r\nusing namespace std;\r\n//使用邻接表存储图\r\n struct EdgeNode /*边表结点"
},
{
"path": "BroadCast/deployment.pri",
"chars": 7008,
"preview": "# This file was generated by an application wizard of Qt Creator.\r\n# The code below handles deployment to Android and Ma"
},
{
"path": "BroadCast/题目.txt",
"chars": 505,
"preview": "无线广播(Broadcast)\n描述\n某广播公司要在一个地区架设无线广播发射装置。该地区共有n个小镇,每个小镇都要安装一台发射机并播放各自的节目。\n\n不过,该公司只获得了FM104.2和FM98.6两个波段的授权,而使用同一波段的发射机会互"
},
{
"path": "DataStructOj.pro",
"chars": 230,
"preview": "TEMPLATE = subdirs\r\n\r\nSUBDIRS += \\\r\n RangeSearch \\\r\n LightHouse \\\r\n Zuma2 \\\r\n Train \\\r\n Tunel \\\r\n Bina"
},
{
"path": "Deduplicate/Deduplicate.pro",
"chars": 199,
"preview": "TEMPLATE = app\r\nCONFIG += console\r\nCONFIG -= app_bundle\r\nCONFIG -= qt\r\n\r\nSOURCES += \\\r\n Depulicate.cpp\r\n\r\ninclude(dep"
},
{
"path": "Deduplicate/Depulicate.cpp",
"chars": 2351,
"preview": "#include <iostream>\r\n#include <cstring>\r\n#include <cstdio>\r\n#include <cmath>\r\n#define MAX 400003\r\nchar buffer[1000000];/"
},
{
"path": "Deduplicate/deployment.pri",
"chars": 7008,
"preview": "# This file was generated by an application wizard of Qt Creator.\r\n# The code below handles deployment to Android and Ma"
},
{
"path": "Deduplicate/题目.txt",
"chars": 1437,
"preview": "重名剔除(Deduplicate)\r\nDescription\r\nMr. Epicure is compiling an encyclopedia of food. He had collected a long list of candid"
},
{
"path": "KahnTopsort/KahnTopsort.pro",
"chars": 191,
"preview": "TEMPLATE = app\r\nCONFIG += console\r\nCONFIG -= app_bundle\r\nCONFIG -= qt\r\n\r\nSOURCES += \\\r\n kahntopsortTSP.cpp\r\n\r\ninclude"
},
{
"path": "KahnTopsort/TSP.txt",
"chars": 1678,
"preview": "Description\r\nShrek is a postman working in the mountain, whose routine work is sending mail to n villages. Unfortunately"
},
{
"path": "KahnTopsort/deployment.pri",
"chars": 7008,
"preview": "# This file was generated by an application wizard of Qt Creator.\r\n# The code below handles deployment to Android and Ma"
},
{
"path": "KahnTopsort/kahntopsortTSP.cpp",
"chars": 2502,
"preview": "#include <iostream>\r\n#include <cstdio>\r\n#include <cstdlib>\r\n#define MAX 1000000\r\n#define GETMAX(x,y) ((x) > (y) ? (x):(y"
},
{
"path": "LightHouse/LightHouse.cpp",
"chars": 2201,
"preview": "#include <iostream>\r\n#include <cstdio>\r\n#define MAX 1000001\r\nint point_x[MAX];\r\nint point_y[MAX];\r\nint tempL[MAX];\r\nint "
},
{
"path": "LightHouse/LightHouse.pro",
"chars": 156,
"preview": "TEMPLATE = app\r\nCONFIG += console\r\nCONFIG -= app_bundle\r\nCONFIG -= qt\r\n\r\nSOURCES += \\\r\n LightHouse.cpp\r\n\r\ninclude(dep"
},
{
"path": "LightHouse/deployment.pri",
"chars": 7008,
"preview": "# This file was generated by an application wizard of Qt Creator.\r\n# The code below handles deployment to Android and Ma"
},
{
"path": "README.md",
"chars": 59,
"preview": "# TsingHuaDataStructOj\n学堂在线mooc-清华数据结构与算法(邓俊辉) OJ习题\n全部满分AC\n"
},
{
"path": "RangeSearch/RangeSearch.cpp",
"chars": 1644,
"preview": "#include <iostream>\r\n#include <cstdlib>\r\n#include <cstdio>\r\nusing namespace std;\r\nint cmp(const void*a, const void *b)\r\n"
},
{
"path": "RangeSearch/RangeSearch.pro",
"chars": 157,
"preview": "TEMPLATE = app\r\nCONFIG += console\r\nCONFIG -= app_bundle\r\nCONFIG -= qt\r\n\r\nSOURCES += \\\r\n RangeSearch.cpp\r\n\r\ninclude(de"
},
{
"path": "RangeSearch/deployment.pri",
"chars": 7008,
"preview": "# This file was generated by an application wizard of Qt Creator.\r\n# The code below handles deployment to Android and Ma"
},
{
"path": "RangeSearch/题目.txt",
"chars": 1088,
"preview": "范围查询(Range)\nDescriptioin\nLet S be a set of n integral points on the x-axis. For each given interval [a, b], you are aske"
},
{
"path": "TSP/TSP.cpp",
"chars": 2480,
"preview": "#include <iostream>\r\n#include <cstdio>\r\n#include <cstdlib>\r\n#define MAX 100\r\n\r\nusing namespace std;\r\n//使用邻接表存储图-基于DFS的拓扑"
},
{
"path": "TSP/TSP.pro",
"chars": 180,
"preview": "TEMPLATE = app\r\nCONFIG += console\r\nCONFIG -= app_bundle\r\nCONFIG -= qt\r\n\r\nSOURCES += \\\r\n TSP.cpp\r\n\r\ninclude(deployment"
},
{
"path": "TSP/TSP.txt",
"chars": 1678,
"preview": "Description\r\nShrek is a postman working in the mountain, whose routine work is sending mail to n villages. Unfortunately"
},
{
"path": "TSP/deployment.pri",
"chars": 7008,
"preview": "# This file was generated by an application wizard of Qt Creator.\r\n# The code below handles deployment to Android and Ma"
},
{
"path": "Toy/Toy.pro",
"chars": 149,
"preview": "TEMPLATE = app\r\nCONFIG += console\r\nCONFIG -= app_bundle\r\nCONFIG -= qt\r\n\r\nSOURCES += \\\r\n toy.cpp\r\n\r\ninclude(deployment"
},
{
"path": "Toy/deployment.pri",
"chars": 7008,
"preview": "# This file was generated by an application wizard of Qt Creator.\r\n# The code below handles deployment to Android and Ma"
},
{
"path": "Toy/toy.cpp",
"chars": 3599,
"preview": "#include <iostream>\r\n#include <cstdio>\r\n#include <cstring>\r\n\r\n/*\r\n* 思路:将一串数字看做是一个字符串,其全排列总共有8!,每种排列对应一个状态\r\n* 有的状态能够通过题目所"
},
{
"path": "Train/Train.pro",
"chars": 151,
"preview": "TEMPLATE = app\r\nCONFIG += console\r\nCONFIG -= app_bundle\r\nCONFIG -= qt\r\n\r\nSOURCES += \\\r\n train.cpp\r\n\r\ninclude(deployme"
},
{
"path": "Train/deployment.pri",
"chars": 7008,
"preview": "# This file was generated by an application wizard of Qt Creator.\r\n# The code below handles deployment to Android and Ma"
},
{
"path": "Train/train.cpp",
"chars": 2863,
"preview": "#include <iostream>\r\n#include <cstdio>\r\n#include <cstring>\r\n\r\n#define MAX 20000000\r\n//#define DEBUG\r\nusing namespace std"
},
{
"path": "Tunel/Tunel.cpp",
"chars": 3524,
"preview": "#include <iostream>\r\n#include <cstdio>\r\n#define MAX 20000000\r\nusing namespace std;\r\nchar resultBuff[10000000];\r\nchar buf"
},
{
"path": "Tunel/Tunel.pro",
"chars": 151,
"preview": "TEMPLATE = app\r\nCONFIG += console\r\nCONFIG -= app_bundle\r\nCONFIG -= qt\r\n\r\nSOURCES += \\\r\n Tunel.cpp\r\n\r\ninclude(deployme"
},
{
"path": "Tunel/deployment.pri",
"chars": 7008,
"preview": "# This file was generated by an application wizard of Qt Creator.\r\n# The code below handles deployment to Android and Ma"
},
{
"path": "Zuma2/Zuma2.cpp",
"chars": 3479,
"preview": "#include <iostream>\r\n#include <cstring>\r\n#include <cstdio>\r\n#include <iostream>\r\n#define MAX 100000000\r\nusing namespace "
},
{
"path": "Zuma2/Zuma2.pro",
"chars": 151,
"preview": "TEMPLATE = app\r\nCONFIG += console\r\nCONFIG -= app_bundle\r\nCONFIG -= qt\r\n\r\nSOURCES += \\\r\n Zuma2.cpp\r\n\r\ninclude(deployme"
},
{
"path": "Zuma2/deployment.pri",
"chars": 7008,
"preview": "# This file was generated by an application wizard of Qt Creator.\r\n# The code below handles deployment to Android and Ma"
},
{
"path": "testDeom/deployment.pri",
"chars": 7008,
"preview": "# This file was generated by an application wizard of Qt Creator.\r\n# The code below handles deployment to Android and Ma"
},
{
"path": "testDeom/main.cpp",
"chars": 334,
"preview": "#include<iostream>\r\n#include<math.h>\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n int count,h;\r\n cin>>h;\r\n count = "
},
{
"path": "testDeom/testDeom.pro",
"chars": 158,
"preview": "TEMPLATE = app\r\nCONFIG += console\r\nCONFIG -= app_bundle\r\nCONFIG -= qt\r\nCONFIG += C++11\r\nSOURCES += main.cpp\r\n\r\ninclude(d"
}
]
About this extraction
This page contains the full source code of the zhousoft/TsingHuaDataStructOj GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 45 files (121.2 KB), approximately 33.9k tokens, and a symbol index with 78 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.