我们N个真是太厉害了
思路:
我们先给数组排序,如果最小的元素不为1,那么肯定是吹牛的,我们拿一个变量记录前缀和,如果当前元素大于它前面所有元素的和+1,那么sum+1是不能到达的值。
代码:
cpp
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<algorithm>
#define int long long
#define pb push_back
#define TEST int T; cin >> T; while (T--)
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define lowbit(x) x&(-x)
#define pll pair<int,int>
const int N = 1e6 + 30;
const int M = 1e3 + 10;
const int inf = 512785182741247112;
const int mod = 1e9 + 7;
using namespace std;
void solve()
{
int n;
cin >> n;
vector<int>a(n + 1);
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a.begin() + 1, a.end());
if (a[1] != 1) {
cout << 1 << '\n';
return;
}
int sum = 1;
for (int i = 2; i <= n; i++) {
if (a[i] > sum + 1) {
cout << sum + 1 << '\n';
return;
}
sum += a[i];
if (sum >= n) {
cout << "Cool!\n";
return;
}
}
cout << "Cool!\n";
}
signed main() {
ios; TEST
solve();
return 0;
}
折返跑
思路:
其实是一个组合数学的题目,我们只要规定每个折返至少挪一米,那么剩下的就可以随便安排,就是一个C(可用的距离,折返次数)就是答案,我们可以预处理一下1到1e6的阶乘。
代码:
cpp
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<algorithm>
#define int long long
#define pb push_back
#define TEST int T; cin >> T; while (T--)
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define lowbit(x) x&(-x)
#define pll pair<int,int>
const int N = 1e6 + 30;
const int M = 1e3 + 10;
const int inf = 512785182741247112;
const int mod = 1e9 + 7;
using namespace std;
int f[N], a[N], sum[N];
int C(int n, int m) {
if (n < m) return 0;
if (m == 0) return 1;
return f[n] * qpow(f[n - m] * f[m], mod - 2, mod) % mod;
}
void solve()
{
int n, m;
cin >> n >> m;
cout << C(n - 2, m - 1) << '\n';
}
signed main() {
f[0] = 1;
f[1] = 1;
for (int i = 2; i <= 1e6; i++) f[i] = f[i - 1] * i % mod;
ios; TEST
solve();
return 0;
}
好好好数
思路:
直接将n变成k进制数,发现答案就是最大的因为,当k为1时,直接输出1。
代码:
cpp
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<algorithm>
#define int long long
#define pb push_back
#define TEST int T; cin >> T; while (T--)
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define lowbit(x) x&(-x)
#define pll pair<int,int>
const int N = 3e5 + 30;
const int M = 1e3 + 10;
const int inf = 512785182741247112;
const int mod = 998244353;
using namespace std;
vector<int>f;
int n, k;
void solve()
{
cin >> n >> k;
if (k == 1) {
cout << 1 << '\n';
return;
}
int ans = 1;
while (n) {
ans = max(ans, n % k);
n /= k;
}
cout << ans << '\n';
}
signed main() {
ios; TEST
solve();
return 0;
}