Codeforces Round 918 (Div. 4)

目录

A. Odd One Out

B. Not Quite Latin Square

C. Can I Square?

D. Unnatural Language Processing

E. Romantic Glasses

F. Greetings

G. Bicycles


A. Odd One Out


直接简单检查一下即可

void solve()
{
    int a,b,c; cin>>a>>b>>c;
    if(a==b) cout<

B. Not Quite Latin Square


直接暴力找缺少的是谁即可

void solve()
{
    n=3;
    int now=0;

    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++){
            cin>>s[i][j];   
            if(s[i][j]=='?') now=i;
        } 

    map mp;  
    for(int j=1;j<=n;j++)
        mp[s[now][j]]++;

    string res="ABC";
    for(auto&v:res)
        if(!mp.count(v)) cout<

C. Can I Square?


平方数直接用sqrt检查即可

void solve()
{
    cin>>n;
    LL res=0;
    while(n--){
        int x; cin>>x;
        res+=x;
    }    
    LL a=sqrt(res);
    cout<<(a*a==res ? "YES" : "NO")<

D. Unnatural Language Processing


依照题意直接模拟即可

void solve()
{
    mp['b']=mp['c']=mp['d']=1;
    mp['a']=mp['e']=2;    

    cin>>n;
    string s; cin>>s;
    for(int i=0;i

E. Romantic Glasses


判断中间某一段是否具有特性可以直接从前后来找特性注意完整的从前面和从后面

void solve()
{
    cin>>n;
    map cnt;

    for(int i=1;i<=n;i++){
        cin>>w[i];
        a[i]=a[i-1];
        if(i&1) a[i]+=w[i];
        else a[i]-=w[i];
        cnt[a[i]]++;

    }



    LL ans=a[n],res=0;
    if(!ans){
        cout<<"YES"<=1;i--){
        cnt[a[i]]--;
        if(i&1) res+=w[i];
        else res-=w[i];
        if(cnt[ans-res]>1){
            cout<<"YES"<

F. Greetings


注意到是明显的二维偏序问题所以我们直接使用树状数组+离散化即可

struct code{
    int x,y;
    bool operator<(const code&t)const{
        return y>n;
    vector a;
    for(int i=1;i<=n;i++) tr[i]=0;

    for(int i=1;i<=n;i++){
        int x,y; cin>>x>>y;
        e[i]={x,y};
        a.push_back(x);
    }    

    sort(a.begin(),a.end());
    sort(e+1,e+1+n);

    for(int i=1;i<=n;i++){
        auto [x,y]=e[i];
    }
    auto find = [&](int x){
        return lower_bound(a.begin(),a.end(),x)-a.begin()+1;
    };

    LL res=0;

    for(int i=1;i<=n;i++){
        auto [x,y]=e[i];
        res+=query(n)-query(find(x));
        add(find(x));
    }
    cout<

G. Bicycles


明显的分层图直接跑一遍dijkstra即可

LL d[M][M];
int w[M];
bool st[M][M];
vector g[N];

void solve()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        g[i].clear();
        for(int j=1;j>a>>b>>c;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }    

    for(int i=1;i<=n;i++) cin>>w[i];

    auto dijkstra = [&](){
        d[1][w[1]]=0;
        priority_queue,greater> q;
        q.emplace(0,w[1],1);
        while(!q.empty()){
            auto [dist,v,u]=q.top(); q.pop();
            if(st[u][v]) continue;
            st[u][v]=true;
            for(auto&[b,c]:g[u]){
                if(d[b][v]>dist+v*c){
                    d[b][v]=dist+v*c;
                    q.emplace(d[b][v],min(v,w[b]),b);
                }
            }
        } 
        LL ans=2e18;
        for(int i=1;i

你可能感兴趣的:(div4,算法)