第四题: #include<iostream> #include<vector> #include<algorithm> #include<ctime> using namespace std; int main() {     clock_t startTime, endTime;     startTime = clock();     int N, M, k;     cin >> N >> M >> k;     if (N <= 0 || M <= 0)     {         return 0;     }     vector<int> arr;     int ss = (int)sqrt(k);     //cout << ss;     int nIndex = N;     int mIndex = M;     if (k > N*M || N <= 0 || M <= 0)     {         return 0;     }     if (N == M)     {         int judge = k - 1;         while (judge)         {             if (nIndex == mIndex && nIndex >= 1 && mIndex >= 1)             {                 nIndex--;                 mIndex = M;                 --judge;             }             else if (nIndex < mIndex && nIndex >= 1 && mIndex >= 1)             {                 if (judge>1)                 {                     judge = judge - 2;                     mIndex--;                 }                 else if (judge == 1)                 {                     --judge;                 }             }         }         cout << nIndex*mIndex <<endl;     }     if (N < M)     {         int judge = k - 1;         while (judge)         {             if (nIndex < mIndex && mIndex > N && mIndex >= 1 && nIndex >= 1)             {                 --judge;                 --mIndex;             }             else if (nIndex < mIndex && mIndex <= N && mIndex >= 1 && nIndex >= 1)             {                 if (judge > 1)                 {                     judge = judge - 2;                     --mIndex;                 }                 else if (judge == 1)                 {                     --judge;                 }             }             else if (nIndex == mIndex)             {                 --nIndex;                 mIndex = M;                 --judge;             }         }         cout << nIndex*mIndex <<endl;     }     if (N>M)     {         int judge = k - 1;         while (judge)         {             if (nIndex == mIndex && mIndex >= 1 && nIndex >= 1)             {                 --mIndex;                 nIndex = N;                 --judge;             }             else if (mIndex < nIndex && nIndex > M && mIndex >= 1 && nIndex >= 1)             {                 --judge;                 --nIndex;             }             else if (mIndex < nIndex && nIndex <= M && mIndex >= 1 && nIndex >= 1)             {                 if (judge > 1)                 {                     judge = judge - 2;                     --nIndex;                 }                 else if (judge == 1)                 {                     --judge;                 }             }         }         cout << nIndex*mIndex<<endl;     }     endTime = clock();     cout << "运行时间:" << endTime - startTime << "ms"<< endl;     system("pause");     return 0; }
点赞 评论

相关推荐

Noob1024:一笔传三代,人走笔还在
点赞 评论 收藏
分享
牛客网
牛客企业服务