Educational Codeforces Round 74 (Rated for Div. 2)

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=2npossi1possi
则对于一个字母a来说

  • 如果是pos比他小的字母i,若这两个字母相邻,则它们的贡献为 c n t ∗ ( p o s a − p o s i ) cnt*(pos_a-pos_i) cnt(posaposi),cnt为这个两个字母相邻的次数,拆开来就是 c n t ∗ p o s a − c n t ∗ p o s i cnt*pos_a-cnt*pos_i cntposacntposi
  • 如果是pos比他大的字母j,若这两个字母相邻,则它们的贡献为 c n t ∗ ( p o s j − p o s a ) cnt*(pos_j-pos_a) cnt(posjposa),cnt为这个两个字母相邻的次数,拆开来就是 c n t ∗ p o s j − c n t ∗ p o s a cnt*pos_j-cnt*pos_a cntposjcntposa
  • 所以字母a对答案的贡献为 p o s a ∗ ( ∑ c n t i − ∑ c n t j ) pos_a*(\sum cnt_i-\sum cnt_j) posa(cnticntj)
    综上所述,当插入字母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在路上了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值