[CODE]#include <iostream>
#include <vector>
using namespace std;
void process(int);
void output(const vector<pair<int,int> >&);
int main()
{
int n;
while(1)
{
cin>>n;
process(n);
}
system("pause");
return 0;
}
void process(int n)
{
vector<pair<int,int> > oneCycle;
int X, Y, cycle;
bool even = false;
if(n%2 == 0)
{
cycle = n - 1;
even = true;
}
else
cycle = n;
for(int i=0; i<cycle; i++)
{
X = i;
Y = (i+1) % cycle;
while(X != Y)
{
oneCycle.push_back(pair<int,int>(X+1, Y+1));
if(--X < 0)
X = cycle-1;
Y = (Y+1) % cycle;
}
if(even)
oneCycle.push_back(pair<int,int>(X+1, n));
output(oneCycle);
oneCycle.clear();
}
}
void output(const vector<pair<int,int> > &oneCycle)
{
for(int i=0; i<oneCycle.size(); i++)
cout<<oneCycle[i].first<<" vs "<<oneCycle[i].second<<" ";
cout<<endl;
}
[/CODE]
感觉应该可以,没有仔细证明