A. A Healthy Breakfast
题意:一个长度为3的字符串,R在M前面则输出YES,否则输出NO
思路:字符串find函数解决,水题
ac代码:
/* ʕ•̀ ω • ʔ *˘︶˘*).。.:*♡ (∗ᵒ̶̶̷̀ω˂̶́∗)੭₎₎̊₊♡ (⋈◍>◡<◍) ʕ•̫͡• ʔ•̫͡•ཻʕ•̫͡•ʔ•͓͡•ʔ.•♫•♬ •♬•♫•.✿.。.:* ☆ .:**:.☆*.:。.✿ *★°*:.☆:*.°★*
●▂● ●0● ●︿● ●ω● ●﹏● ●△● ●▽● ♡⃝ ʜᴇʟʟᴏ •ᴗ• ☽⋆
∩ ∩ ̋(๑˃́ꇴ˂̀๑) ᐕ)⁾⁾ *:ஐ (๑´ᵕ`) ஐ:* *ଘ(੭*ˊᵕˋ)੭* (੭ˊᵕˋ)੭* ੈ✩˚
>(>_<)<
I I
I I ʕง•ᴥ•ʔง
IU UI
I I ꉂꉂ꒰•̤▿•̤*ૢ꒱
≧▂≦ ≧0≦ ≧︿≦ ≧ω≦ ≧﹏≦ ≧△≦ ꒰๑˃͈꒵˂͈๑꒱
☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫
(~o▔▽▔)~o o~(▔▽▔o~) ‿︵‿︵‿︵୨˚̣̣̣͙୧ - - - -୨˚̣̣̣͙୧‿︵‿︵‿︵
*/
#include<bits/stdc++.h>
using namespace std;
#define lll __int128
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> PII;
const int mod=1e9+7;
inline ll read()
{
ll x = 0, y = 1;
char c = getchar();
while (!isdigit(c))
{
if (c == '-')
y = -1;
c = getchar();
}
while (isdigit(c))
{
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x *= y;
}
inline void write(ll x)
{
if (x < 0)
x = -x, putchar('-');
ll sta[35], top = 0;
do
sta[top++] = x % 10, x /= 10;
while (x);
while (top)
putchar(sta[--top] + '0');
}
void Miraitowa(){
string s;
cin >> s;
if(s.find('R')<s.find('M'))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
Miraitowa();
return 0;
};
B. Vertical Reading
题意:给两个字符串,找一对整数c和w,使得s从头开始每隔w个字符拆分一次,那么长度至少为c的子串的c个字符依次连接等于T
思路:模拟,枚举w,模拟过程,当遇到字符串为T时则输出yes,否则no
ac代码:
/* ʕ•̀ ω • ʔ *˘︶˘*).。.:*♡ (∗ᵒ̶̶̷̀ω˂̶́∗)੭₎₎̊₊♡ (⋈◍>◡<◍) ʕ•̫͡• ʔ•̫͡•ཻʕ•̫͡•ʔ•͓͡•ʔ.•♫•♬ •♬•♫•.✿.。.:* ☆ .:**:.☆*.:。.✿ *★°*:.☆:*.°★*
●▂● ●0● ●︿● ●ω● ●﹏● ●△● ●▽● ♡⃝ ʜᴇʟʟᴏ •ᴗ• ☽⋆
∩ ∩ ̋(๑˃́ꇴ˂̀๑) ᐕ)⁾⁾ *:ஐ (๑´ᵕ`) ஐ:* *ଘ(੭*ˊᵕˋ)੭* (੭ˊᵕˋ)੭* ੈ✩˚
>(>_<)<
I I
I I ʕง•ᴥ•ʔง
IU UI
I I ꉂꉂ꒰•̤▿•̤*ૢ꒱
≧▂≦ ≧0≦ ≧︿≦ ≧ω≦ ≧﹏≦ ≧△≦ ꒰๑˃͈꒵˂͈๑꒱
☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫
(~o▔▽▔)~o o~(▔▽▔o~) ‿︵‿︵‿︵୨˚̣̣̣͙୧ - - - -୨˚̣̣̣͙୧‿︵‿︵‿︵
*/
#include <bits/stdc++.h>
using namespace std;
#define lll __int128
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> PII;
const int mod = 1e9 + 7;
inline ll read()
{
ll x = 0, y = 1;
char c = getchar();
while (!isdigit(c))
{
if (c == '-')
y = -1;
c = getchar();
}
while (isdigit(c))
{
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x *= y;
}
inline void write(ll x)
{
if (x < 0)
x = -x, putchar('-');
ll sta[35], top = 0;
do
sta[top++] = x % 10, x /= 10;
while (x);
while (top)
putchar(sta[--top] + '0');
}
void Miraitowa()
{
string s, a;
cin >> s >> a;
set<string> se;
for (int k = 1; k < s.size(); k++)
{
for (int i = 0; i < k; i++)
{
string str;
for (int j = i; j < s.size(); j += k)
{
str += s[j];
}
se.insert(str);
}
}
if (se.count(a))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
// int t;
// cin>>t;
// while(t--)
Miraitowa();
return 0;
};
C. Move It
题意:有一个1到N的箱子和物品,求每个箱子正好有一件物品所需的最小的总成本
思路:刚开始有N个物品放在了箱子里,可能有的箱子放多个或者一个没放,但是最后我们需要使得每个箱子都要有1个物品,所以一个箱子里有多个物品肯定是要留一个,剩下的全移走,那么我们为了使得总成本最小,则留下成本最大的那个,剩下的全移走就行,可以通过数组排序实现这个过程
ac代码:
/* ʕ•̀ ω • ʔ *˘︶˘*).。.:*♡ (∗ᵒ̶̶̷̀ω˂̶́∗)੭₎₎̊₊♡ (⋈◍>◡<◍) ʕ•̫͡• ʔ•̫͡•ཻʕ•̫͡•ʔ•͓͡•ʔ.•♫•♬ •♬•♫•.✿.。.:* ☆ .:**:.☆*.:。.✿ *★°*:.☆:*.°★*
●▂● ●0● ●︿● ●ω● ●﹏● ●△● ●▽● ♡⃝ ʜᴇʟʟᴏ •ᴗ• ☽⋆
∩ ∩ ̋(๑˃́ꇴ˂̀๑) ᐕ)⁾⁾ *:ஐ (๑´ᵕ`) ஐ:* *ଘ(੭*ˊᵕˋ)੭* (੭ˊᵕˋ)੭* ੈ✩˚
>(>_<)<
I I
I I ʕง•ᴥ•ʔง
IU UI
I I ꉂꉂ꒰•̤▿•̤*ૢ꒱
≧▂≦ ≧0≦ ≧︿≦ ≧ω≦ ≧﹏≦ ≧△≦ ꒰๑˃͈꒵˂͈๑꒱
☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫
(~o▔▽▔)~o o~(▔▽▔o~) ‿︵‿︵‿︵୨˚̣̣̣͙୧ - - - -୨˚̣̣̣͙୧‿︵‿︵‿︵
*/
#include<bits/stdc++.h>
using namespace std;
#define lll __int128
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> PII;
const int mod=1e9+7;
inline ll read()
{
ll x = 0, y = 1;
char c = getchar();
while (!isdigit(c))
{
if (c == '-')
y = -1;
c = getchar();
}
while (isdigit(c))
{
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x *= y;
}
inline void write(ll x)
{
if (x < 0)
x = -x, putchar('-');
ll sta[35], top = 0;
do
sta[top++] = x % 10, x /= 10;
while (x);
while (top)
putchar(sta[--top] + '0');
}
bool cmp(PII a,PII b){
if(a.first!=b.first)
return a.first < b.first;
return a.second > b.second;
}
const int N = 2e5 + 10;
PII a[N];
void Miraitowa(){
int n;
cin >> n;
for (int i = 1; i <= n;i++)
cin >> a[i].first;
for (int i = 1; i <= n;i++)
cin >> a[i].second;
sort(a + 1, a + 1 + n,cmp);
ll id = 0, res = 0;
for (int i = 1; i <= n;i++)
if (id != a[i].first)
id = a[i].first;
else res += a[i].second;
cout << res << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
// int t;
// cin>>t;
// while(t--)
Miraitowa();
return 0;
};
D.Ghost Ants
题意:在横坐标上有N只蚂蚁,有的往左走有的往右走,求在T秒内有多少蚂蚁相交
思路:首先我们可以用两个数组将蚂蚁向左走和向右走的位置存下来排序,然后我们可以枚举向右走的蚂蚁,每秒会移动1单位,那么我们可以看成向右走的移动两米,在t秒后能到的距离能和多少个像左走的蚂蚁位置相交,这个可以通过二分来获得到两个边界,相减后就是这只蚂蚁能在T秒内和多少蚂蚁碰面
ac代码:
/* ʕ•̀ ω • ʔ *˘︶˘*).。.:*♡ (∗ᵒ̶̶̷̀ω˂̶́∗)੭₎₎̊₊♡ (⋈◍>◡<◍) ʕ•̫͡• ʔ•̫͡•ཻʕ•̫͡•ʔ•͓͡•ʔ.•♫•♬ •♬•♫•.✿.。.:* ☆ .:**:.☆*.:。.✿ *★°*:.☆:*.°★*
●▂● ●0● ●︿● ●ω● ●﹏● ●△● ●▽● ♡⃝ ʜᴇʟʟᴏ •ᴗ• ☽⋆
∩ ∩ ̋(๑˃́ꇴ˂̀๑) ᐕ)⁾⁾ *:ஐ (๑´ᵕ`) ஐ:* *ଘ(੭*ˊᵕˋ)੭* (੭ˊᵕˋ)੭* ੈ✩˚
>(>_<)<
I I
I I ʕง•ᴥ•ʔง
IU UI
I I ꉂꉂ꒰•̤▿•̤*ૢ꒱
≧▂≦ ≧0≦ ≧︿≦ ≧ω≦ ≧﹏≦ ≧△≦ ꒰๑˃͈꒵˂͈๑꒱
☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫
(~o▔▽▔)~o o~(▔▽▔o~) ‿︵‿︵‿︵୨˚̣̣̣͙୧ - - - -୨˚̣̣̣͙୧‿︵‿︵‿︵
*/
#include <bits/stdc++.h>
using namespace std;
#define lll __int128
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> PII;
const int mod = 1e9 + 7;
inline ll read()
{
ll x = 0, y = 1;
char c = getchar();
while (!isdigit(c))
{
if (c == '-')
y = -1;
c = getchar();
}
while (isdigit(c))
{
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x *= y;
}
inline void write(ll x)
{
if (x < 0)
x = -x, putchar('-');
ll sta[35], top = 0;
do
sta[top++] = x % 10, x /= 10;
while (x);
while (top)
putchar(sta[--top] + '0');
}
const int N = 5e5 + 10;
ll a[N];
vector<ll> v0, v1;
void Miraitowa()
{
ll n, t;
string s;
cin >> n >> t >> s;
for (int i = 0; i < n; i++)
{
cin >> a[i];
if (s[i] == '0')
v0.push_back(a[i]);
else
v1.push_back(a[i]);
}
sort(v0.begin(), v0.end());
sort(v1.begin(), v1.end());
ll ans = 0;
for (int i = 0; i < (ll)v1.size(); i++)
{
if (!v0.size() || !v1.size())
continue;
ll l = 0, r = (ll)v0.size() - 1, res = -1;
while (l <= r)
{
ll mid = (l + r) >> 1;
if (v0[mid] <= v1[i] + t * 2)
{
l = mid + 1;
res = mid;
}
else
r = mid - 1;
}
ll l2 = 0, r2 = (ll)v0.size() - 1, res2 = -1;
while (l2 <= r2)
{
ll mid = (l2 + r2) >> 1;
if (v0[mid] >= v1[i])
{
r2 = mid - 1;
res2 = mid;
}
else
l2 = mid + 1;
}
if (res != -1 && res2 != -1 && res >= res2)
ans += max(0ll, res - res2 + 1);
}
cout << ans << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
// int t;
// cin>>t;
// while(t--)
Miraitowa();
return 0;
};
E. Random Swaps of Balls
题意:有N-1个白球和一个黑球排成一排,黑球在最左边,每次操作可以任选两个位置,若两个位置不同则交换,问经过k次交换后,黑球在第x个位置,求x的期望
思路:首先我们思考,每次都是等可能获取,那么k次操作后黑球到2~n任何一个位置的可能性相同,因此我们可以先求出在k次操作后黑球在第一个位置的概率,剩下位置的概率为(1-在第一个位置的概率)/(n-1)
因此我们可以用递推的思想考虑这个问题,设f[i]
表示为经过第i次操作后黑球在第一个位置的概率,
那么可以分为两种情况:
-
如果
f[i-1]
经过第i次操作后黑球在第一个位置,那么我们本次操作只需要移动不是第一个位置或者两次都是第一个位置,总共有n*n
种可能,操作后不在第一个位置的可能有选第1和其他的,和选其他的和1这些情况,共2*(n-1)种,因此f[i]=f[i-1]*(n*n-2*(n-1))/n*n
-
如果
f[i-1]
经过第i次操作后黑球不在第一个位置,那么我们本次操作只需要选到1,有两种情况,因此
`f[i]=(1-f[i-1])*2/n*n`
得到了递推公式那么我们就可以计算出第一个位置的概率f[k],剩下的位置的概率为(1-f[k])/(n-1),最后计算期望就可以了
ac代码:
```c
/* ʕ•̀ ω • ʔ *˘︶˘*).。.:*♡ (∗ᵒ̶̶̷̀ω˂̶́∗)੭₎₎̊₊♡ (⋈◍>◡<◍) ʕ•̫͡• ʔ•̫͡•ཻʕ•̫͡•ʔ•͓͡•ʔ.•♫•♬ •♬•♫•.✿.。.:* ☆ .:**:.☆*.:。.✿ *★°*:.☆:*.°★*
●▂● ●0● ●︿● ●ω● ●﹏● ●△● ●▽● ♡⃝ ʜᴇʟʟᴏ •ᴗ• ☽⋆
∩ ∩ ̋(๑˃́ꇴ˂̀๑) ᐕ)⁾⁾ *:ஐ (๑´ᵕ`) ஐ:* *ଘ(੭*ˊᵕˋ)੭* (੭ˊᵕˋ)੭* ੈ✩˚
>(>_<)<
I I
I I ʕง•ᴥ•ʔง
IU UI
I I ꉂꉂ꒰•̤▿•̤*ૢ꒱
≧▂≦ ≧0≦ ≧︿≦ ≧ω≦ ≧﹏≦ ≧△≦ ꒰๑˃͈꒵˂͈๑꒱
☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫☗♪叮☖叮♫ ☗铛♪ ☖♫
(~o▔▽▔)~o o~(▔▽▔o~) ‿︵‿︵‿︵୨˚̣̣̣͙୧ - - - -୨˚̣̣̣͙୧‿︵‿︵‿︵
*/
#include<bits/stdc++.h>
using namespace std;
#define lll __int128
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> PII;
const int mod = 998244353;
inline ll read()
{
ll x = 0, y = 1;
char c = getchar();
while (!isdigit(c))
{
if (c == '-')
y = -1;
c = getchar();
}
while (isdigit(c))
{
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x *= y;
}
inline void write(ll x)
{
if (x < 0)
x = -x, putchar('-');
ll sta[35], top = 0;
do
sta[top++] = x % 10, x /= 10;
while (x);
while (top)
putchar(sta[--top] + '0');
}
ll qmi(ll a,ll b){
ll res = 1;
while(b){
if(b&1) res = res * a % mod;
b >>= 1;
a = a * a % mod;
}
return res;
}
const int N = 5e5 + 10;
ll f[N],p0, p1;
void Miraitowa(){
ll n, k;
cin >> n >> k;
p0 = (n * n - 2 * (n - 1)) % mod * qmi(n * n%mod, mod - 2)%mod;
p1 = 2 * qmi(n * n%mod, mod - 2)%mod;
f[0] = 1;
for (int i = 1; i <= k;i++)
f[i] = (f[i - 1] * p0 % mod + (1-f[i - 1]+mod) * p1%mod) % mod;
ll ans = f[k];
ans += (1 - f[k]+mod)*qmi(n-1,mod-2)%mod * ((n + 2)*(n-1) / 2%mod) %mod;
ans %= mod;
cout << ans << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
// int t;
// cin>>t;
// while(t--)
Miraitowa();
return 0;
};
```