首页 > 其他分享 >CSP模拟17

CSP模拟17

时间:2023-08-10 21:47:31浏览次数:41  
标签:return 17 int long 300010 fa include CSP 模拟

CSP模拟17

T1 弹珠游戏

考虑贪心,枚举右端点,产生贡献的是没有填满的人,所以先让某些人填满是最优的。
优先填满已经填了2个的,再填1个的。方案数就是每次填了相同个数的人数的乘积。

code

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
#define int long long
const int mod=998244353;
int n,ls,f[300010],ans=1;
char s[300010];
vector<int>a1,a2,a3;
signed main(){
    scanf("%lld%s",&n,s);
    for(int i=1;i<=3*n;i++){
        if(s[i-1]=='R') a1.push_back(i);
        if(s[i-1]=='G') a2.push_back(i);
        if(s[i-1]=='B') a3.push_back(i);
    }
    for(int i=0;i<n;i++){
        f[min(a1[i],min(a2[i],a3[i]))]=-1;
        f[max(a1[i],max(a2[i],a3[i]))]=1;
    }
    for(int a=1,b=0,c=0;a<=n*3;a++){
        if(f[a]==-1) b++;
        else if(f[a]==0){
            ans*=b--;
            ans%=mod;
            c++;
        }
        else{
            ans*=c--;
            ans%=mod;
        } 
    }
    for(int i=1;i<=n;i++){
        ans*=i;
        ans%=mod;
    }
    printf("%lld",ans);
    return 0;
}

T2 晚会

使用最大生成树,我们可以发现每三个点都会组成等边三角形或腰比底长的等腰三角形。
从大向小枚举边,两个已经连好的集合每个点都用 1 连接。剩下的点都用 1 连接。

code

#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
#define int long long
int n,m,siz[300010],ans,fa[300010],tot;
struct nod{
    int x,y,z;
}nd[300010];
int find(int x){
    if(x^fa[x]) return fa[x]=find(fa[x]);
    return fa[x];
}
bool cmp(nod x,nod y){
    return x.z>y.z;
}
signed main(){
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=n;i++){
        siz[i]=1;
        fa[i]=i;
    }
    for(int i=1;i<=m;i++){
        scanf("%lld%lld%lld",&nd[i].x,&nd[i].y,&nd[i].z);
    }
    sort(nd+1,nd+m+1,cmp);
    for(int i=1;i<=m;i++){
        if(i^1&&nd[i].z<nd[i-1].z){
            for(int j=i;;j--){
                if(nd[i].z^nd[j].z){
                    break;
                }
                if(find(nd[j].x)==find(nd[j].y)){
                    printf("-1");
                    return 0;
                }
            }
        }
        if(find(nd[i].x)^find(nd[i].y)){
            tot+=siz[find(nd[i].x)]*siz[find(nd[i].y)];
            siz[find(nd[i].x)]+=siz[find(nd[i].y)];
            fa[find(nd[i].y)]=find(nd[i].x);
        }
        ans+=(nd[i].z-nd[i+1].z)*tot;
    }
    ans+=(n*(n-1)>>1)-tot;
    printf("%lld",ans);
    return 0;
}

T3 优美的字符串

DP套DP

T4 选举

回滚莫队和分块

标签:return,17,int,long,300010,fa,include,CSP,模拟
From: https://www.cnblogs.com/muzqingt/p/17621568.html

相关文章

  • LOJ #6039「雅礼集训 2017 Day5」珠宝
    给定\(n\)个物品,第\(i\)个物品有体积\(c_i\),价值\(v_i\)。给定\(K\),对\(1\simK\)的所有\(i\)求大小为\(i\)的背包的最大价值。\(n\leq10^6\),\(K\leq5\times10^4\),\(c_i\leq300\),\(0\leqv_i\leq10^9\),时限\(\text{2.0s}\)。注意到\(c_i\)范......
  • 2023.8.7模拟
    T1DescriptionSolutionCode点击查看T2DescriptionSolutionCode点击查看T3DescriptionSolutionCode点击查看T4抽卡I([THUPC2023决赛]老hu机)link:https://www.luogu.com.cn/problem/P9379Description俺のターン,ドロー!(然后对面就翻开神宣把你拍出去......
  • 【考后总结】8 月 CSP-S 模拟赛 3
    8.10CSP模拟17BohemianRhapsody-QueenIsthisthereallife?Isthisjustfantasy?Caughtinalandslide,noescapefromrealityOpenyoureyes,lookuptotheskiesandseeI'mjustapoorboy,IneednosympathyBecauseI'measycome,eas......
  • 疯狂模拟四V我165分总结
    模拟4总结目录模拟4总结总体上个体上:第一题:第二题没看第三题老师布置的题目:第四题,eZ题目总体上个人感觉这一次做题非常舒服,第一题和第四题都想出来了,只可惜第三题做对了一点(最大值)个体上:第一题:很可惜,tarjan写错了,实际得分是65分......说明算法流程不是很掌握确实tarjan容......
  • CSP模拟-17
    前言仔细想了想,考试的时候其实对正解有些思路,但自己认为正确性有问题,所以没这么写,大寄,考了倒2,呜呜呜┭┮﹏┭┮T1弹珠游戏下面的匹配的含义:\(R\)的匹配指\(G,B\),其中\(R\)为被匹配字母,\(G,B\)为匹配字母;\(G\)的匹配指\(R,B\)以此类推。我们用把每个人现在手里的牌用十......
  • 23 暑假友谊赛 No.4(UKIEPC 2017)
    23暑假友谊赛No.4(UKIEPC2017)ProblemAAlienSunsethh,开始一眼差分,但是写寄了qwq,后来换枚举过了(Orz,但是看学长差分是能做的,我就说嘛,差分肯定能做(说下枚举思路吧,就是把每个区间都存起来,选出自转周期的最大值为\(ma\),然后去枚举\(0\simma\times1825\),每次看......
  • Audition Au 2017音频编辑软件下载和安装教程
    Audition是一款完善的工具集,其中包含用于创建、混合、编辑和复原音频内容的多轨、波形和光谱显示功能。这一强大的音频工作站旨在加快视频制作工作流程和音频修整的速度,并且还提供带有纯净声音的精美混音效果。软件介绍新机载体验为新用户提供了常见任务的一系列指导解决方法,例如......
  • CLO Standalone 7(3D服装设计软件) v7.1.178.42210 (x64)中文永久使用
    CLOStandalone7是一款专业的3D服装设计软件,它为服装设计师和制造商提供了先进的工具和功能,以快速而准确地创建、模拟和可视化服装设计。点击获取CLOStandalone7 CLOStandalone7具有以下主要特点和功能:三维虚拟设计:CLOStandalone7使用先进的三维建模技术,可以在虚拟......
  • UKIEPC 2017
    A-AlienSunset这到题,用一个数组表示当前时间有多少个星球是夜晚,这样就转换成了区间修改单点查询。因为只查询一次,所以用差分即可。#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongconstintm=1825*100+5;int32_tmain(){ios::sync_wi......
  • LeetCode从算法到算命—1749.任意子数组和的绝对值的最大值
    1749.任意子数组和的绝对值的最大值题目信息给你一个整数数组nums。一个子数组[numsl,numsl+1,...,numsr-1,numsr]的和的绝对值为abs(numsl+numsl+1+...+numsr-1+numsr)。请你找出nums中和的绝对值最大的任意子数组(可能为空),并返回该最大值。abs(x)......