Educational Codeforces Round 96

A B C D E

英语阅读题。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
inline int read(){
    int f=1,ans=0;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
    return f*ans;
} 
int T,N;
int main(){
    T=read();
    while(T--){
        N=read();bool ff=0;
        for(int i=0;i*7<=N;i++){
            for(int j=0;i*7+j*5<=N;j++){
                int res=N-i*7-j*5;
                if((res%3)==0){
                    printf("%d %d %d\n",res/3,j,i);
                    ff=1;break;
                }
            }if(ff) break;
        }    if(!ff) printf("-1\n");
    }return 0;
}
A
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define int long long
using namespace std;
inline int read(){
    int f=1,ans=0;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
    return f*ans;
} 
const int MAXN=2e5+11;
int T,N,A[MAXN],K;
signed main(){
    T=read();
    while(T--){
        N=read(),K=read();for(int i=1;i<=N;i++) A[i]=read(); 
        sort(A+1,A+N+1);int ans=0;
        for(int i=N-K;i<=N;i++) ans+=A[i];
        printf("%lld\n",ans);
    }
}
B
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
inline int read(){
    int f=1,ans=0;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
    return f*ans;
} 
const int MAXN=2e5+11;
pii Ans[MAXN]; int T,N,tot;
priority_queue<int> que;
int main(){
    T=read();
    while(T--){
    tot=0;while(!que.empty()) que.pop();
    N=read();for(int i=1;i<=N;i++) que.push(i);
    while(que.size()!=1){
        int a=que.top();que.pop();
        int b=que.top();que.pop();
        Ans[++tot].fi=a,Ans[tot].se=b;
        int x=(a+b+1)/2;
        que.push(x);
    } 
    printf("%d\n",que.top());
    for(int i=1;i<=tot;i++) printf("%d %d\n",Ans[i].fi,Ans[i].se);    
    }
    return 0;
}
C
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
inline int read(){
    int f=1,ans=0;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
    return f*ans;
} 
const int MAXN=2e5+11;
int T,N,A[MAXN],F[MAXN]; char str[MAXN];
int main(){
    T=read();
    while(T--){
        N=read();scanf("%s",str+1);F[0]=0;
        for(int i=1;i<=N;i++) A[i]=str[i]-'0';
        int l=1;
        for(int i=2;i<=N;i++){
            if(A[i]!=A[i-1]){
                F[++F[0]]=i-l;
                l=i;
            }
        } F[++F[0]]=N-l+1;l=1;int ans=0;
        for(int i=1;i<=F[0];i++){
            if(i>l) l=i;
            while(l<=F[0]&&F[l]==1) l++;
            if(l==F[0]+1){int res=F[0]-i+1;ans+=(res+1)/2;break;}
            F[l]--;ans++;
        }printf("%d\n",ans);
    }return 0;
}/*
1
6
111010
 
*/
D
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<climits>
#include<bitset>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define int long long
using namespace std;
inline int read(){
    int f=1,ans=0;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
    return f*ans;
}
const int MAXN=2e5+11;
int N;vector<int> vec[31];char S[MAXN],T[MAXN];
int A[MAXN],ps[31];
struct BIT{
    int val[MAXN];
    int lowbit(int x){return x&-x;}
    void Add(int x){for(;x<=N;x+=lowbit(x)){val[x]++;}return;}
    int Query(int x){int res=0;for(;x;x-=lowbit(x)) res+=val[x];return res;}
}bit;
signed main(){
    N=read();scanf("%s",S+1);
    for(int i=1;i<=N;i++) T[i]=S[N-i+1];
    for(int i=1;i<=N;i++) vec[S[i]-'a'].pb(i);
    for(int i=1;i<=N;i++) A[i]=vec[T[i]-'a'][ps[T[i]-'a']++];
    int res=0;for(int i=N;i>=1;i--){
        res+=bit.Query(A[i]),bit.Add(A[i]);
    }
    printf("%lld\n",res);return 0;
}
E

F

为啥 $n\leq 2000$ 啊,自闭了。

考虑手枪有剩余的情况什么时候会出现,一定时在 $l$ 的时刻换。

所以我们设 $f_i$ 表示第 $l_i$ 时必须手枪内至少有 $f_i$ 的子弹,直接转移即可。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<climits>
#include<bitset>
#define int long long
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
inline int read(){
    int f=1,ans=0;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
    return f*ans;
}
const int MAXN=2e3+11;
int f[MAXN],N,Ans,K,L[MAXN],R[MAXN],W[MAXN];
signed main(){
    //freopen("F.in","r",stdin);
    N=read(),K=read();for(int i=1;i<=N;i++) L[i]=read(),R[i]=read(),W[i]=read(),Ans+=W[i];
    for(int i=N;i>=1;i--){
        int res=W[i];if(R[i]==L[i+1]) res+=f[i+1];
        f[i]=max(0ll,res-K*(R[i]-L[i]));
        if(f[i]>K){printf("-1\n");return 0;}
    }
    int res=K;for(int i=1;i<=N;i++){
        if(res<f[i]) Ans+=res,res=K;
        res=(res-W[i]%K+K)%K;
    }printf("%lld\n",Ans);return 0;
}
View Code

G

将位独立后直接状压,每次计算后面的贡献即可。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<climits>
#include<bitset>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
inline int read(){
    int f=1,ans=0;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
    return f*ans;
}
const int MAXN=19;
int N,M,f[1<<MAXN],pre[1<<MAXN],W[MAXN],G[1<<MAXN],vis[MAXN],Sum[1<<MAXN];
vector<int> vec[MAXN];
int Ans[MAXN],g[1<<MAXN];
void print(int Sta){
    if(!Sta) return;
    print(pre[Sta]);int now=Sta^pre[Sta];
    ++Ans[0];for(int i=1;i<=N;i++) if(now&(1<<(i-1))) Ans[i]=Ans[0];
    return;
}
int main(){
    //freopen("G.in","r",stdin);
    N=read(),M=read();
    for(int i=1;i<=M;i++){
        int u=read(),v=read(),w=read();vec[u].pb(v);
        W[u]+=w,W[v]-=w;g[1<<(u-1)]|=(1<<(v-1));
    }
    for(int i=0;i<(1<<N);i++) for(int j=1;j<=N;j++) if(i&(1<<(j-1))) g[i]|=g[(1<<(j-1))];
    for(int i=0;i<(1<<N);i++){
        memset(vis,0,sizeof(vis));for(int j=1;j<=N;j++) if(i&(1<<(j-1))) vis[j]=1,Sum[i]+=W[j];
        for(int j=1;j<=N;j++) if(vis[j]) for(auto v:vec[j]) {if(vis[v]) G[i]=1;}
    }memset(f,127/3,sizeof(f));f[0]=0;
    for(int i=1;i<(1<<N);i++){
        for(int S=i;S;S=(S-1)&i){
            int Now=S^i,New=S;
            if(G[New]||((g[i]& (i^((1<<N)-1)) ))) continue;
            int cur=f[Now]+Sum[((1<<N)-1)^Now];
            if(f[i]>cur) pre[i]=Now,f[i]=cur;
        }
    }print((1<<N)-1);
    for(int i=1;i<=N;i++) printf("%d ",Ans[i]);printf("\n");
    return 0;
}
View Code

 

posted @ 2020-10-12 15:30  siruiyang_sry  阅读(103)  评论(0编辑  收藏  举报