Cutting Paper Squares

Mary has an nXm piece of paper that she wants to cut into  pieces according to the following rules:

  • She can only cut one piece of paper at a time, meaning she cannot fold the paper or layer already cut pieces on top of one another.
  • Each cut is a straight line from one side of the paper to the other side of the paper.
Given n and m, find and print the minimum number of cuts Mary must make to cut the paper into n.m squares that are 1X1 unit in size.

Example:

Input:  n = 3, m = 1
Output: 2

Approach

C++

#include <bits/stdc++.h>
using namespace std;

long long int solve(int nint m)
{
    long long int row = n;
    long long int column = m;
    long long int count = (((row - 1) * column) + (column - 1));
    return count;
}

int main()
{

    int n = 3;
    int m = 1;

    cout << solve(nm<< "\n";

    return 0;
}


No comments:

Post a Comment