描述 公主被恶人抓走,被关押在牢房的某个地方。牢房用N*M (N, M <= 200)的矩阵来表示。矩阵中的每项可以代表道路(@)、墙壁(#)、和守卫(x)。 英勇的骑士(r)决定孤身一人去拯救公主(a)。我们假设拯救成功的表示是“骑士到达了公主所在的位置”。由于在通往公主所在位置的道路中可能遇到守卫,骑士一旦遇到守卫,必须杀死守卫才能继续前进。 现假设骑士可以向上、下、左、右四个方向移动,每移动一个位置需要1个单位时间,杀死一个守卫需要花费额外的1个单位时间。同时假设骑士足够强壮,有能力杀死所有的守卫。 给定牢房矩阵,公主、骑士和守卫在矩阵中的位置,请你计算拯救行动成功需要花费最短时间。 输入 第一行为一个整数S,表示输入的数据的组数(多组输入) 随后有S组数据,每组数据按如下格式输入 1、两个整数代表N和M, (N, M <= 200). 2、随后N行,每行有M个字符。”@”代表道路,”a”代表公主,”r”代表骑士,”x”代表守卫, “#”代表墙壁。 输出 如果拯救行动成功,输出一个整 继续阅读 >>


余海 16/12/04 02:01:11
Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, }; 它表示一个迷宫,其中的1表示墙壁,0表示可以走的路,只能横着走或竖着走,不能斜着走,要求编程序找出从左上角到右下角的最短路线。 Input 一个5 × 5的二维数组,表示一个迷宫。数据保证有唯一解。 Output 左上角到右下角的最短路径,格式如样例所示。 Sample Input 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 1 0 Sample Output (0, 0) (1, 0) (2, 0) (2, 1) (2, 2) (2, 3) (2, 4) (3, 4) (4, 4) 思路 递归打印路径 /***************************************************** 继续阅读 >>


余海 16/12/03 22:15:39
Description Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,000) on a number line and the cow is at a point K (0 ≤ K ≤ 100,000) on the same number line. Farmer John has two modes of transportation: walking and teleporting. Walking: FJ can move from any point X to the points X - 1 or X + 1 in a single minute Teleporting: FJ can move from any point X to the point 2 × X in a single minute. If t 继续阅读 >>


余海 16/12/03 19:49:22
Problem Description Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个A*B*C的立方体,可以被表示成A个B*C的矩阵,刚开始Ignatius被关在(0,0,0)的位置,离开城堡的门在(A-1,B-1,C-1)的位置,现在知道魔王将在T分钟后回到城堡,Ignatius每分钟能从一个坐标走到相邻的六个坐标中的其中一个.现在给你城堡的地图,请你计算出Ignatius能否在魔王回来前离开城堡(只要走到出口就算离开城堡,如果走到出口的时候魔王刚好回来也算逃亡成功),如果可以请输出需要多少分钟才能离开,如果不能则输出-1. Input 输入数据的第一行是一个正整数K,表明测试数据的数量.每组测试数据的第一行是四个正整数A,B,C和T(1<=A,B,C<=50,1<=T<=1000),它们分别代表城堡的大小和魔王回来的时间.然后是A块输入数据(先是第0块,然后是第1块,第2块……),每块输入数据有B行,每行有C个正整数,代表迷宫的布局,其中0代表路, 继续阅读 >>


余海 16/12/03 18:42:18
前言 服务端而言,对于每一个新的连接我们都需要去保存其基本信息,如ip地址,套接字fd,也需要赋予其唯一标识如用户名。 这里,我们来谈谈对用户连接的封装。 用户连接需要哪些数据 1. 套接字描述符 sockfd 执行读写操作时当然不可缺 2. 连接信息 sockaddr 基本信息的保存 3. 用户缓存区 Buffer 非阻塞读写不可缺 4. 唯一标识 服务端进行消息转发时不可能根据sockfd去进行查找,所以我们需要对每一个连接有一个唯一标识,用于对其进行检索 关于Buffer细节可看Epoll-ET模式下非阻塞读写之Buffer的封装 用户连接需要哪些操作 1. 读 epoll-Et模式下,读必须将缓冲区全部读完,否则不会再次触发 2. 写 epoll-Et模式下,写必须将所写数据全部写入或是写到缓冲区满,否则不 继续阅读 >>


师毅 16/12/03 16:36:16
D. Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and the amount of tax he has to pay is calculated as the maximum divisor of n (not equal to n, of course). For example, if n = 6 then Funt has to pay 3 burles, whi 继续阅读 >>


楚东方 16/12/03 14:51:43
C. Tennis Championship time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be nplayers participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately. Organizers are still arrangin 继续阅读 >>


楚东方 16/12/03 14:40:27
B. Urbanization time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are n people who plan to move to the cities. The wealth of the i of them is equal to ai. Authorities plan to build two cities, first for n1 people and s 继续阅读 >>


楚东方 16/12/03 14:38:52
A. Ostap and Grasshopper time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grassh 继续阅读 >>


楚东方 16/12/03 14:36:39
E - 487-3279 Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practice POJ 1002 Description Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spell a memorable word or phrase. For example, you can call the University of Waterloo by dialing the memorable TUT-GLOP. Sometimes only part of the number 继续阅读 >>


楚东方 16/12/03 14:30:48