人菜就要多努力,今天实验室去教室里边去宣讲(虽然我只是一个打杂的),我预感这届新生会有强的选手,带带学长们吧!
今天一天的课,并且上午极困(并且上午上完课感觉那个困劲小了一半有没有,我果然还是适合自己自学),没有什么时间去想这道题目,感觉自己静不下心来呢,还是稳住吧,感觉要想拿牌子还是不能幻想着队友的爆发,我还是先爆发吧。
思路:我们首先有 n n n个糖果,题目中要求我们每次对决都不能输,所以我们在对决中的糖果数量已经是一定的了,就是 x , x + 1 , x + 2 … … x,x + 1, x + 2…… x,x+1,x+2…… 知道了这些,我们就可以在每个位置上来选出来我们合适的人选,所以我们只需要选出小于 x , x + 1 , x + 2 , x + 3..... x, x + 1, x + 2, x + 3..... x,x+1,x+2,x+3..... 就可以了,然后进行乘法原理就完成了。我们这点感觉还挺考验代码能力的,不然会写的一团糟。
#include <iostream>
#include <cstring>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <map>
using namespace std;
const int N = 1e5 + 10;
int a[N], dp[N];
int main()
{
int n, p; scanf ("%d%d", &n, &p);
int Max = 0;
for (int i = 1; i <= n; i ++)
{
scanf ("%d", a + i);
Max = max (a[i], Max);
}
sort (a + 1, a + n + 1);
vector <int> arr;
arr.clear();
for (int i = 1; i <= Max; i ++)
{
long long ans = 1;
int pos = 1;
for (int j = 1; j <= n; j ++)
{
while (pos <= n && i + j - 1 >= a[pos]) pos ++;
ans *= (pos - j), ans %= p;
//cout << i << ' ' << pos << ' ' << ans << endl;
}
if (ans) arr.push_back (i);
}
printf ("%d\n", arr.size());
for (int i = 0; i < arr.size(); i ++) printf ("%d ", arr[i]);
return 0;
}