Codeforces Round #441 (Div. 1, by Moscow Team Olympiad)

A Classroom Watch

显然sum of digit 不会超过9*9 暴力枚举

#include<bits/stdc++.h> 
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
                        For(j,m-1) cout<<a[i][j]<<' ';\
                        cout<<a[i][m]<<endl; \
                        } 
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
    return x*f;
} 
int main()
{
//  freopen("A.in","r",stdin);
//  freopen(".out","w",stdout);

    int n=read();
    vi v;
    Fork(i,max(n-1000,1),n) {
        ll p=i,q=0;
        while(p) q+=p%10,p/=10;
        if (q+i==n) v.pb(i);
    }
    sort(ALL(v));
    cout<<SI(v)<<endl;
    Rep(i,SI(v)) cout<<v[i]<<endl;
    return 0;
}

B Sorting the Coins

冒泡排序每次都能冒泡一个数

#include<bits/stdc++.h> 
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
                        For(j,m-1) cout<<a[i][j]<<' ';\
                        cout<<a[i][m]<<endl; \
                        } 
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
    return x*f;
} 
ll a[312345];

int main()
{
    freopen("B.in","r",stdin);
//  freopen(".out","w",stdout);
    int n=read();
    MEM(a)
    putchar('1');
    int l=n+1,r=n;
    For(i,n) {
        int p=read();
        gmin(l,p)
        while(a[r]) --r;
        cout<<' '<<r-l+1-i;
    }


    return 0;
}

C National Property

2-sat 模型很明显了

#include<bits/stdc++.h> 
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
                        For(j,m-1) cout<<a[i][j]<<' ';\
                        cout<<a[i][m]<<endl; \
                        } 
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
    return x*f;
} 
#define MAXN (200000+10)
int cnt[MAXN]={},l[MAXN]={},r[MAXN]={};
int a[MAXN]={};
bool fl=1;
int cap[MAXN]={};
class SSC  
{  
public:  
    int n,b[MAXN],num[MAXN];  
    vector<int> G[MAXN],rG[MAXN]; //ͼ£¬·´ÏòºóµÄͼ   
    vector<int> vs; //ºóÐø±éÀú¶¥µãÁÐ±í   
    void mem(int _n)  
    {  
        n=_n; MEM(num)  
        For(i,n) G[i].clear(),rG[i].clear();  
        vs.clear();  
    }  
    void addedge(int u,int v)  
    {  
        G[u].push_back(v);  
        rG[v].push_back(u);  
    }  
    void dfs(int x)  
    {  
        b[x]=1;  
        Rep(i,G[x].size())  
        {  
            if (!b[G[x][i]]) dfs(G[x][i]);  
        }  
        vs.push_back(x);  
    }  
    void rdfs(int x,int k)  
    {  
        b[x]=1;num[x]=k;  
        Rep(i,rG[x].size())  
        {  
            if (!b[rG[x][i]]) rdfs(rG[x][i],k);  
        }  
    }  
    int ssc()  
    {  
        MEM(b)   
        For(i,n) if (!b[i]) dfs(i);  
        MEM(b) int k=0;  
        RepD(i,vs.size()-1) if (!b[vs[i]]) rdfs(vs[i],++k);  
        return k;  
    }  

};  
class Two_Sat //(a||!b)&&(c||b)&&...
{
public:
    int n;
    SSC S;  //1..n
    void mem(int _n)
    {
        n=_n;
        S.mem(2*n);
    }
    int no(int u){if (u>0) return u;else return n-u; }
    void addedge(int u,int v) //((b¡Å ~c) : b -c
    {
        S.addedge(no(-u),no(v));
        S.addedge(no(-v),no(u));
    }
    bool work(vi &v) {
        S.ssc();
        For(i,n) {
            if (S.num[i]==S.num[i+n]) return 0;
            else if (S.num[i]>S.num[i+n]) v.pb(i);
        }
        return 1;
    }
}S;

void check(int l,int r){
    while(a[l]&&a[r]) {
        if (a[l]!=a[r]) {
            if (a[l]<a[r]) S.addedge(-a[r],a[l]);
            if (a[l]>a[r]) S.addedge(a[l],a[l]),S.addedge(-a[r],-a[r]);
            return;
        }
        ++l,++r;
    }
    if (a[l]&&!a[r]) {
        fl=0;return ;
    }
}
int main()
{
//  freopen("C.in","r",stdin);
//  freopen(".out","w",stdout);
    int n=read(),m=read();
    S.mem(m);
    l[0]=r[0]=0;
    For(i,n) {
        cnt[i]=read();
        l[i]=r[i-1]+1;
        r[i]=l[i];
        For(j,cnt[i]) {
            a[r[i]++]=read();
        }
        a[r[i]]=0;
    }
    For(i,n-1) {
        check(l[i],l[i+1]);
    }
    vi v;
    if (!fl|| !S.work(v)) puts("No");
    else {
        puts("Yes");
        int sz=SI(v);
        printf("%d\n",sz);
        if (sz) {
            printf("%d\n",v[0]);
            For(i,sz-1) printf(" %d",v[i]);
        }
    }
    return 0;
}

D High Cry

给一个数列,问有多少子串满足or和>max值

枚举左端点,or值最多有Log(Ai)个,可以暴力在每段2分。

E Delivery Club

F Royal Questions

10w点2分图带权匹配,注意某一边点度数均为2。

题目可以转化为,最大环加外向树生成树,类似MST。

#include<bits/stdc++.h> 
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
                        For(j,m-1) cout<<a[i][j]<<' ';\
                        cout<<a[i][m]<<endl; \
                        } 
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
    return x*f;
} 
#define MAXN (200100)
int fa[MAXN],s[MAXN];
int getfa(int x) {return (fa[x]==x)?x:(fa[x]=getfa(fa[x]));}
pair< int ,pi > p[MAXN];
int main()
{
//  freopen("F.in","r",stdin);
//  freopen(".out","w",stdout);
    int n=read(),m=read();
    For(i,n) fa[i]=i;
    For(i,m) p[i].se.fi=read(),p[i].se.se=read(),p[i].fi=read();
    sort(p+1,p+1+m);
    int ans=0;
    ForD(i,m) {
        int x=p[i].se.fi,y=p[i].se.se,w=p[i].fi;
        x=getfa(x),y=getfa(y);
        if( (x^y) && (!s[y]||!s[x]) ) {
            fa[x]=y;
            s[y]+=s[x];
            ans+=w;
        } else if (!s[x]){
            ans+=w;
            s[x]=1;
        }
    }
    cout<<ans<<endl;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值