Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int global_max=-1,global_index;
- int hill[10]= {1,9,0,3,5,2,9,7,100,1};
- for(int i=0; i<100; i++) //global search for 100 times
- {
- int local_max=-1,local_index=-1;
- int x= rand()%10; //random index selected 10 times
- for(int j=x; j<10; j++) //local max finding
- {
- if(hill[j]>=local_max)
- {
- local_max=hill[j];
- local_index=j;
- }
- else break;
- }
- if( global_max<=local_max)
- {
- global_max=local_max;
- global_index=local_index;
- }
- }
- cout<<"global maximum : "<<global_max<<endl;
- cout<<"index of global maximum : "<<global_index<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement