cf1207解题报告

cf1207解题报告

A

模拟

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll T,a,b,c,x,y;
int main() {
    cin>>T;
    while(T --> 0) {
        cin>>a>>b>>c>>x>>y;
        ll ans=0;
        if(x>y) {
            while(a>=2&&b>=1) ans+=x,a-=2,b--;
            while(a>=2&&c>=1) ans+=y,a-=2,c--;
        } else {
            while(a>=2&&c>=1) ans+=y,a-=2,c--;
            while(a>=2&&b>=1) ans+=x,a-=2,b--;
        }
        cout<<ans<<"\n";
    }
    return 0;
}

B

能选就选

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int _=110;
int n,m,a[_][_],b[_][_];
vector<pair<int,int> > ans;
int main() {
    cin>>n>>m;
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)
            cin>>a[i][j];
    for(int i=1;i<n;++i) {
        for(int j=1;j<m;++j) {
            if(a[i][j]&&a[i+1][j]&&a[i][j+1]&&a[i+1][j+1]) {
                b[i][j]=b[i+1][j]=b[i][j+1]=b[i+1][j+1]=1;
                ans.push_back(make_pair(i,j));  
            }
        }
    }
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j) 
            if(a[i][j]!=b[i][j]) return puts("-1"),0;
    printf("%d\n",(int)ans.size());
    for(auto x:ans) printf("%d %d\n",x.first,x.second);
    return 0;
}

C

简单dp

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int _=1e6+7;
ll f[_][2];int s[_];
int main() {
    int T,n,a,b;
    scanf("%d",&T);
    while(T --> 0) {
        scanf("%d%d%d",&n,&a,&b);
        for(int i=1;i<=n;++i) scanf("%1d",&s[i]);
        memset(f,0x3f,sizeof(f));
        f[1][0]=0;
        for(int i=2;i<=n+1;++i) {
            f[i][1]=min(f[i-1][1],f[i-1][0]+a)+b;
            if(!s[i] and !s[i-1])
                f[i][0]=min(f[i-1][0],f[i-1][1]+a);         
        }
        ll ans=f[n+1][0]+1LL*n*a+1LL*(n+1)*b;
        cout<<ans<<"\n";
    }
    return 0;   
}

D

入门容斥。
\(n!-bad_a-bad_b+bad_a&&bad_b\)

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll _=6e5+7,mod=998244353;
ll read() {
    ll x=0,f=1;char s=getchar();
    for(;s>'9'||s<'0';s=getchar()) if(s=='-') f=-1;
    for(;s>='0'&&s<='9';s=getchar()) x=x*10+s-'0';
    return x*f;
}
ll n,jc[_];
struct node {ll a,b;}c[_];
bool operator == (node x,node y) {
    return x.a==y.a&&x.b==y.b;
}
bool cmp1(node x,node y) {
    return x.a==y.a?x.b<y.b:x.a<y.a;
}
bool cmp2(node x,node y) {
    return x.b==y.b?x.a<y.a:x.b<y.b;
}
int main() {
    n=read();
    jc[0]=jc[1]=1;for(ll i=2;i<=n;++i) jc[i]=jc[i-1]*i%mod;
    for(ll i=1;i<=n;++i) c[i].a=read(),c[i].b=read();
    ll bad1=1,bad2=1;
    sort(c+1,c+1+n,cmp1);
    for(ll l=1,r;l<=n;) {
        r=l;while(c[l].a==c[r+1].a&&r+1<=n) r++;
        bad1*=jc[r-l+1],bad1%=mod;
        l=r+1;
    }
    sort(c+1,c+1+n,cmp2);
    for(ll l=1,r;l<=n;) {
        r=l;while(c[l].b==c[r+1].b&&r+1<=n) r++;
        bad2*=jc[r-l+1],bad2%=mod;
        l=r+1;
    }
    ll ans=jc[n]-bad1-bad2;
    ans=(ans%mod+mod)%mod;
    for(ll i=2;i<=n;++i)
        if(c[i-1].a>c[i].a)
            return cout<<ans<<"\n",0;
    ll good=1;
    for(ll l=1,r;l<=n;) {
        r=l;while(c[l]==c[r+1]&&r+1<=n) r++;
        good*=jc[r-l+1],good%=mod;
        l=r+1;
    }
    ans+=good;
    ans=(ans%mod+mod)%mod;
    cout<<ans<<"\n";
    return 0;
}

E

两次确定x的前7位和后七位。

#include <bits/stdc++.h>
using namespace std;
int tmp,ans;
int main() {
    printf("? ");
    for(int i=1;i<=100;++i) printf("%d ",i);
    printf("\n");
    fflush(stdout);
    scanf("%d",&tmp);
    for(int i=7;i<14;++i) if(tmp&(1<<i)) ans|=1<<i;
    printf("? ");
    for(int i=1;i<=100;++i) printf("%d ",i<<7);
    printf("\n");
    fflush(stdout);
    scanf("%d",&tmp);
    for(int i=0;i<7;++i) if(tmp&(1<<i)) ans|=1<<i;
    cout<<"! "<<ans<<"\n";
    return 0;
}

F

分块。
又读错范围了,开了\(long long T\)飞了.
预处理sum[i][j]\(表示\)%i\(余\)j\(的和。 对于模数大于\)\sqrt{n}$的直接暴力跳。

#include <bits/stdc++.h>
#define int long long
#define ll long long
using namespace std;
int read() {
    int x=0,f=1;char s=getchar();
    for(;s>'9'||s<'0';s=getchar()) if(s=='-') f=-1;
    for(;s>='0'&&s<='9';s=getchar()) x=x*10+s-'0';
    return x*f;
}
const int _=5e5+7;
ll n,sum[1000][1000],a[_];
signed main() {
    n=read();
    int dsr=sqrt(500000);
    while(n --> 0) {
        int opt=read(),x=read(),y=read();
        if(opt==1) {
            a[x]+=y;
            for(int i=1;i<=dsr;++i) sum[i][x%i]+=y;
        } else {//%x=y
            if(x>dsr) {
                int ans=0;
                for(int i=y;i<=500000;i+=x) ans+=a[i];
                cout<<ans<<"\n";
            } else {
                cout<<sum[x][y]<<"\n";
            }
        }   
    }
    return 0;
}

转载于:https://www.cnblogs.com/dsrdsr/p/11405992.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值