Code First Fractional group: 15th matrix Flip (image rollover)

Source: Internet
Author: User

Code First Fractional group: 15th matrix Flip (image rollover)

First of all, pure simulation, from the outside to the inner lap of the turn, but this method is too slow.
For example, first flip along the diagonal and then flip it one time along the horizontal midline.

Source

#include <iostream>#include<vector>using namespacestd;//Reference type parametervoidSwapint&n,int&L) {    inttemp=N; N=m; M=temp;}//pointer type parametervoidSWAP1 (int*a,int*b) {    inttemp; Temp= *A; *a = *b; *b =temp; }//swap function with addition and subtractionvoidSWAP2 (int&a,int&b) {a= A +b; b= A-b; A= A-b;}//swap function using an XOR operationvoidSWAP3 (int&a,int&b) {a= a^b; b= a^b; A= a^b;}voidRotateinta[][3],intN) {    //int i,j;     for(inti =0; I < n; i++)    {         for(intj =0; J < N-i; J + +) {Swap (A[i][j],a[n-j-1][n-i-1]); }    }     for(inti =0; I < n/2; i++)    {         for(intj =0; J < N; J + +) {Swap (A[i][j],a[n-i-1][j]); }    }}voidRotate2 (vector<vector<int>>&matrix) {    Const intn =matrix.size ();  for(inti =0; I < n; i++)    {//invert diagonally along the diagonal         for(intj =0; J < N-i; J + +) {swap (matrix[i][j], matrix[n-1-J][n-1-i]); }    }     for(inti =0; I < n/2; i++)    {//reverse along the horizontal midline         for(intj =0; J < N; J + +) {swap (matrix[i][j], matrix[n-1-i]        [j]); }    }}intMain () {inta[3][3]={{1,2,3},{4,5,6},{7,8,9}}; Rotate (A,3);  for(inti =0; I <3; i++)    {         for(intj =0; j<3; J + +) {cout<<a[i][j]<<Endl; }} vector<vector<int>> matrix={{1,2,3},{4,5,6},{7,8,9}};    Rotate2 (matrix);  for(inti =0; I <3; i++)    {         for(intj =0; j<3; J + +) {cout<<matrix[i][j]<<Endl; }    }    /*vector<int> row1 = {n/a};    Vector<int> row2 = {4,5,6};    Vector<int> row3 = {7,8,9};    Vector<vector<int>> Matrix;    Matrix.push_back (ROW1);    Matrix.push_back (ROW2);    Matrix.push_back (ROW3);    Rotate2 (matrix);    int n = matrix.size ();        for (int i = 0;i < n;i++) {for (int j = 0;j < n;j++) {cout<<matrix[i][j]<<endl; }    }*/    return 0;}

Code First Fractional group: 15th matrix Flip (image rollover)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.