Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <cmath>
- #include <ctype.h>
- #include <cassert>
- #include <ctime>
- #include <climits>
- #include <limits>
- #include <algorithm>
- #include <list>
- #include <set>
- #include <map>
- #include <string>
- #include <stdio.h>
- #include <queue>
- #include <stack>
- #include <iomanip>
- #include <bitset>
- #include <utility>
- #include <deque>
- #include <stdlib.h>
- #include <functional>
- #include <float.h>
- //#define C11
- //#include <windows.h>
- #ifdef C11
- #include <unordered_map>
- #include <unordered_set>
- #include <tuple>
- #endif // C11
- #define F first
- #define S second
- #define mp make_pair
- #define pb push_back
- #define fabs(x) ((x>0) ? (x) : -1*(x))
- #define show(a,n) cout <<#a<<": "; for (int iii=0;iii<n;iii++) cout <<a[iii]<<" "; cout<<"\n";
- #define show2(a,n,m) cout <<#a<<":\n"; for (int iii=0;iii<n;iii++) { for(int jjj=0;jjj<m;jjj++) cout <<a[iii][jjj]<<" "; cout <<"\n";}
- #define name(x) cout <<#x<<" \n";
- #define print(x) cout <<#x"="<<x<<"\n";
- #define letters char alp[30]={qwertyuiopasdfghjklzxcvbnm},sogl[30]={qwrtpsdfghjklzxcvbnm},gl[30]={eyuioa};
- #define SetBit(value,place) (value|(1<<place))
- #define ClearBit(value,place) (value&(~(1<<place)))
- #define InverseBit(value,place) (value^(1<<place))
- #define StartClock time_t inittime=clock();
- #define GetClock fprintf(stderr,"Time: %f\n",1.0*(clock()-inittime)/CLOCKS_PER_SEC);
- typedef std::pair<int,int> pii;
- typedef std::vector <int>::iterator iti;
- typedef std::multiset <int>::iterator itm;
- typedef std::set <int>::iterator itset;
- typedef std::string::iterator its;
- typedef std::pair<long long,long long> pll;
- typedef std::vector <std::vector <int> > graph;
- typedef unsigned long long ull;
- typedef unsigned int ui;
- using namespace std;
- const int INF=INT_MAX;
- const long long LINF=LLONG_MAX;
- const unsigned long long ULINF=ULLONG_MAX;
- const double DINF=DBL_MAX;
- const double EPS=0.000001;
- const int mod=1000000007;
- #define ONLINE_JUDGE
- #ifndef ONLINE_JUDGE
- #include <fstream>
- ifstream cin("input.txt");
- ofstream cout("output.txt");
- #else
- #include <iostream>
- #endif // LOCAL
- int main()
- {
- ios_base::sync_with_stdio(0); //cin.tie(0);
- int n;
- cout <<"Enter n for n x n matrix: ";
- cin >>n;
- if (n > 10)
- {
- cout <<"n is too big, must be <=10\n";
- return 0;
- }
- else if (n <= 0)
- {
- cout <<"n is less than 1\n";
- return 0;
- }
- double** v = new double*[n];
- for (int i=0;i<n;i++)
- v[i] = new double[n];
- cout <<"Enter upper triangle of the matrix:\n";
- for (int i=0;i<n;i++)
- for (int j=0;j<i+1;j++)
- {
- cin >>v[i][j];
- v[j][i]=v[i][j];
- }
- cout <<"So given matrix is:\n";
- for (int i=0;i<n;i++)
- {
- for (int j=0;j<n;j++)
- {
- cout.width(11);
- cout <<fixed<<setprecision(6)<<v[i][j];
- }
- cout <<"\n";
- }
- for (int i=0;i<n;i++)
- {
- double prev_max = (i==0 ? DINF : v[i-1][i-1]);
- pii maxi=mp(n-1,n-1);
- for (int j=0;j<n;j++)
- {
- for (int k=0;k<n;k++)
- {
- if (v[j][k] > (v[maxi.F][maxi.S] + EPS) && !(v[j][k] > prev_max + EPS) && !(j == k && k < i))
- {
- maxi=mp(j,k);
- }
- }
- }
- swap(v[i][i],v[maxi.F][maxi.S]);
- }
- cout <<"Matrix after transformation:\n";
- for (int i=0;i<n;i++)
- {
- for (int j=0;j<n;j++)
- {
- cout.width(11);
- cout <<fixed<<setprecision(6)<<v[i][j];
- }
- cout <<"\n";
- }
- int index = -1;
- for (int i=0;i<n;i++)
- {
- bool excpt = false;
- for (int j=0;j<n;j++)
- {
- if (v[i][j] >= EPS)
- {
- excpt = true;
- break;
- }
- }
- if (!excpt)
- {
- index = i;
- break;
- }
- }
- if (index == -1)
- cout <<"There is no row with only negative elements!\n";
- else
- cout <<"The first row of only negative elements is "<<index<<"\n";
- for (int i=0;i<n;i++)
- delete [] v[i];
- delete [] v;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement