2018.12.15 jzoj c组题解(差T4)

本文解析了四道编程题目,包括模拟、离散化压缩、目标环搜索和待解决的问题,涉及C++代码实现,展示了从输入处理到算法设计的全过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

T1

题解:这道题属于水题,模拟

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
long long int n,ans1=-10,ans2,a,b,c,an,na,ns;
char s[21],as[21],st1,st2;
void getc()
{
    na=1;
    scanf("%c",&s[na]);
    while(s[na]!=' ')scanf("%c",&s[++na]);
    na--;
}
int main()
{
    freopen("scholar.in","r",stdin);
    freopen("scholar.out","w",stdout);
    scanf("%lld\n",&n);
    for(int i=1;i<=n;i++)
    {
        getc();
        scanf("%lld %lld %c %c %lld\n",&a,&b,&st1,&st2,&c);
        an=0;
        if(a>80&&c>=1)an+=8000;
        if(a>85&&b>80)an+=4000;
        if(a>90)an+=2000;
        if(a>85&&st2=='Y')an+=1000;
        if(b>80&&st1=='Y')an+=850;
        ans2+=an;
        if(an>ans1)
        {
            ans1=an;
            ns=na;
            for(int j=1;j<=na;j++)
            {
                as[j]=s[j];
            }
        }
    }
    for(int i=1;i<=ns;i++)
    {
         printf("%c",as[i]);
    }printf("\n");
    printf("%lld\n%lld",ans1,ans2);
    return 0;
}

T2

题解:离散化压位,搞一下就行了

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
long long int l,s,t,m,f[1000001],st[150000],fl[1500000],ans=999999999;
int main()
{
    freopen("river.in","r",stdin);
    freopen("river.out","w",stdout);
    memset(f,127,sizeof(f));
    scanf("%lld%lld%lld%lld",&l,&s,&t,&m);
    for(long long int i=1;i<=m;i++)scanf("%lld",&st[i]);
    sort(st+1,st+m+1);
    if(s==t)
    {
        ans=0;
        for(int i=1;i<=m;i++)if(st[i]%s==0)ans++;
        printf("%lld",ans);return 0;
    }
    st[0]=0;
    long long int k=s*t/(t-s)+s+t+1;l=0;
    for(long long int i=1;i<=m;i++)
    {
        l+=min(st[i]-st[i-1],k);
        fl[l]=1;
    }
    f[0]=0;
    for(int i=0;i<=l+t;i++)
    {
        for(int j=i-t;j<=i-s;j++)
        {
            if(j>=0)
            {
                f[i]=min(f[i],f[j]+fl[i]);
            }
        }
    }
    for(int i=l;i<=l+t;i++)
    {
        ans=min(ans,f[i]);
    }
    printf("%lld",ans);
    return 0;
}

T3

题解:建个目标环,顺时针和逆时针搜一遍当前点与目标的距离,然后找距离一致中的最多的,用n减去它就是答案

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
long long int n,a[50001],b[50001],dis[100001],dis2[100001],ans=-2147483647;
struct nod{long long int l,r;}f[50001];
int main()
{
    freopen("fire.in","r",stdin);
    freopen("fire.out","w",stdout);
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        a[i]=i;
        scanf("%lld %lld",&f[i].l,&f[i].r);
    }
    b[1]=1;
    b[2]=f[1].l;
    b[n]=f[1].r;
    for(int i=3;i<=n-1;i++)
    {
        if(b[i-2]==f[b[i-1]].l)
        {
            b[i]=f[b[i-1]].r;
        }
        else if(b[i-2]==f[b[i-1]].r)
        {
            b[i]=f[b[i-1]].l;
        }
        else
        {
            printf("-1");
            return 0;
        }
    }
    for(int i=1;i<=n;i++)
    {
        dis[(i-b[i]+n)%n]++;
        dis2[(b[i]+i+n)%n]++;
    }
    for(int i=0;i<=2*n;i++)
    {
        ans=max(ans,max(dis[i],dis2[i]));
    }
    long long int xc=n-ans;
    printf("%lld\n",xc);
    return 0;
}

T4

作者正在写代码中...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值