暑期个人赛第二场

第二场个人赛,队友三人齐上阵,感觉还是蛮不错的,队友分别收获a,d一血,自己在c题也险些拿下一血,甚是可惜

 

先看看自己研究的c吧

 

C 1213 小V的滑板鞋

思路:双目标优化问题,瞬间想到星星问题,树状数组优化处理

即先考虑按质量(最大1e9)排序,后面处理的就一定能满足第一维质量条件。再将第二维树状数组处理

而1e9的鞋子数按单支处理,O(n^2)肯定tle,于是想到四数和的分治,即将所有鞋子处理出一个对称映像,即买完这只鞋后剩余的质量和价格空间,放入树状数组中一起排序,当每次处理到映像时,求解所有已存在的鞋子数,即可顺利解决

注意一下,当质量和金钱均小于要求的一半时,本身比可以被处理进来,于是在最开始预处理减掉这种情况即可。

最后,就是注意一下cmp的处理,等号一定要特判啊,这个点wa了我1h,直接wa掉了我完美的一血梦,关键是心态有点崩,还需冷静

 

/*
Author Owen_Q
*/

#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e5+10;

typedef struct SHOES
{
    int m;
    int w;
    bool isShoes;
}Shoes;

Shoes sho[maxn];

int c[maxn];

bool cmp(const Shoes &a,const Shoes &b)
{
    if(a.m<b.m)
    {
        return true;
    }
    else if((a.m==b.m)&&(a.w<b.w))
    {
        return true;
    }
    else if((a.m==b.m)&&(a.w==b.w)&&(a.isShoes)&&(!b.isShoes))
    {
        return true;
    }
    else
    {
        return false;
    }
}

int lowbit(int x)
{
	return x&-x;
}

int sum(int i)
{
	int s=0;
	while(i>0)
	{
		s+=c[i];
		i-=lowbit(i);
	}
	return s;
}

void modify(int i,int val)
{
	while(i<=(1e5+10))
	{
		c[i]+=val;
		i+=lowbit(i);
	}
}


int main()
{
    int n;
    int M,W;
    while(scanf("%d%d%d",&n,&M,&W)!=EOF)
    {
        memset(c,0,sizeof(c));
        long long sumshoes = 0LL;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&sho[i].m);
            sho[i+n].m = M - sho[i].m;
        }
        for(int i=0;i<n;i++)
        {
            scanf("%d",&sho[i].w);
            sho[i].isShoes = true;
            sho[i+n].w = W - sho[i].w;
            sho[i+n].isShoes = false;
            if(((2*sho[i].m)<=M)&&((2*sho[i].w)<=W))
            {
                sumshoes--;
            }
        }
        sort(sho,sho+n*2,cmp);
        for(int i=0;i<2*n;i++)
        {
            if(sho[i].isShoes)
            {
                modify(sho[i].w,1);
            }
            else
            {
                if(sho[i].w>0)
                {
                    sumshoes += (long long)(sum(sho[i].w));
                }
            }
        }
        //cout << sumshoes << endl;
        sumshoes /= 2LL;
        printf("%lld\n",sumshoes);
    }
    return 0;
}


再来看看我两个队友拿的一血吧

 

A 1229 Glory And String

思路:又是个典型的字符串dp问题,不难发现,删除和添加操作是一样的,于是,对原串和反串做个lcs,O(n^2)的复杂度绰绰有余,完美解决

 

/*
Author Owen_Q
*/

#include <bits/stdc++.h>

using namespace std;

const int maxn = 5e3+10;

char a[maxn],b[maxn];
int f[maxn][maxn];

int main()
{
    int t;
    while(scanf("%d",&t)!=EOF)
    {
        while(t--)
        {
            scanf("%s",&a[1]);
            int n = strlen(&a[1]);
            //cout << n << endl;
            for(int i=1;i<=n;i++)
            {
                b[i]=a[n-i+1];
            }
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=n;j++)
                {
                    if(a[i]==b[j])
                    {
                        f[i][j]=f[i-1][j-1]+1;
                    }
                    else
                    {
                        f[i][j]=max(f[i-1][j],f[i][j-1]);
                    }
                }
            }
            printf("%d\n",n-f[n][n]);
        }
    }
    return 0;
}


最后一题,另一个队友写的模拟

 

D 1237 W老师的玩具

思路:寻找最优策略,逆向模拟,正数减一,零合并,只要想到,问题并不大

 

/*
Author Owen_Q
*/

#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e6+10;

int a[maxn];

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        sort(a,a+n);
        int t = 0;
        int di = 0;
        while(t < a[n-1])
        {
            int ze = upper_bound(a+di,a+n,t) - &a[di];
            if(ze + &a[di] == &a[n])
            {
                ze = 0;
            }
            //cout << ze << "*0*"<<endl;
            di += (ze >> 1) ;
            t++;
        }
        int les = n - di;
        //cout << les << "**" << t<<endl;
        while(les>1)
        {
            t++;
            les -= (les>>1);
        }
        printf("%d\n",t);
    }
    return 0;
}


总的来说还挺不错,加油吧

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值