HDU-2612 Find a way

Find a way (HDU - 2612) 题面 Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year, yifenfei have many people to meet. Especially a good friend Merceki. Yifenfei’s home is at the countryside, but Merceki’s home is in the center of city. So yifenfei made arrangements with Merceki to meet at a KFC. There are many KFC in Ningbo, they want to choose one that let the total time to it be most smallest. Now give you a Ningbo map, Both yifenfei and Merceki can move up, down ,left, right to the adjacent road by cost 11 minutes. ...

2018-03-23 · Lordash

HDU-1495 非常可乐

非常可乐 (HDU - 1495) 题面 大家一定觉的运动以后喝可乐是一件很惬意的事情,但是seeyou却不这么认为。因为每次当seeyou买了可乐以后,阿牛就要求和seeyou一起分享这一瓶可乐,而且一定要喝的和seeyou一样多。但seeyou的手中只有两个杯子,它们的容量分别是N 毫升和M 毫升 可乐的体积为S (S<101)毫升 (正好装满一瓶) ,它们三个之间可以相互倒可乐 (都是没有刻度的,且 S==N+M,101>S>0,N>0,M>0) 。聪明的ACMER你们说他们能平分吗?如果能请输出倒可乐的最少的次数,如果不能输出"NO"。 ...

2018-03-23 · Lordash

HDU-1241 Oil Deposits

Oil Deposits (HDU - 1241) 题面 The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It then analyzes each plot separately, using sensing equipment to determine whether or not the plot contains oil. A plot containing oil is called a pocket. If two pockets are adjacent, then they are part of the same oil deposit. Oil deposits can be quite large and may contain numerous pockets. Your job is to determine how many different oil deposits are contained in a grid. ...

2018-03-23 · Lordash

POJ-3984 迷宫问题

迷宫问题 (POJ - 3984) 题面 定义一个二维数组: 1int maze[5][5] = { 2 0, 1, 0, 0, 0, 3 0, 1, 0, 1, 0, 4 0, 0, 0, 0, 0, 5 0, 1, 1, 1, 0, 6 0, 0, 0, 1, 0, 7}; 它表示一个迷宫,其中的1表示墙壁,0表示可以走的路,只能横着走或竖着走,不能斜着走,要求编程序找出从左上角到右下角的最短路线。 ...

2018-03-23 · Lordash

UVA-11624 Fire!

Fire! (UVA - 11624) 题面 思路 先跑一次bfs求出火蔓延到每一格的时间,再以此为限制对人跑bfs求解,注意有多个起火点 代码 1using namespace std; 2typedef long long ll; 3const int inf = 0x3f3f3f3f; 4const int N = 1e3+5; 5 6char b[N][N] = {{0}}; 7bool vis[N][N] = {{0}}; 8int t[N][N] = {{0}}; 9int T, n, m, ans = 0; 10 11int dx[] = { 1, -1, 0, 0}; 12int dy[] = { 0, 0, 1, -1}; 13 14struct F { 15 int x, y; 16 int step; 17}; 18 19struct P { 20 int x, y; 21 int step; 22}; 23queue<F> f; 24 25void pre() { 26 memset(vis, 0, sizeof(vis)); 27 while(!f.empty()) { 28 F tf = f.front(); 29 f.pop(); 30 31 F nf = tf; 32 for(int i=0; i<4; i++) { 33 int x = nf.x = tf.x+dx[i]; 34 int y = nf.y = tf.y+dy[i]; 35 36 if(x<0 || x>=n || y<0 || y>=m) { 37 continue; 38 } 39 40 if(!vis[x][y] && b[x][y]=='.') { 41 nf.step = tf.step+1; 42 f.push(nf); 43 vis[x][y] = 1; 44 t[x][y] = nf.step; 45 } 46 } 47 } 48} 49 50bool bfs(int x, int y) { 51 memset(vis, 0, sizeof(vis)); 52 53 P sp; 54 sp.x = x; 55 sp.y = y; 56 sp.step = 0; 57 58 queue<P> q; 59 q.push(sp); 60 vis[x][y] = 1; 61 62 while(!q.empty()) { 63 P tp = q.front(); 64 q.pop(); 65 66 P np = tp; 67 for(int i=0; i<4; i++) { 68 int x = np.x = tp.x+dx[i]; 69 int y = np.y = tp.y+dy[i]; 70 71 if(x<0 || x>=n || y<0 || y>=m) { 72 ans = tp.step+1; 73 return true; 74 } 75 76 if(!vis[x][y] && b[x][y]=='.' && tp.step+1<t[x][y]) { 77 np.step = tp.step+1; 78 q.push(np); 79 vis[x][y] = 1; 80 } 81 } 82 } 83 return false; 84} 85 86int main(void) { 87 scanf("%d", &T); 88 for(int cs=1; cs<=T; cs++) { 89 memset(t, inf, sizeof(t)); 90 scanf("%d%d", &n, &m); 91 int x, y; 92 for(int i=0; i<n; i++) { 93 for(int j=0; j<m; j++) { 94 scanf(" %c", &b[i][j]); 95 if(b[i][j]=='F') { 96 F sf; 97 sf.x = i; 98 sf.y = j; 99 sf.step = 0; 100 t[i][j] = 0; 101 f.push(sf); 102 } else if(b[i][j]=='J') { 103 x = i; 104 y = j; 105 } 106 } 107 } 108 pre(); 109 if(bfs(x, y)) 110 printf("%d\n", ans); 111 else 112 printf("IMPOSSIBLE\n"); 113 } 114 return 0; 115}

