- #include<iostream>
- using namespace std;
- char Big_array[1000][1000];
- char small_array[4][1000][1000];
- int checkin(int N, int n, int slice){
- int counter = 0;
- bool flag;
- for (int i = 0; i < N-n+1; i++){
- for (int j = 0; j < N-n+1; j++){
- flag = true;
- for (int x = 0; x < n; x++){
- for (int y = 0; y < n; y++){
- if (Big_array[x + j][y + i] != small_array[slice][x][y]){
- flag = false; break;
- }
- }
- if (!flag){
- break;
- }
- }
- if (flag){//the small square is found in the big one
- ++counter;
- }
- }
- }
- return counter;
- }
- int main()
- {
- int N_big, n_small;
- for (;;){
- cin >> N_big >> n_small;
- if (N_big == 0 && n_small == 0) break;
- int arr[4] = { 0 };
- for (int i = 0; i < N_big; i++){
- for (int j = 0; j < N_big; j++){
- cin >> Big_array[i][j];
- }
- }
- for (int i = 0; i < n_small; i++){
- for (int j = 0; j < n_small; j++){
- cin >> small_array[0][i][j];
- }
- }
- for (int i = 0; i < n_small; i++){
- for (int j = 0; j < n_small; j++){
- /****rotated 90 degrees
- (0,0) in slice#1 <-- (1,0) in slice#0
- (0,1) in slice#1 <-- (0,0) in slice#0
- (1,0) in slice#1 <-- (1,1) in slice#0
- (1,1) in slice#1 <-- (0,1) in slice#0
- */
- small_array[1][i][j] = small_array[0][n_small - 1 - j][i];
- /****rotated 180 degrees
- (0,0) in slice#2 <-- (1,1) in slice#0
- (0,1) in slice#2 <-- (1,0) in slice#0
- (1,0) in slice#2 <-- (0,1) in slice#0
- (1,1) in slice#2 <-- (0,0) in slice#0
- */
- small_array[2][i][j] = small_array[0][n_small - 1 - i][n_small - 1 - j];
- /****rotated 270 degrees
(0,0) in slice#3 <-- (0,1) in slice#0 - (0,1) in slice#3 <-- (1,1) in slice#0
- (1,0) in slice#3 <-- (0,0) in slice#0
- (1,1) in slice#3 <-- (1,0) in slice#0
- */
- small_array[3][i][j] = small_array[0][j][n_small - 1 - i];
- }
- }
- for (int i = 0; i < 4; i++){
- arr[i] = checkin(N_big, n_small, i);
- }
- cout <<arr[0]<<" "<<arr[1]<<" "<<arr[2]<<" "<<arr[3]<< endl;
- }
- return 0;
- }
UVA Online Judge Solutions in C++
7/28/2015
10855 - Rotated square
7/11/2015
11034 - Ferry Loading IV
Note:
1) The cars are loaded in the order of their arrival;
2) The ferry is initially on the left bank;
2) The ferry is initially on the left bank;
*3) If you get the error "deque iterator not dereferenceable" , make sure that you are not calling pop()/front() on empty queue.
Here's the code:
- #include<iostream>
- #include<queue>
- #include<string>
- using namespace std;
- int main()
- {
- int laps , l, m, c, car, load;
- string bank;
- bool rightBank;
- cin >> c;
- for (int i = 0; i < c; i++){
- cin >> l >> m;
- queue<int>Left, Right;
- load = 0;
- rightBank = 0;
- for (int j = 0; j < m; j++){
- cin >> car >> bank;
- if (bank == "left")
- Left.push(car);
- else
- Right.push(car);
- }
- laps = 0; l *= 100;
- while (!Left.empty() || !Right.empty()){
- load = 0;
- if (rightBank){
- while (!Right.empty() && load + Right.front() <= l)
- {
- load += Right.front(); Right.pop();
- }
- }
- else{
- while (!Left.empty() && load + Left.front() <= l)
- {
- load += Left.front(); Left.pop();
- }
- }
- ++laps;
- rightBank = 1 - rightBank;
- }
- cout << laps << endl;
- }
- return 0;
- }
Sample input:
9
1 4
100 right
100 right
100 right
100 right
1 3
20 left
81 left
99 left
1 1
100 right
15 4
380 right
720 left
1340 right
1040 left
Sample output:
6
5
2
4
8/11/2013
846 - Steps - UVA
- #include<iostream>
- using namespace std;
- int main ()
- {
- int x , y;
- int testCases;
- int min_steps = 0;
- cin>>testCases;
- for(int i=0; i<testCases ; i++)
- {
- cin>>x>>y;
- int difference = y - x;
- min_steps = 0;
- if(difference != 0)
- {
- int sumOfSteps = 0;
- int z = 2; //divided by 2, it represents the size if the next step
- while(difference > sumOfSteps)
- {
- sumOfSteps += (z / 2); //next step
- min_steps++;
- z++;
- }
- }
- cout<<min_steps<<endl;
- }
- return 0;
- }
You can find more of my solutions on Here
Subscribe to:
Posts (Atom)