构造图 Codeforces Round #236 (Div. 2) C. Searching for Graph

 

题目地址

 1 /*  2  题意:要你构造一个有2n+p条边的图,使得,每一个含k个结点子图中,最多有2*k+p条边  3  水得可以啊,每个点向另外的点连通,只要不和自己连,不重边就可以,正好2*n+p就结束:)  4 */  5 #include <cstdio>  6 #include <iostream>  7 #include <algorithm>  8 #include <cstring>  9 #include <string> 10 #include <map> 11 #include <cmath> 12 using namespace std; 13 14 int main(void) //Codeforces Round #236 (Div. 2) C. Searching for Graph 15 { 16 //freopen ("B.in", "r", stdin); 17 18 int t; 19 scanf ("%d", &t); 20 while (t--) 21  { 22 int n, p; 23 scanf ("%d%d", &n, &p); 24 25 int cnt = 0, i = 1, j = 2; 26 while (cnt < 2 * n + p) 27  { 28 printf ("%d %d\n", i, j); 29 j++; cnt++; 30 if (j == n + 1) j = ++i + 1; 31  } 32  } 33 34 return 0; 35 }

 

你可能感兴趣的:(codeforces)