2018-03-23 · Lordash

FZU-2150 Fire Game

Fire Game (FZU - 2150) 题面 Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this board is consisting of grass or just empty and then they start to fire all the grass. Firstly they choose two grids which are consisting of grass and set fire. As we all know, the fire can spread among the grass. If the grid (x, y) is firing at time t, the grid which is adjacent to this grid will fire at time t+1 which refers to the grid (x+1, y), (x-1, y), (x, y+1), (x, y-1). This process ends when no new grid get fire. If then all the grid which are consisting of grass is get fired, Fat brother and Maze will stand in the middle of the grid and playing a MORE special (hentai) game. (Maybe it’s the OOXX game which decrypted in the last problem, who knows.) ...

2018-03-23 · Lordash

POJ-3414 Pots

Pots (POJ - 3414) 题面 You 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 i to the drain; POUR(i,j) pour from pot i to pot j; after this operation either the pot j is full (and there may be some water left in the pot i), or the pot i is empty (and all its contents have been moved to the pot j). Write a program to find the shortest possible sequence of these operations that will yield exactly C liters of water in one of the pots. ...

2018-03-23 · Lordash

POJ-3087 Shuffle'm Up

Shuffle’m Up (POJ - 3087) 题面 A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of poker chips, S1 and S2, each stack containing C chips. Each stack may contain chips of several different colors. The actual shuffle operation is performed by interleaving a chip from S1 with a chip from S2 as shown below for C = 5: ...

2018-03-23 · Lordash

POJ-3126 Prime Path

Prime Path (POJ - 3126) 题面 The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-digit room numbers on their offices. — It is a matter of security to change such things every now and then, to keep the enemy in the dark. — But look, I have chosen my number 1033 for good reasons. I am the Prime minister, you know! — I know, so therefore your new number 8179 is also a prime. You will just have to paste four new digits over the four old ones on your office door. — No, it’s not that simple. Suppose that I change the first digit to an 8, then the number will read 8033 which is not a prime! — I see, being the prime minister you cannot stand having a non-prime number on your door even for a few seconds. — Correct! So I must invent a scheme for going from 1033 to 8179 by a path of prime numbers where only one digit is changed from one prime to the next prime. ...

2018-03-23 · Lordash

POJ-1426 Find The Multiple

Find The Multiple (POJ - 1426) 题面 Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there is a corresponding m containing no more than 100 decimal digits. 输入 The input file may contain multiple test cases. Each line contains a value of n (1 <= n <= 200). A line containing a zero terminates the input. ...

2018-03-23 · Lordash

POJ-3279 Fliptile

Fliptile (POJ - 3279) 题面 Farmer John knows that an intellectually satisfied cow is a happy cow who will give more milk. He has arranged a brainy activity for cows in which they manipulate an M × N grid (1 ≤ M ≤ 15; 1 ≤ N ≤ 15) of square tiles, each of which is colored black on one side and white on the other side. As one would guess, when a single white tile is flipped, it changes to black; when a single black tile is flipped, it changes to white. The cows are rewarded when they flip the tiles so that each tile has the white side face up. However, the cows have rather large hooves and when they try to flip a certain tile, they also flip all the adjacent tiles (tiles that share a full edge with the flipped tile). Since the flips are tiring, the cows want to minimize the number of flips they have to make. ...

2018-03-23 · Lordash

POJ-3278 Catch That Cow

Catch That Cow (POJ - 3278) 题面 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. ...

2018-03-23 · Lordash

POJ-2251 Dungeon Master

Dungeon Master (POJ - 2251) 题面 You 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 rock on all sides. Is an escape possible? If yes, how long will it take? ...

2018-03-23 · Lordash

POJ-1321 棋盘问题

棋盘问题 (POJ - 1321) 题面 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。 ...

2018-03-23 · Lordash