Created
January 3, 2015 15:12
-
-
Save ik11235/756eea0a881cfe601a7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<vector> | |
#include<algorithm> | |
using namespace std; | |
template < class BidirectionalIterator > | |
bool next_combination ( BidirectionalIterator first1 , | |
BidirectionalIterator last1 , | |
BidirectionalIterator first2 , | |
BidirectionalIterator last2 ) | |
{ | |
if (( first1 == last1 ) || ( first2 == last2 )) { | |
return false ; | |
} | |
BidirectionalIterator m1 = last1 ; | |
BidirectionalIterator m2 = last2 ; --m2; | |
while (--m1 != first1 && !(* m1 < *m2 )){ | |
} | |
bool result = (m1 == first1 ) && !(* first1 < *m2 ); | |
if (! result ) { | |
while ( first2 != m2 && !(* m1 < * first2 )) { | |
++ first2 ; | |
} | |
first1 = m1; | |
std :: iter_swap (first1 , first2 ); | |
++ first1 ; | |
++ first2 ; | |
} | |
if (( first1 != last1 ) && ( first2 != last2 )) { | |
m1 = last1 ; m2 = first2 ; | |
while (( m1 != first1 ) && (m2 != last2 )) { | |
std :: iter_swap (--m1 , m2 ); | |
++ m2; | |
} | |
std :: reverse (first1 , m1 ); | |
std :: reverse (first1 , last1 ); | |
std :: reverse (m2 , last2 ); | |
std :: reverse (first2 , last2 ); | |
} | |
return ! result ; | |
} | |
template < class BidirectionalIterator > | |
bool next_combination ( BidirectionalIterator first , | |
BidirectionalIterator middle , | |
BidirectionalIterator last ) | |
{ | |
return next_combination (first , middle , middle , last ); | |
} | |
int main() | |
{ | |
int n,k; | |
cin>>n>>k; | |
vector<int> data; | |
int ma[n],mb[n]; | |
for(int i=0; i<n; i++){ | |
cin>>ma[i]>>mb[i]; | |
data.push_back(i); | |
} | |
int cnt=0; | |
int mindiff=99999999; | |
do{ | |
int tmp=0; | |
for(int i=0;i<k;i++) | |
for(int j=i+1;j<k;j++) | |
{ | |
tmp=max(tmp,max(abs(ma[data[i]]-ma[data[j]]),abs(mb[data[i]]-mb[data[j]]))); | |
} | |
if(mindiff>tmp) | |
{ | |
mindiff=tmp; | |
cnt=1; | |
} | |
else if(mindiff==tmp) | |
cnt++; | |
}while(next_combination(data.begin(), data.begin()+k, data.end())); | |
cout<<mindiff<<endl<<cnt<<endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment