好的,数据加强了,wa了
1 /*
2 题意:1到n分成m组,每组和相等
3 贪心:先判断明显不符合的情况,否则肯定有解(可能数据弱?)。贪心的思路是按照当前的最大值来取
4 如果最大值大于所需要的数字,那么去找没有vis的数字
5 */
6 /************************************************
7 * Author :Running_Time
8 * Created Time :2015-8-6 13:24:55
9 * File Name :C.cpp
10 ************************************************/
11
12 #include <cstdio>
13 #include <algorithm>
14 #include <iostream>
15 #include <sstream>
16 #include <cstring>
17 #include <cmath>
18 #include <string>
19 #include <vector>
20 #include <queue>
21 #include <deque>
22 #include <stack>
23 #include <list>
24 #include <map>
25 #include <set>
26 #include <bitset>
27 #include <cstdlib>
28 #include <ctime>
29 using namespace std;
30
31 #define lson l, mid, rt << 1
32 #define rson mid + 1, r, rt << 1 | 1
33 typedef long long ll;
34 const int MAXN = 1e5 + 10;
35 const int INF = 0x3f3f3f3f;
36 const int MOD = 1e9 + 7;
37 bool vis[MAXN];
38 vector<int> ans[11];
39 ll n, m;
40
41 int main(void) { //HDOJ 5355 Cake
42 int T; scanf ("%d", &T);
43 while (T--) {
44 memset (vis, false, sizeof (vis));
45 scanf ("%I64d%I64d", &n, &m);
46 ll tot = n * (n + 1) / 2;
47 if (tot % m != 0 || tot / m < n) {
48 puts ("NO"); continue;
49 }
50
51 ll sum = tot / m; ll mx = n;
52 for (int i=1; i<=m; ++i) {
53 ans[i].clear (); ll tmp = sum;
54 while (tmp >= mx) {
55 tmp -= mx; ans[i].push_back (mx); vis[mx] = true;
56 while (mx - 1 >= 1 && vis[mx]) --mx;
57 }
58 ll t = mx;
59 while (tmp != 0) {
60 while ((t - 1 >= 1 && vis[t]) || tmp < t) t--;
61 tmp -= t; ans[i].push_back (t); vis[t] = true;
62 t = tmp;
63 }
64 }
65
66 puts ("YES");
67 for (int i=1; i<=m; ++i) {
68 printf ("%d", (int) ans[i].size ());
69 for (int j=0; j<ans[i].size (); ++j) {
70 printf (" %d", ans[i][j]);
71 }
72 puts ("");
73 }
74 }
75
76 return 0;
77 }