Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
AC Code// soulution i'm korean i'm not english well. loop { 1. find the max(0~n); 2. you should trans max to n 3. find the max(0~n-1) 4. you should trans max to n-1; warning output Scenario #1: 3 <-------------blank Scenario #2: 2 <-----------blank } #include <iostream> #include <vector> #include <algorithm> using namespace std; bool ok(); void sort(); void print(); int max(); int cnt,ans=0,idx=0,n,x=1; int* arr; int main() { int _n; int k=10; vector<int> v1; cin>>cnt; while(cnt) { cnt--; cin>>n; _n=n; arr= new int [ n+1 ]; for(int i=1;i<n+1;i++) { cin>>arr[i]; } while(true) { if( ok() ){break;} sort(); } v1.push_back(ans); ans=0; idx=0; delete[] arr; } vector<int>::iterator it = v1.begin(); for(it;it!=v1.end();it++) { cout<<"Scenario #"<<x<<":"<<endl; cout<<*it<<endl; cout<<endl; x++; } return 0; } bool ok() { for(int i=1;i<n;i++) { if(arr[i]<=arr[i+1]) { continue; } else { return false; } } return true; } void sort() { int M = max(); // cout<<"max = "<<M<<endl; int temp; for(int i=M;i<=n-idx;i++) { if(i>=n-idx){break;} temp=arr[i]; arr[i]=arr[i+1]; arr[i+1]=temp; ans++; } idx++; } int max() { int m=-1000009; int add=0; for(int i=1;i<=n-idx;i++) { // cout<<"Seqeunce = "<< arr[i]<<endl; if(arr[i]>=m) { m=arr[i]; add=i; } } return add; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator