
刷题记录
文章平均质量分 73
lxlybytwo
这个作者很懒,什么都没留下…
展开
-
PAT2016甲级第四题——先根后根求中根
先根后根不能唯一确定中根的情况:左子树或右子树为空。相对于先根中根确定后根或者后根中根确定先根来说,注意长度为1的变化。先上先根中根求后根的代码:#include #include #include void gettree(char* pre,char* in,char* post,int length){ i原创 2016-09-16 22:42:47 · 486 阅读 · 0 评论 -
算法分析与复杂性理论 第一次上机 2的幂次方表示
总时间限制: 1000ms 内存限制: 65536kB描述任何一个正整数都可以用2的幂次方表示。例如: 137=27+23+20同时约定方次用括号来表示,即ab可表示为a(b)。由此可知,137可表示为: 2(7)+2(3)+2(0)进一步:7=22+2+20(21用2表示) 3=2+20所以最后137可原创 2017-09-16 11:17:10 · 260 阅读 · 0 评论 -
算法设计与复杂性原理 第一次上机 玛雅历
总时间限制: 1000ms 内存限制: 65536kB描述上周末,M.A. Ya教授对古老的玛雅有了一个重大发现。从一个古老的节绳(玛雅人用于记事的工具)中,教授发现玛雅人使用了一个一年有365天的叫做Haab的历法。这个Haab历法拥有19个月,在开始的18个月,一个月有20天,月份的名字分别是pop, no, zip, zotz, tzec, xul, yoxkin, mo原创 2017-09-14 20:21:27 · 385 阅读 · 0 评论 -
算法分析与复杂性原理 第一次上机 二叉树的操作
总时间限制: 1000ms 内存限制: 65535kB描述给定一棵二叉树,在二叉树上执行两个操作:1. 节点交换把二叉树的两个节点交换。2. 前驱询问询问二叉树的一个节点对应的子树最左边的节点。输入第一行输出一个整数t(t 对于每组测试数据,第一行输入两个整数n m,n代表二叉树节点的个数,m代表操作的次数。随后输入n行,每行包含原创 2017-09-15 16:18:08 · 447 阅读 · 0 评论 -
算法分析与复杂性原理 第一次上机 棋盘问题
总时间限制: 1000ms 内存限制: 65536kB描述在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。输入输入含有多组测试数据。每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及原创 2017-09-14 20:24:43 · 277 阅读 · 0 评论 -
算法设计 第二次上机 The Unique MST
总时间限制: 1000ms 内存限制: 65536kB描述Given a connected undirected graph, tell if its minimum spanning tree is unique.Definition 1 (Spanning Tree): Consider a connected, undirected graph G = (V, E).原创 2017-11-07 15:48:39 · 228 阅读 · 0 评论 -
算法分析 第二次上机 Yogurt factory
总时间限制: 1000ms 内存限制: 65536kB描述The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the next N (1 <= N <= 10,000) weeks, the price of milk and labor will fluctuate w原创 2017-11-07 15:48:52 · 252 阅读 · 0 评论 -
算法分析 第二次上机 Butterfly
可以使用bfs与并查集。注意bfs使用时,压入队列的数值要标为已访问,否则会导致节点多次压入队列,造成TTL。#include #include #include #include #include using namespace std;int relation[1005][1005];bool visited[1005];bool type[1005原创 2017-11-07 15:49:11 · 498 阅读 · 0 评论 -
算法设计与复杂性分析 第二次上机 Dynamic Median
总时间限制: 3000ms 内存限制: 65536kB描述设计一个数据结构,初始为空,支持以下操作:(1)增加一个元素,要求在log(n)时间内完成,其中n是该数据结构中当前元素的个数。注意:数据结构中允许有重复的元素。(2)返回当前元素集合的中位数,要求在常数时间内完成。如果当前元素的个数为偶数,那么返回下中位数(即两个中位数中较小的一个)。(3)删除原创 2017-11-07 15:49:23 · 485 阅读 · 0 评论 -
算法设计与复杂性 模拟 to europe
总时间限制: 1000ms 内存限制: 65536kB描述Almost everyone in the candidate states wants to `go to Europe'', although most of the people have very vague ideas about what this actually means. Anyway, immediate原创 2017-12-28 16:05:12 · 301 阅读 · 0 评论 -
算法设计与复杂度 模拟考 Palindrome
总时间限制: 3000ms 内存限制: 65536kB描述A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a program which, given a原创 2017-12-29 17:31:43 · 320 阅读 · 0 评论 -
算法分析与复杂性理论 第三题 Til the Cows Come Home
总时间限制: 1000ms 内存限制: 65536kB描述Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bessie needs her原创 2017-09-15 21:18:01 · 287 阅读 · 0 评论 -
算法设计与复杂性理论 第一次上机 仙岛求药
总时间限制: 1000ms 内存限制: 65536kB描述少年李逍遥的婶婶病了,王小虎介绍他去一趟仙灵岛,向仙女姐姐要仙丹救婶婶。叛逆但孝顺的李逍遥闯进了仙灵岛,克服了千险万难来到岛的中心,发现仙药摆在了迷阵的深处。迷阵由M×N个方格组成,有的方格内有可以瞬秒李逍遥的怪物,而有的方格内则是安全。现在李逍遥想尽快找到仙药,显然他应避开有怪物的方格,并经过最少的方格,而且那里会有神秘人物等原创 2017-09-15 23:24:42 · 399 阅读 · 0 评论 -
算法设计与复杂性 第五次上机 Arbitrage
总时间限制: 1000ms 内存限制: 65536kB描述Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example,原创 2018-01-06 18:39:01 · 257 阅读 · 0 评论 -
算法设计与复杂性 第四次上机 LITTLE SHOP OF FLOWERS
总时间限制: 1000ms 内存限制: 65536kB描述You want to arrange the window of your flower shop in a most pleasant way. You have F bunches of flowers, each being of a different kind, and at least as many原创 2018-01-06 20:18:08 · 297 阅读 · 0 评论 -
九度1040
#include #include #include #include #include #include #include using namespace std;bool isPrime(int n){ for(int i=2;i<=sqrt(n);i++) if(n%i==0) return false; retu原创 2016-09-24 21:29:03 · 366 阅读 · 0 评论 -
九度1099
#include #include #include #include #include #include using namespace std;int cmp(const void* a,const void *b){ return strcmp((char*)a,(char*)b);}int main(){ string str; char原创 2016-09-24 21:23:49 · 262 阅读 · 0 评论 -
九度1104
注意多组数据输入#include #include #include #include #include #include #include using namespace std;int main(){ int n,a; while(cin>>n>>a) { int cnt=0; long long int res原创 2016-09-24 15:40:06 · 227 阅读 · 0 评论 -
九度1083 特殊乘法
水题#include #include #include int main(){ char left[15]; char right[15]; int res; int llen,rlen; int i,j; while(~scanf("%s%s",left,right)) {原创 2016-09-16 23:07:53 · 301 阅读 · 0 评论 -
九度1084 整数拆分
递归。当n为奇数,f(n)与f(n-1)相同;当n为偶数,f(n)分为包括1和不包括1,包括1的拆分数为f(n-1)=f(n-2),不包括1的拆分等于f(n/2)。可以采用只记录偶数的方式节省空间。#include #include #include int data[1000005];int main(){ int n; int i; dat原创 2016-09-16 23:45:47 · 251 阅读 · 0 评论 -
九度1067 n的阶乘
n#include #include #include int main(){ long long res; int n; int i; while(~scanf("%d",&n)) { res=1; for(i=1;i<=n;i++) res=res*i; printf(原创 2016-09-17 16:53:42 · 296 阅读 · 0 评论 -
九度1076 N的阶乘
n数值较小,可以直接与每位上的数相乘。#include #include #include void reverse(char * s){ char temp; int i,j; for(i=0,j=strlen(s)-1;i<j;i++,j--) { temp=s[i]; s[i]=s[j]; s[j]原创 2016-09-17 18:29:21 · 657 阅读 · 0 评论 -
九度1088
水题,但是注意memset按字节赋值#include #include #include int tree[10005];int main(){ int l,m; int i,j; int le,ri; int count; while(~scanf("%d%d",&l,&m)) { memset(tree,1,4*原创 2016-09-17 19:56:22 · 347 阅读 · 0 评论 -
九度1061
用冒泡#include #include #include int main(){ int n; char name[1000][105]; int age[1000],score[1000]; int i,flag; int rank[1000]; int temp; while(~scanf("%d",&n)) {原创 2016-09-17 20:27:46 · 241 阅读 · 0 评论 -
九度1069
涉及string的substr、find函数,以及map及其iterator使用方式。#include #include #include #include #include #include using namespace std;int main(){ int n,m; int i; int index; string str,id,in原创 2016-09-17 22:58:40 · 338 阅读 · 0 评论 -
九度1087
#include #include #include #include #include #include #include #include using namespace std;int main(){ int n; int m; int res; while(cin>>n) { for(int i=0;i<n;i原创 2016-09-17 23:12:43 · 273 阅读 · 0 评论 -
九度1207
最暴力方法,但是结果超时。#include #include #include #include #include #include #include #include using namespace std;int main(){ int n; int res; while(cin>>n) { res=0;原创 2016-09-17 23:29:28 · 254 阅读 · 0 评论 -
九度1082
C实现#include #include #include int main(){ char agency[1005][16]; char server[2005][16]; int n,m; int i,j; int flag; int res; int start; int maxl; while(~scan原创 2016-09-18 18:23:22 · 235 阅读 · 0 评论 -
九度1077 最大子序列和
dp[i]=max{dp[i-1]+value[i],value[i]}包含第i个元素的长为i的子序列最大和。原创 2016-09-18 18:24:37 · 229 阅读 · 0 评论 -
九度1080
超时#include #include #include #include using namespace std;int main(){ int n,m; string str; string result; while(cin>>m>>n) { cin>>str; result.clear();原创 2016-09-18 22:14:08 · 277 阅读 · 0 评论 -
九度1081矩阵二分法
再次分析题目,会发现递推公式进而推出问题转化为求这里要用到 矩阵二分乘法。矩阵二分乘法是一种有效的快速计算矩阵幂的算法。矩阵二分乘法通常可以将线性递推问题O(n)时间缩短到O(log(n))。#include #include #include #include usi原创 2016-09-18 23:15:42 · 345 阅读 · 0 评论 -
九度1092
fibonacci数列,水题#include #include #include #include #include #include #include using namespace std;int main(){ int n; int fib[35]; fib[0]=0; fib[1]=1; for(int i=2;i<=30;原创 2016-09-24 14:41:50 · 238 阅读 · 0 评论 -
算法设计与复杂性 Raid
总时间限制: 1000ms 内存限制: 65536kB描述After successive failures in the battles against the Union, the Empire retreated to its last stronghold. Depending on its powerful defense system, the Em原创 2018-01-07 12:58:59 · 362 阅读 · 0 评论