A
#include<cstdio>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
int main()
{
ll a,b;int T;cin>>T;
while(T--)
{
cin>>a>>b;
if(a-b<2)puts("NO");
else puts("YES");
}
return 0;
}
B
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N = 1e5+10;
int arr[N];
int main()
{
int T;cin>>T;
while(T--)
{
int n,r;cin>>n>>r;
for(int i=1;i<=n;++i)
cin>>arr[i];
sort(arr+1,arr+1+n);
int len = unique(arr+1,arr+1+n)-arr;
int now=0;
for(int i=len-1;i>0&&arr[i]>now;--i)
now+=r;
cout<<now/r<<endl;
}
return 0;
}
C
没看懂题,咕
D
#include<cstdio>
#include<iostream>
#define ll long long
using namespace std;
const int N = 3e5+10;
int dp[N];
char s[N];
int nxt[N],pre[N];
ll ans;
int main()
{
int n;cin>>n;
cin>>s+1;
int A = 0,B = 0;
ans = 1ll*(n-1)*n/2;
for(int i=1;i<=n;++i)
{
if(s[i]=='A')
pre[i] = A,A = i;
else
pre[i] = B,B = i;
}
A = B = n+1;
for(int i=n;i;--i)
{
if(s[i]=='A')
nxt[i] = A,A = i;
else
nxt[i] = B,B = i;
}
for(int i=1;i<=n;++i)
{
if(s[i]!=s[i+1] &&i<n)
ans++;
ans -= nxt[i]-pre[i]-2;
}
cout<<ans<<endl;
return 0;
}
E
很有意思的一道题
求
∑
i
=
2
n
∣
p
o
s
s
i
−
1
−
p
o
s
s
i
∣
\sum\limits^{n}_{i=2}|pos_{s_{i-1}}-pos_{si}|
i=2∑n∣possi−1−possi∣
则对于一个字母a来说
- 如果是pos比他小的字母i,若这两个字母相邻,则它们的贡献为 c n t ∗ ( p o s a − p o s i ) cnt*(pos_a-pos_i) cnt∗(posa−posi),cnt为这个两个字母相邻的次数,拆开来就是 c n t ∗ p o s a − c n t ∗ p o s i cnt*pos_a-cnt*pos_i cnt∗posa−cnt∗posi
- 如果是pos比他大的字母j,若这两个字母相邻,则它们的贡献为 c n t ∗ ( p o s j − p o s a ) cnt*(pos_j-pos_a) cnt∗(posj−posa),cnt为这个两个字母相邻的次数,拆开来就是 c n t ∗ p o s j − c n t ∗ p o s a cnt*pos_j-cnt*pos_a cnt∗posj−cnt∗posa
- 所以字母a对答案的贡献为
p
o
s
a
∗
(
∑
c
n
t
i
−
∑
c
n
t
j
)
pos_a*(\sum cnt_i-\sum cnt_j)
posa∗(∑cnti−∑cntj)
综上所述,当插入字母a时,只要知道比它小的字母,就能知道此时它对答案的贡献。这样我们就可以状压dp了
dp[i]中i表示哪个字母已经被用过了,然后就可以加没用过的字母更新状态,加的顺序就是pos,比如已经有3个字母了,则现在加的pos就为4
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int M = (1<<21);
int dp[M][21];
char s[100010];
int mp[21][21];
int rdp[M];
int main()
{
int len,m;cin>>len>>m;
cin>>s+1;
memset(rdp,0x3f,sizeof(rdp));
for(int i=1;i<len;++i)
{
if(s[i]==s[i+1])continue;
mp[s[i]-'a'][s[i+1]-'a']++;
mp[s[i+1]-'a'][s[i]-'a']++;
}
for(int i=1;i<(1<<m);++i)
for(int j=0;j<m;++j)
{
//cout<<i<<" "<<j<<endl;
if((i&(1<<j))==0)
{
//cout<<" "<<j<<endl;
for(int k=0;k<m;++k)
if((i&(1<<k)))
{
dp[i][j]+=mp[j][k];
// cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
}
}
}
rdp[0]=0;
int l =(1<<m)-1;
for(int i=0;i<(1<<m);++i)
{
int gs=0;
for(int j=0;j<m;++j)
if(i&(1<<j))
gs++;
for(int j=0;j<m;++j)
if((i&(1<<j))==0)
{
//cout<<i<<" "<<j<<" "<<" "<<(l^i^(1<<j))<<endl;
rdp[i^(1<<j)] = min(rdp[i^(1<<j)],rdp[i]+gs*(dp[i][j]-dp[l^i^(1<<j)][j]));
//cout<<" "<<i<<" "<<j<<" "<<rdp[i^(1<<j)]<<" "<<gs<<" "<<dp[i][j]-dp[((1<<m)-1)^i][j]<<endl;
}
}
cout<<rdp[(1<<m)-1]<<endl;
return 0;
}
E咕咕咕
F在路上了