codeforces round #236 div.2 C
题目链接:http://codeforces.com/contest/402/problem/C
刚刚看了题目完全没有头绪,看了题解还是不理解为什么。但直接根据题解写代码A掉了。
最后想想,题解的思路是这样的:要得到满足条件的图,则应该让边尽可能的分布在每两个点之间。这样才能任选一部分点使得这部分构成的子图的边数的最大值尽可能小。
1 ///2014.3.18 2 ///codeforces round #236 div.2 3 ///C 4 5 #include <iostream> 6 #include <cstdio> 7 using namespace std; 8 9 int main() 10 { 11 // freopen("in","r",stdin); 12 // freopen("out","w",stdout); 13 14 int t; 15 cin>>t; 16 while( t-- ){ 17 int n,p; 18 cin>>n>>p; 19 int NUM = 2*n+p; 20 int i=1; 21 int j=2; 22 for(int num=0 ; num<NUM ; num++){ 23 cout<<i<<' '<<j<<endl; 24 j++; 25 if(j>n){ 26 i++; 27 j = i+1; 28 } 29 } 30 } 31 return 0; 32 }