随笔分类 - 搜索
摘要:题意:可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验。魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老。年迈的国王正是心急如焚,告招天下勇士来拯救公主。不过公主早已习以为常,她深信智勇的骑士LJ肯定能将她救出。现据密探所报,公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输机用#表示,墙用*表示,平地用.表示。骑士们一进入时空传输机就会被转到另一层的相对位置,但如果被转到的位置是墙的话,那骑士们就会被撞死。骑士们在一层中只能前后左右移动,每移动一格花1时刻。层间的移动只能通过时空传输机,且
阅读全文
摘要:题意:Ignatius花了一个星期的时间终于找到了传说中的宝藏,宝藏被放在一个房间里,房间的门用密码锁起来了,在门旁边的墙上有一些关于密码的提示信息:密码是一个C进制的数,并且只能由给定的M个数字构成,同时密码是一个给定十进制整数N(0<=N<=5000)的正整数倍(如果存在多个满足条件的数,那么最小的那个就是密码),如果这样的密码存在,那么当你输入它以后门将打开,如果不存在这样的密码......那就把门炸了吧.注意:由于宝藏的历史久远,当时的系统最多只能保存500位密码.因此如果得到的密码长度大于500也不能用来开启房门,这种情况也被认为密码不存在.分析:大数取模+广搜。注意0的
阅读全文
摘要:题意: M2%10x=N ,给出n值,找到满足等式的最小m值,x=(0,1,2...)。分析: 由于M的位数不可能超过n的位数,可以从n的最后一位开始逐位搜索。#include<stdio.h>#include<string.h>const __int64 INF=999999999;__int64 num[25];__int64 min(__int64 a,__int64 b){ return a<b?a:b;}__int64 ans,n;int top;__int64 p;void dfs(int pos,__int64 w,__int64 res){ if(
阅读全文
摘要:题意: 给定两个字符串,输出他们的最长公共子序列,要求字典序最小。分析:先用LCS算法将最长公共子序列的长度len求出来,还有数组f[i][j],表示字符串a前i个字符和字符串b前j个字符的最长公共子序列的长度,时间复杂度O(n*m)。然后将两个字符串逆序,方便求最小字典序。用两个二维数组分别记录两个字符串a和b前i个字符中字符c出现的最后位置,la[i][c],字符串a的前i个字符中,字符c出现的最后位置。la[i][c],字符串b的前i个字符中,字符c出现的最后位置。然后从最大长度len到1枚举答案的每个位置的字符,直接暴力会超时,需要优化。利用前面的f[][],la[],lb[]数组进行
阅读全文
摘要:分析: 给一个地图,一个人从起点开始,身上有一个定时炸弹,时间为6,每走一步花费一个时间,走到标号为4 的点上时时间重置, 问从起点到终点最少需要经过多少步。分析: 直接广搜,加上对状态的判重。。。View Code #include<stdio.h>#include<string.h>struct node{ int x,y,time,step;}q[1000],st,en,tt,xx;int f[8]={-1,0,0,1,0,-1,1,0};int a[10][10];int b[10][10];int v[10][10][7];int main(){ int fr
阅读全文
摘要:题意: 给你n 木棍碎片,要求还原原木棍,且原木棍等长,问最短长度是多少。分析: 各种剪枝。View Code /*1:越长的木棍对后面木棍的约束力越大,因此要把小木棍排序, 按木棍长度从大到小搜索,这样就能在尽可能靠近根的地方 剪枝。 2:当出现加上某根木棍恰好能填满一根原始木棍,但由在后面的 搜索中失败了,就不必考虑其他木棍了,直接退出当前的枚举。 3:考虑每根原始木棍的第一根木棍,如果当前枚举的木棍长度无 法得出合法解,就不必考虑下一根木棍了,当前木棍一定是作 为某根原始木棍的第一根木棍的,现在不行,以后也不可能得 出合法解。也就是说每根原始木棍的...
阅读全文
摘要:题意: 给你个n*n 的位图,让你放大k 倍后输出。分析: 最终图案的每一部分都是有原图相应位置扩大而来,可以用递归实现。View Code #include<stdio.h>#include<math.h>#include<string.h>char a[30][30];char v[3005][3005];int n;void dfs(int k,int x,int y){ int tmp,i,j,tot,l; if(k==1) { for(i=x;i<x+n;i++) for(j=y;j<y+n;j++) ...
阅读全文
摘要:DescriptionThe 15-puzzle has been around for over 100 years; even if you don't know it by that name, you've seen it. It is constructed with 15 sliding tiles, each with a number from 1 to 15 on it, and all packed into a 4 by 4 frame with one tile missing. Let's call the missing tile '
阅读全文
摘要:DescriptionConsider equations having the following form:a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0The coefficients are given integers from the interval [-50,50].It is consider a solution a system (x1, x2, x3, x4, x5) that verifies the equation, xi∈[-50,50], xi != 0, any i∈{1,2,3,4,5}.Determine how many sol
阅读全文
摘要:DescriptionJimmy experiences a lot of stress at work these days, especially since his accident made working difficult. To relax after a hard day, he likes to walk home. To make things even nicer, his office is on one side of a forest, and his house is on the other. A nice walk through the forest, se
阅读全文
摘要:Problem DescriptionHow can anagrams result from sequences of stack operations? There are two sequences of stack operators which can convert TROT to TORT: [i i i i o o o oi o i i o o i o]where i stands for Push and o stands for Pop. Your program should, given pairs of words produce sequences of stack
阅读全文
摘要:Problem DescriptionHogwarts正式开学以后,Harry发现在Hogwarts里,某些楼梯并不是静止不动的,相反,他们每隔一分钟就变动一次方向. 比如下面的例子里,一开始楼梯在竖直方向,一分钟以后它移动到了水平方向,再过一分钟它又回到了竖直方向.Harry发现对他来说很难找到能使得他最快到达目的地的路线,这时Ron(Harry最好的朋友)告诉Harry正好有一个魔法道具可以帮助他寻找这样的路线,而那个魔法道具上的咒语,正是由你纂写的.Input测试数据有多组,每组的表述如下:第一行有两个数,M和N,接下来是一个M行N列的地图,'*'表示障碍物,'.
阅读全文
摘要:Problem Description在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。Input输入含有多组测试数据。 每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目。 n <= 8 , k <= n 当为-1 -1时表示输入结束。 随后的n行描述了棋盘的形状:每行有n个字符,其中 # 表示棋盘区域, . 表示空白区域(数据保证不出现多余的空白行或者空白列)。Outpu
阅读全文
摘要:DescriptionA university network is composed of N computers. System administrators gathered information on the traffic between nodes, and carefully divided the network into two subnetworks in order to minimize traffic between parts. A disgruntled computer science student Vasya, after being expelled f
阅读全文
摘要:Problem DescriptionFor a boat on a large body of water, strong currents can be dangerous, but with careful planning, they can be harnessed to help the boat reach its destination. Your job is to help in that planning.At each location, the current flows in some direction. The captain can choose to eit
阅读全文
摘要:DescriptionYou are given two pots, having the volume of A and B liters respectively. The following operations can be performed:FILL(i) fill the pot i (1 ≤ i ≤ 2) from the tap;DROP(i) empty the pot ito the drain;POUR(i,j) pour from pot i to pot j; after this operation either the pot j is full (and th
阅读全文
摘要:DescriptionYou are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonally and the maze is surrounded by solid
阅读全文
摘要:DescriptionThe cornfield maze is a popular Halloween treat. Visitors are shown the entrance and must wander through the maze facing zombies, chainsaw-wielding psychopaths, hippies, and other terrors on their quest to find the exit. One popular maze-walking strategy guarantees that the visitor will e
阅读全文


浙公网安备 33010602011771号