A 小美的外卖订单编号
直接取模,如果为0就是m,反之为x%m
点击折叠/展开
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
void solve()
{
int q;
cin >> q;
while(q--)
{
LL m,x;
cin >> m >> x;
if(x%m == 0) cout << m << '\n';
else cout << x%m << '\n';
}
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t = 1;
while(t--) solve();
return 0;
}
B 小美的数组操作
数据极小,直接暴力模拟即可
点击折叠/展开
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e2 + 10;
int a[N],n,k;
void solve()
{
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= k; i++)
{
int u,v;
cin >> u >> v;
a[u]++,a[v]--;
}
for(int i = 2; i <= n; i++)
{
if(a[i] < a[i - 1])
{
cout << "No" << '\n';
return;
}
}
cout << "Yes" << '\n';
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t = 1;
cin >> t;
while(t--) solve();
return 0;
}
C 小美的01串翻转
也是暴力枚举所有子串,因为要每个相邻的数字都不一样,所以修改后的必为0101...或者1010...
对于每个枚举的子串,模拟这两种修改情况,取最小的修改次数并累加即可
点击折叠/展开
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e3 + 10;
char s[N];
void solve()
{
cin >> s + 1;
int n = strlen(s + 1);
LL res = 0;
for(int i = 1; i <= n; i++)
{
LL temp1 = 0,temp2 = 0;
for(int j = i; j <= n; j++)
{
if(j%2)
{
if(s[j] == '0') temp1++;
else temp2++;
}
else
{
if(s[j] == '0') temp2++;
else temp1++;
}
res += min(temp1,temp2);
}
}
cout << res << '\n';
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t = 1;
while(t--) solve();
return 0;
}
D 小美的元素删除
简单线性dp,赛时读错题卡了挺久
为了方便后序操作我们先排序
状态设计为代表到第
个数字,取
个数字的方法数
对于第个数字我们枚举小于他的数字,假设为
那么只要i%j == 0就是合法的,就可以从
转移而来
时间复杂度看似是的,但是因为题目条件说不可能出现相同的数字,所以最大的合法情况也就是
形如 1 2 4 8 ... 这种的,最多可取的数字数量也很小,所以近似
详情见代码
点击折叠/展开
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e3 + 10,MOD = 1e9 + 7;
LL n,m,a[N],f[N][N];
void solve()
{
cin >> n >> m;
m = n - m;
for(int i = 1; i <= n; i++) cin >> a[i],f[i][1] = 1;
sort(a + 1,a + n + 1);
//f[i][k] 代表到第i个数 选k个数的方法数
LL res = 0;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j < i; j++)
{
if(a[i]%a[j]) continue;
for(int k = 2; k <= m; k++)
{
f[i][k] += f[j][k - 1];
f[i][k] %= MOD;
}
}
res = (res + f[i][m])%MOD;
}
cout << res << '\n';
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t = 1;
while(t--) solve();
return 0;
}