Problem Statement | |||||||||||||
|
Percy has just received a new game called Penguin Tiles. The game is played on a rectangular grid. Except for one square, each square of the grid contains a tile with a part of an image of a penguin. The one remaining square is empty, and it is called the open square. The player is allowed to slide one of the tiles adjacent to the open square onto the open square. After several moves the tile game is supposed to form a picture with the bottom right corner containing the open square.
Percy's version of Penguin Tiles is a misprint. Instead of each tile containing a different part of a penguin all tiles contain an image of the same penguin. In other words each pair of tiles in Percy's Penguin Tiles is indistinguishable.
Percy has decided to play with the game anyway but instead of moving just one tile at a time he has decided to move several tiles at once. In one move, Percy can either move some c onsecutive vertical tiles one square vertically, or some consecutive horizontal tiles one square horizontally. Of course, one of the tiles has to be moved onto the open square. (In other words, instead of moving several tiles one at a time, Percy may move them all at once, if they all lie in the same row or in the same column.)
You are given a vector <string> tiles representing the game. The j-th character of the i-th element oftiles is 'P' if the square at row i, column j contains a tile, and it is '.' (a period) for the open square. Return the minimum number of moves to complete Percy's game. | ||||||||||||
Definition | |||||||||||||
|
| ||||||||||||
| |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
- |
tiles will contain between 2 and 50 elements, inclusive. | ||||||||||||
- |
Each element of tiles will contain between 2 and 50 characters, inclusive. | ||||||||||||
- |
Each element of tiles will contain the same number of characters. | ||||||||||||
- |
Each character of each element of tiles will be either 'P' or '.'. | ||||||||||||
- |
tiles will contain exactly 1 occurrence of the character '.'. | ||||||||||||
Examples | |||||||||||||
0) |
| ||||||||||||
|
| ||||||||||||
1) |
| ||||||||||||
|
| ||||||||||||
2) |
| ||||||||||||
|
| ||||||||||||
3) |
| ||||||||||||
|
| ||||||||||||
4) |
| ||||||||||||
|
|
#include <deque>
#include <vector>
#include <algorithm>
#include <functional>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <utility>
#include <stack>
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI 3.1415926535898
#define LL long long
using namespace std;
class PenguinTiles
{
public:
int minMoves(vector <string> tiles)
{
int size = tiles.size();
int x=0,y=0;
for(int i=0;i<size;i++)
for(int j=0;j<size;j++)
{
if( tiles[i][j] == '.')
{
x = i;
y = j;
}
}
size--;
if (( x == size )&&( y == size))
return 0;
else
{
if(( x!= size)&&( y != size))
return 2;
else
return 1;
}
}
};
500pt:
Problem Statement | |||||||||||||
Penguin Pals is a match making service that matches penguins to new friends, using the following procedure: 1.ch penguin is asked a single question: "Do you prefer the color blue, or the color red?" 2.All penguins are arranged so that they stand on a circle, equally spaced. 3.The organizers draw some straight lines, connecting some pairs of penguins. 4.Each penguin may only be connected to at most one other penguin. Two penguins cannot be connected if they prefer a different color. 5.Each penguin who is connected to some other penguin follows the line to find their match. The only problem with the above system was that it allowed penguins to collide if two lines crossed each other. Therefore, a new additional rule was adopted: no two lines may cross. Penguin Pals now has some penguins arranged on a circle (after step 2 of the above procedure). They need to know the maximum number of pairs of penguins they can create. You are given a string colors whose i-th character represents the prefered color of the i-th penguin (0-based index) in the circular arrangement. The i-th character is 'R' if the i-th penguin prefers red and 'B' if the i-th penguin prefers blue. Return the maximum number of matched pairs that can be formed. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
- | colors will contain between 1 and 50 characters, inclusive. | ||||||||||||
- | Each character of colors will be either 'R' or 'B'. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
| |||||||||||||
4) | |||||||||||||
| |||||||||||||
5) | |||||||||||||
| |||||||||||||
6) | |||||||||||||
| |||||||||||||
7) | |||||||||||||
|
#include <deque>
#include <vector>
#include <algorithm>
#include <functional>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <utility>
#include <stack>
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define PI 3.1415926535898
#define LL long long
using namespace std;
class PenguinPals
{
public:int findMaximumMatching(string colors)
{
string clrs = colors;
int length = 0;
int cnt = 0;
int tail = 0;;
int i=0;;
for(i=0;i<colors.size()-1;i++)
{
if( colors[i] == colors[i+1] )
{
i++;
cnt++;
}
else
{
clrs[length] = colors[i];
length++;
}
}
if( colors[i] != colors[i-1])
{
clrs[length] = colors[i];
length++;
}
tail = length-1;
for(i=0;i<length-1;i++)
{
if( i >= tail)
break;
else
{
if( clrs[i] == clrs[tail])
{
cnt++;
tail--;
}
}
}
return cnt;
}
};
1000pt:
Problem Statement | |||||||||||||
Paco collects penguins. His penguins like to play and run around on the ice where he lives. In order to keep his penguins safe he decided to construct a single fence enclosure to keep danger out. Paco's penguins have fallen asleep. Acting quickly Paco placed numPosts posts in a circular configuration on the ice. Each post is placedradius meters from location (0,0). The posts are equally spaced with the first post being placed at location (radius, 0). To construct the fencing, Paco will connect some pairs of fence posts using straight fences. No two s egments of the fence are allowed to cross. In the resulting fencing, each fence post will either be unused, or it will be connected to exactly two other fence posts. In order to minimize the damage his penguins cause to the ice, he would like to minimize the area enclosed by the fence. In order to keep all his penguins happy Paco would like to have all his penguins in the one single enclosure. Two penguins are in the same enclosure if it is possible to walk from one penguin to the other without crossing a fence. You are given two ints numPosts and radius. You are also given two int[]sx andy representing the (x,y) location of each of the sleeping penguins. Each penguin is small enough to be considered a point. Compute an return the smallest area of an enclosure that can contain all the penguins. If it is not possible to enclose all the penguins return -1. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
- | numPosts will be between 3 and 222, inclusive. | ||||||||||||
- | radius will be between 5 and 100,000, inclusive. | ||||||||||||
- | x will contain between 1 and 50 elements, inclusive. | ||||||||||||
- | y will contain the same number of elements as x. | ||||||||||||
- | Each element in x will be between -100,000 and 100,000, inclusive. | ||||||||||||
- | Each element in y will be between -100,000 and 100,000, inclusive. | ||||||||||||
- | No penguin will come within 10^-6 of any potential fencing. | ||||||||||||
- | No two penguins will occupy the same location. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
| |||||||||||||
4) | |||||||||||||
| |||||||||||||
5) | |||||||||||||
| |||||||||||||
6) | |||||||||||||
|