http://acm.timus.ru/problem.aspx?space=1&num=1641
水题 枚举就行
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<string> #include<vector> #include<map> #include<queue> #include<stack> #include<cmath> #define LL long long //#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const int INF=0x3f3f3f3f; const int N=105; int response[N]; bool used[N][N]; int main() { //freopen("data.txt","r",stdin); int n,m,k; while(cin>>n>>m>>k) { for(int i=1,j=1;i<=n;++i,j=(j==m)?1:j+1) { response[i]=j; cout<<j<<endl; } memset(used,false,sizeof(used)); for(int i=1;i<n;i+=2) { int j=(i==n)?1:i+1; if(!used[i][j]&&k) { cout<<i<<" "<<j<<endl; used[i][j]=used[j][i]=true; --k; } if(!k) break; } if(k&&!used[n][n-1]) { cout<<n-1<<" "<<n<<endl; used[n][n-1]=used[n-1][n]=true; --k; } for(int i=1;i<=n;++i) { for(int j=1;j<=n;++j) { if(response[i]!=response[j]&&!used[i][j]&&k) { cout<<i<<" "<<j<<endl; used[i][j]=used[j][i]=true; --k; } if(!k) break; } if(!k) break; } } return 0; }