小红的整数操作
我们直接使用map进行维护,每次对元素进行取余操作,最后遍历记录最大值
// #pragma GCC optimize(3,"Ofast","inline")
// #pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define point(n) fixed << setprecision(n)
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0), cout.tie(0);
#define debug(a) cout << "=======" << a << "========" << endl;
#define endl '\n'
#define inf 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
ll pow(ll a, ll b, ll mod)
{
ll res = 1;
while (b > 0)
{
a = a % mod;
if (b & 1)
res = res * a % mod;
b = b >> 1;
a = a * a % mod;
}
return res;
}
ll pow(ll a, ll b)
{
ll res = 1;
while (b > 0)
{
if (b & 1)
res = res * a;
b = b >> 1;
a = a * a;
}
return res;
}
ll ceil(ll a, ll b)
{
if (a % b == 0)
return a / b;
else
return a / b + 1;
}
typedef pair<int, int> PII;
const int N = 1e6 + 10, mod = 1e9 + 7;
int n, m, k;
int f[N];
void solve()
{
cin >> n >> m;
map<int, int> s;
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
s[x % m]++;
}
int cnt = 0;
for(auto [x,y]:s)
{
cnt = max(cnt, y);
}
cout << cnt << endl;
}
int main()
{
IOS;
int _;
_ = 1;
while (_--)
solve();
return 0;
}
小红的01串
有点小思维,最后状态必然是‘0’或者‘1’的个数为0,如果有‘1’或者‘0’的个数为偶数,我们总可以使它全部变成另一个字符。故我们只需判断初始字符奇偶性即可。
// #pragma GCC optimize(3,"Ofast","inline")
// #pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define point(n) fixed << setprecision(n)
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0), cout.tie(0);
#define debug(a) cout << "=======" << a << "========" << endl;
#define endl '\n'
#define inf 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
ll pow(ll a, ll b, ll mod)
{
ll res = 1;
while (b > 0)
{
a = a % mod;
if (b & 1)
res = res * a % mod;
b = b >> 1;
a = a * a % mod;
}
return res;
}
ll pow(ll a, ll b)
{
ll res = 1;
while (b > 0)
{
if (b & 1)
res = res * a;
b = b >> 1;
a = a * a;
}
return res;
}
ll ceil(ll a, ll b)
{
if (a % b == 0)
return a / b;
else
return a / b + 1;
}
typedef pair<int, int> PII;
const int N = 1e6 + 10, mod = 1e9 + 7;
int n, m, k;
int f[N];
void solve()
{
string s;
cin >> s;
int cnt1 = 0, cnt2 = 0;
for (auto g : s)
{
if (g == '0')
cnt2++;
else
cnt1++;
}
if (cnt1 & 1 && cnt2 & 1)
cout << "No\n";
else
cout << "Yes\n";
}
int main()
{
IOS;
int _;
cin >> _;
while (_--)
solve();
return 0;
}
小红闯沼泽地
dp或者最短路或者dfs都可以做出来
// #pragma GCC optimize(3,"Ofast","inline")
// #pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define point(n) fixed << setprecision(n)
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0), cout.tie(0);
#define debug(a) cout << "=======" << a << "========" << endl;
#define endl '\n'
#define inf 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
ll pow(ll a, ll b, ll mod)
{
ll res = 1;
while (b > 0)
{
a = a % mod;
if (b & 1)
res = res * a % mod;
b = b >> 1;
a = a * a % mod;
}
return res;
}
ll pow(ll a, ll b)
{
ll res = 1;
while (b > 0)
{
if (b & 1)
res = res * a;
b = b >> 1;
a = a * a;
}
return res;
}
ll ceil(ll a, ll b)
{
if (a % b == 0)
return a / b;
else
return a / b + 1;
}
typedef pair<int, int> PII;
const int N = 1e6 + 10, mod = 1e9 + 7;
int n, m, k;
int f[N];
ll mp[2010][2010];
ll dp[2010][2010];
void solve()
{
}
int main()
{
IOS;
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> mp[i][j];
memset(dp, 0x3f, sizeof dp);
dp[1][1] = 0;
for (int i = 1; i <= n; i++)
{
for (int j = m; j >= 1; j--)
{
dp[i][j] = min({dp[i][j], dp[i - 1][j] + 1 + (mp[i - 1][j] != mp[i][j]), dp[i][j + 1] + 1 + (mp[i][j + 1] != mp[i][j])});
}
for (int j = 1; j <= m; j++)
{
dp[i][j] = min({dp[i][j], dp[i - 1][j] + 1 + (mp[i - 1][j] != mp[i][j]), dp[i][j - 1] + 1 + (mp[i][j - 1] != mp[i][j])});
}
}
cout << dp[n][m] << endl;
return 0;
}
小红的漂亮串(二)
题目要求至少2个,我们可以先求出来0个和1个的情况,最后用26^n-dp[n][0]-dp[n][1],第一维表示位数,第二维表示red的个数。先初始化dp[0][0]=1,dp[1][0]=26,dp[2][0]=26*26。
dp[i][0]=dp[i-1][0]*26-dp[i-3][0] 假设前i-3位已经填好,并且没有red,我们让i-2~i位为red,这样就要减去dp[i-3][0]
dp[i][1]=dp[i-1][1]*26-dp[i-3][1]+dp[i-3][0] 假设前i-3位已经填好,并且已经有一个red,如果i-2~i位是red,就有两个red了,所以我们要减去dp[i-3][1],如果前i-3位没有red,我们让i-2~i位是red,这样前i位就只有一个red,所以我们要加上dp[i-3][0]。
// #pragma GCC optimize(3,"Ofast","inline")
// #pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define point(n) fixed << setprecision(n)
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0), cout.tie(0);
#define debug(a) cout << "=======" << a << "========" << endl;
#define endl '\n'
#define inf 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
ll pow(ll a, ll b, ll mod)
{
ll res = 1;
while (b > 0)
{
a = a % mod;
if (b & 1)
res = res * a % mod;
b = b >> 1;
a = a * a % mod;
}
return res;
}
ll pow(ll a, ll b)
{
ll res = 1;
while (b > 0)
{
if (b & 1)
res = res * a;
b = b >> 1;
a = a * a;
}
return res;
}
ll ceil(ll a, ll b)
{
if (a % b == 0)
return a / b;
else
return a / b + 1;
}
typedef pair<int, int> PII;
const int N = 1e6 + 10, mod = 1e9 + 7;
int n, m, k;
int f[N];
ll e[N], ne[N];
ll dp[N][2];
int main()
{
IOS;
cin >> n;
if (n < 6)
cout << 0 << endl;
else
{
dp[0][0] = 1;
dp[1][0] = 26;
dp[2][0] = 26 * 26;
for (int i = 3; i <= n; i++)
{
dp[i][0] = (dp[i - 1][0] * 26 - dp[i - 3][0]) % mod;
dp[i][1] = (dp[i - 1][1] * 26 + dp[i - 3][0] - dp[i - 3][1]) % mod;
}
cout << (pow(26, n, mod) - dp[n][0] - dp[n][1] + mod) % mod << endl;
}
return 0;
}