刷水凑数2333

这题目貌似几天前applepi大爷讲过。。。直接乱搞即可,可惜当时没想出来

每次找到两个点,如果没有它们没有边就把它们都删掉,最后必定留下一个至少n / 3的团

 

 1 /**************************************************************
 2     Problem: 2530
 3     User: rausen
 4     Language: C++
 5     Result: Accepted
 6     Time:3048 ms
 7     Memory:9628 kb
 8 ****************************************************************/
 9  
10 #include <cstdio>
11  
12 using namespace std;
13 const int N = 3005;
14  
15 int n, m;
16 bool mp[N][N], d[N];
17  
18 inline int read() {
19     int x = 0;
20     char ch = getchar();
21     while (ch < '0' || '9' < ch)
22         ch = getchar();
23     while ('0' <= ch && ch <= '9') {
24         x = x * 10 + ch - '0';
25         ch = getchar();
26     }
27     return x;
28 }
29  
30 int main() {
31   int i, j, k, x, y;
32   n = read(), m = read();
33   for (i = 1; i <= m; ++i) {
34     x = read(), y = read();
35     mp[x][y] = mp[y][x] = 1;
36   }
37   for (i = 1; i <= n; ++i) if (!d[i]) {
38       for (j = 1; j <= n; ++j) if (i != j && !mp[i][j] && !d[j]) {
39       d[i] = d[j] = 1;
40       break;
41       }
42     }
43   for (i = 1, k = 0; i <= n, k < n / 3; ++i)
44     if (!d[i]) {
45       printf("%d", i);
46       if (++k == n / 3) putchar('\n');
47       else putchar(' ');
48     }
49   return 0;
50 }
View Code

(p.s.  妈呀。。。这坑爹的emacs强制缩进啊。。。)

posted on 2015-01-05 23:13  Xs酱~  阅读(210)  评论(0编辑  收藏  举报