Codeforces 779

Codeforces 779

Codeforces 779B Weird Rounding

贪心,从后面往前面贪心,注意特判即可

#include <cstdio>
#include <cmath>

using namespace std;

typedef long long LL;

LL n,k,ans,cnt,tmp;

int main()
{
    scanf("%lld%lld",&n,&k);
    if(n==0)    {puts("0");return 0;}
    tmp=n;
    while(n)
    {
        if(n%10==0) cnt++;
        else ans++;
        n/=10;
        if(cnt==k)  break;
    }
    printf("%lld\n",cnt==k?ans:(int)log10(tmp));
    return 0;
}

Codeforces 779C Dishonest Sellers

可以排序,也可以先 O(n) 扫描一遍,同一天选较少的,新建数组储存差价,如果不够k,再补差价即可
貌似可以出到 1e7 不能毒害

#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long LL;

const int MAXN=200000+10;

LL n,k;

LL l[MAXN],a[MAXN],cnt,ans,tmp[MAXN];

bool cmp(int A,int B)   {return A<B;}

int main()
{
    scanf("%lld%lld",&n,&k);
    for(int i=1;i<=n;i++)
        scanf("%lld",&l[i]);
    for(int j=1;j<=n;j++)
        scanf("%lld",&a[j]);
    for(int i=1;i<=n;i++)
    {
        if(l[i]<=a[i])  ans+=l[i],cnt++;
        else ans+=a[i],tmp[++tmp[0]]=l[i]-a[i];
    }
    sort(tmp+1,tmp+tmp[0]+1,cmp);
    for(int i=1;i<=(k-cnt);i++)
        ans=ans+tmp[i];
    printf("%lld\n",ans);
    return  0;
}
Codeforces 779D String Game

二分答案,check即可

#include <cstdio>
#include <cstring>

using namespace std;

const int MAXN=200000+10;

char a[MAXN],b[MAXN];
int pos,ans,len1,len2;
int w[MAXN];
bool v[MAXN];

bool check(int m)
{
    int cnt=0;
    memset(v,0,sizeof v);
    for(int i=1;i<=m;i++)
        v[w[i]-1]=1;
    for(int i=0;i<len1;i++)
    {
        if(b[cnt]==a[i]&&(!v[i]))   cnt++;
        if(cnt==len2)   return true;
    }
    if(cnt==len2)   return true;
    return false;

}

int main()
{
    scanf("%s",a);
    scanf("%s",b);
    len1=strlen(a),len2=strlen(b);
    for(int i=1;i<=len1;i++)
        scanf("%d",&w[i]);
    int l=0,r=len1;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        if(check(mid))  ans=mid,l=mid+1;
        else r=mid-1;
    }
    printf("%d\n",ans);
}
Codeforces 779E Bitwise Formula

二进制分开枚举即可

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值