Codeforces Round #589 (Div. 2)【数学 + 构造】

2023-11-06

A题 Distinct Digits


  因为数的大小最长也就是5位,所以直接暴力求解即可,复杂度O(5 * N)。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define lowbit(x) ( x&( -x) )
#define pi 3.141592653589793
#define e 2.718281828459045
#define INF 0x3f3f3f3f
#define efs 1e-7
#define HalF (l + r)>>1
#define lsn rt<<1
#define rsn rt<<1|1
#define Lson lsn, l, mid
#define Rson rsn, mid+1, r
#define QL Lson, ql, qr
#define QR Rson, ql, qr
#define myself rt, l, r
#define MP(a, b) make_pair(a, b)
using namespace std;
typedef unsigned long long ull;
typedef unsigned int uit;
typedef long long ll;
int x, y;
bool check(int val)
{
    bool vis[10] = {false};
    int tmp;
    while(val)
    {
        tmp = val % 10;
        if(vis[tmp]) return false;
        vis[tmp] = true;
        val /= 10;
    }
    return true;
}
int main()
{
    scanf("%d%d", &x, &y);
    for(int i=x; i<=y; i++)
    {
        if(check(i))
        {
            printf("%d\n", i);
            return 0;
        }
    }
    printf("-1\n");
    return 0;
}

 

B题 Filling the Grid


  直接判断哪些格子被固定了,需要判断哪些格子置黑与强制为白的冲突性,因为那会决定答案的存在性。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define lowbit(x) ( x&( -x) )
#define pi 3.141592653589793
#define e 2.718281828459045
#define INF 0x3f3f3f3f
#define efs 1e-7
#define HalF (l + r)>>1
#define lsn rt<<1
#define rsn rt<<1|1
#define Lson lsn, l, mid
#define Rson rsn, mid+1, r
#define QL Lson, ql, qr
#define QR Rson, ql, qr
#define myself rt, l, r
#define MP(a, b) make_pair(a, b)
using namespace std;
typedef unsigned long long ull;
typedef unsigned int uit;
typedef long long ll;
const int maxN = 1e3 + 7;
const ll mod = 1e9 + 7;
int vis[maxN][maxN] = {0};
int N, M;
ll jc[maxN * maxN];
inline ll fast_mi(ll a, int b)
{
    ll ans = 1LL;
    while(b)
    {
        if(b & 1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
ll solve(int val)
{
    ll ans = 0;
    for(int i=0; i<=val; i++)
    {
        ans = (ans + jc[val] * fast_mi(jc[i], mod - 2) % mod * fast_mi(jc[val - i], mod - 2) % mod) % mod;
    }
    return ans;
}
int main()
{
    jc[0] = jc[1] = 1;
    for(int i=2; i<=1e6; i++) jc[i] = jc[i-1] * i % mod;
    scanf("%d%d", &N, &M);
    for(int i=1, r, j; i<=N; i++)
    {
        scanf("%d", &r);
        for(j=1; j<=r; j++) vis[i][j] = 1;
        vis[i][j] = -1;
    }
    bool flag = true;
    for(int i=1, w, j; i<=M; i++)
    {
        scanf("%d", &w);
        for(j=1; j<=w; j++)
        {
            if(vis[j][i] == -1) flag = false;
            vis[j][i] = 1;
        }
        if(vis[j][i] == 1) flag = false;
        vis[j][i] = -1;
    }
//    for(int i=1; i<=N; i++)
//    {
//        for(int j=1; j<=M; j++)
//        {
//            printf("%d ", vis[i][j]);
//        }
//        printf("\n");
//    }
    if(!flag)
    {
        printf("0\n");
        return 0;
    }
    int sum = 0;
    for(int i=1; i<=N; i++) for(int j=1; j<=M; j++) sum += (vis[i][j] ? 0 : 1);
    printf("%lld\n", solve(sum));
    return 0;
}

 

C题 Primes and Multiplication


  直接求质数对原数产生的贡献即可。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define lowbit(x) ( x&( -x) )
#define pi 3.141592653589793
#define e 2.718281828459045
#define INF 0x3f3f3f3f
#define efs 1e-7
#define HalF (l + r)>>1
#define lsn rt<<1
#define rsn rt<<1|1
#define Lson lsn, l, mid
#define Rson rsn, mid+1, r
#define QL Lson, ql, qr
#define QR Rson, ql, qr
#define myself rt, l, r
#define MP(a, b) make_pair(a, b)
using namespace std;
typedef unsigned long long ull;
typedef unsigned int uit;
typedef long long ll;
const int maxN = 1e6 + 7;
const ll mod = 1e9 + 7;
bool Prime[maxN] = {false};
int inque[maxN], cnt = 0;
ll X, N;
vector<ll> vt;
inline ll fast_mi(ll a, ll b)
{
    ll ans = 1LL;
    while(b)
    {
        if(b & 1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
inline void pre_did()
{
    for(int i=2; i<=1e6; i++)
    {
        if(!Prime[i])
        {
            inque[++cnt] = i;
            for(int j = 2 * i; j <= 1e6; j += i) Prime[j] = true;
        }
    }
}
int main()
{
    pre_did();
    scanf("%lld%lld", &X, &N);
    for(int i=1; i<=cnt; i++)
    {
        if(X % inque[i] == 0)
        {
            vt.push_back(inque[i]);
            while(X % inque[i] == 0) X /= inque[i];
        }
    }
    if(X ^ 1) vt.push_back(X);
    int len = (int)vt.size();
    ll tmp1, tmp2, cop, ans = 1LL;
    for(int i=0; i<len; i++)
    {
        tmp1 = tmp2 = 0;
        cop = N;
        while(cop)
        {
            tmp1 = cop / vt[i];
            cop /= vt[i];
            tmp2 += tmp1;
        }
        ll _get = fast_mi(vt[i], tmp2);
        ans = ans * _get % mod;
    }
    printf("%lld\n", ans);
    return 0;
}

 

D题 Complete Tripartite


  开虚拟的时候唯独没有想全的题了,具体思维

  首先,我们不是所有的边都是需要的,尤其是我们指向下一个节点的时候,我们可以小的结点去指向大的结点,并且固定如此,让一开始所有的结点都在集合1中,然后呢,我们从1号结点开始进行处理,所有的有链接的且在同一个集合中的点,我们对于序号大的点放进一个更大的集合中去,保证了题目中的所要的要求了。

  但是,我们尽管这样做了之后,可以保证每个集合内的点是互相之间没有边链接的,但是呢(亲测,WA10),我们现在还是没有保证集合中的各点到除了自己之外的集合中的各点都有一条边链接。

  这样,我们还要处理第二条规则,首先可以看到,两个点之所以不在一个集合,是因为他们之间是有边相连接的,所以在这里,利用这条规则,我们只需要去判断一下,1号集合与2号集合的总的边的数量、1号集合与3号集合的总的边的数量、2号集合与3号集合的总的边的数量的总和是不是等于M即可。等于M,表示了每条边都用上了,保证了题目中的要求。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define lowbit(x) ( x&( -x) )
#define pi 3.141592653589793
#define e 2.718281828459045
#define INF 0x3f3f3f3f
#define efs 1e-7
#define HalF (l + r)>>1
#define lsn rt<<1
#define rsn rt<<1|1
#define Lson lsn, l, mid
#define Rson rsn, mid+1, r
#define QL Lson, ql, qr
#define QR Rson, ql, qr
#define myself rt, l, r
#define MP(a, b) make_pair(a, b)
using namespace std;
typedef unsigned long long ull;
typedef unsigned int uit;
typedef long long ll;
const int maxN = 1e5 + 7;
int N, M, team[maxN] = {0}, head[maxN], cnt, tot, op[4] = {0};
struct Eddge
{
    int nex, to;
    Eddge(int a=-1, int b=0):nex(a), to(b) {}
}edge[600007];
inline void addEddge(int u, int v)
{
    if(u > v) return;
    edge[cnt] = Eddge(head[u], v);
    head[u] = cnt++;
}
inline void _add(int u, int v) { addEddge(u, v); addEddge(v, u); }
inline void init()
{
    cnt = 0; tot = 1;
    for(int i=1; i<=N; i++) head[i] = -1;
    for(int i=1; i<=N; i++) team[i] = 1;
}
int main()
{
    scanf("%d%d", &N, &M);
    init();
    for(int i=1, u, v; i<=M; i++)
    {
        scanf("%d%d", &u, &v);
        _add(u, v);
    }
    for(int u=1; u<=N; u++)
    {
        for(int i=head[u], v; ~i; i=edge[i].nex)
        {
            v = edge[i].to;
            if(team[v] == team[u]) team[v]++;
            tot = max(tot, team[v]);
        }
    }
    if(tot == 3)
    {
        for(int i=1; i<=N; i++) op[team[i]]++;
        if((op[1] * op[2] + op[1] * op[3] + op[2] * op[3]) ^ M) { printf("-1\n"); return 0; }
        for(int i=1; i<=N; i++) printf("%d ", team[i]);
        printf("\n");
    }
    else printf("-1\n");
    return 0;
}

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Codeforces Round #589 (Div. 2)【数学 + 构造】 的相关文章

  • Codeforces Round #706 (Div. 2)

    代码 xff1a span class token macro property span class token directive keyword include span span class token string lt iost
  • Codeforces Round #841 (Div. 2)

    B Kill Demodogs 分析 显然要选择和两斜线的元素相加 所以答案可以表示为 xff1a 即 xff1a 根据公式 得答案为 但答案不能直接得这个 因为n的范围为1e9 xff0c 而ull的范围为1e20 xff0c 答案的第一
  • Educational Codeforces Round 141 Editorial C~D

    1783C Yet Another Tournament 分析 正解思路是贪心 开始自己也想的贪心 xff1a 首先显然打败的人数越多越好 xff0c 然后选择权值最小的人打败 这个思路前半部分没问题 xff0c 后半部分过不了样例的第二个
  • Codeforces Round 857 (Div. 1 + Div. 2) 2A - 2D

    A Likes 分析 首先数据保证了一定合法 xff0c 那只需要统计有几个负数 最大的策略是先把所有正数用完 xff0c 然后把所有负数用完 xff0c 可知答案一定是1 2 3 4 5 4 3这种形式 xff1b 最小策略是加一个就直接
  • C. Good String Codeforces Round #560 (Div. 3)

    C Good String time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outp
  • Codeforces Round #779 (Div. 2)-D2 - 388535 (Hard Version)

    传送门 xff1a https codeforces com contest 1658 problem D2 思路 xff1a 字典树 首先答案res一定位于 a i l 之中 xff0c 那么可以通过遍历 a i l 来求得res 但直接
  • 【codeforces】Round #604 (Div. 2)(A. B.)

    Codeforces Round 604 Div 2 xff1a http codeforces com contest 1265 目录 A Beautiful String链接题意思路AC代码 B Beautiful Numbers链接题
  • Educational Codeforces Round 84 题解

    Educational Codeforces Round 84 题解 A Sum of Odd Integers 题意 xff1a n n n 是否能表示为 k k k 个不同的正奇
  • codeforces 1330 C.D.题解

    codeforces 1330 C D 题解 Dreamoon Likes Coloring 题意 xff1a 给 n lt 61 100000 n lt 61 100000 n lt 61
  • codeforces Round680 C. Division 题解

    codeforces Round680 C Division 题解 题目 Oleg s favorite subjects are History and Math and his favorite branch of mathematic
  • 1500*C. Tenzing and Balls (线性DP)

    解析 每次选择两个相同的数 删去他们以及他们之间的所有数 问最多可以删除多少 DP 对于某个位置 i 其前面有多个 j 使得 a i a j 所以使用 f i 来记录前 i 个数能够删除的最大值 include
  • codeforces 950 #469 div2 D A Leapfrog in the Array

    Problem codeforces com contest 950 problem D Reference Codeforces Round 469 Div 2 D A Leapfrog in the Array 思维 Meaning 开
  • Catowice City【Codeforces 1248 F】【Tarjan】

    Codeforces Round 594 Div 2 F 这道题的解法还真是不少 写了个枚举也可以做这道题 当然Tarjan自然也是可以的 我一开始没捋清楚思路 再想想 发现 我们看到审判者 他们都会指向一些参赛选手 那么我们是不是可以尽力
  • Petya and Exam【Codeforces 1282 C】【贪心】

    Codeforces Round 610 Div 2 C 有N道题目 题目有简单与困难之分 简单的题目花费A分钟 困难的题目花费B分钟 那么考试时间一共有T的情况下 我们是可以提前交卷的 但是有些时间限制 就是譬如说你现在第x分钟交卷 但是
  • 1200*C. Stripe

    题意翻译 给定一整数n 下面有n个数a i 求将该数列分割成两个非空数列且两个数列内数字的和相等的方案数 1 lt n lt 10 5 a i 的绝对值不大于10000 解析 前缀和 include
  • 1200*A. You‘re Given a String...(枚举)

    include
  • 1500*B. The Walkway(贪心&规律)

    解析 把每个区间段分成左闭右开区间 我们可以观察到 每个区间的饼干数量为 r l d 上取整 所以先计算不删除某个点的饼干总和init 然后遍历所有点 将这个点删除 所以删除某个点后剩余数量为 找出最小值并且统计数量 需要注意的是 因为如果
  • 1600*C. Binary String Copying

    https codeforces com problemset problem 1849 C Binary String Copying 洛谷 解析 对于某个区间x y 他排序之后 最左侧的连续0和最右侧的连续1是不影响排序结果的 假设左侧
  • 【前后缀 + 推公式整理】 Codeforces Round #813 (Div. 2) D. Empty Graph

    题意 给定 n n n 个点的点权 a i a i ai 这 n
  • Codeforces Round #561 (Div. 2)ABC

    三个题 各位大佬别喷我 我很菜 A Silent Classroom There are n students in the first grade of Nlogonia high school The principal wishes

随机推荐

  • VMware Workstation 17 Pro的下载&&安装&&使用

    目录 一 下载 二 安装 三 检查网络连接 方式一 简便版 方式二 麻烦版 四 使用 创建虚拟机 使用命令 快照的使用 拍摄快照 恢复快照 克隆虚拟机 移除虚拟机 一 下载 下载地址 Windows 虚拟机 Workstation Pro
  • 14-堆排序

    堆 Heap 是一种常见的数据结构 常用于存储数据 其本质上是一棵完全二叉树 下面我们来看看如何用数组实现堆结构及其相关功能 堆的定义 首先来看一下堆的存储结构 堆可以看成是一颗完全二叉树 首先什么是二叉树 借助百度中的解释 二叉树 bin
  • arXiv是个什么东西?

    arXiv只是个提交论文预印本 preprint 的平台 而且里面的论文都没有经过同行评审 peer review 所以文章质量参差不齐 比较有名的计算机检索数据库DBLP数据库可以检索arXiv里的文章 DBLP把arXiv归类为非正式发
  • opencv 学习:reshape函数

    在opencv中 reshape函数比较有意思 它既可以改变矩阵的通道数 又可以对矩阵元素进行序列化 非常有用的一个函数 函数原型 C Mat Mat reshape int cn int rows 0 const 参数比较少 但设置的时候
  • BUAA_C程序括号匹配检查

    问题描述 编写一程序检查C源程序文件中 等括号是否匹配 并输出第一个检测到的不匹配的括号及所对应括号所在的行号 程序中只有一个括号不匹配 注意 1 除了括号可能不匹配外 输入的C源程序无其它语法错误 2 字符常量 字符串常量及注释中括号不应
  • 基于近半年Twitter与Github趋势分析_12大分类500+ChatGPT最新开源GitHub存储库(涵盖ChatGPT开发全框架、全编程语言及教程)——每周更新

    目录 前言 令人惊叹的开源ChatGPT资源 Awesome lists 提示工程 聊天机器人 浏览器扩展及插件 CLIs命令行界面标准应用程序 Reimplementations重实现模型 教程 NLP自然语言处理 Langchain U
  • Vue-自定义指令

    Vue 自定义指令 1 什么是自定义指令 vue 官方提供了 v text v for v model v if 等常用的指令 除此之外vue 还允许开发者自定义指令 2 自定义指令的分类 私有自定义指令 在每个vue 组件中 可以在dir
  • Safari开发者工具

    Safari开发者工具 1 开发者功能 2 开发者功能可以干什么 2 1 捕获模拟器的请求 1 开发者功能 Safari gt 首选项 gt 高级 gt 开启 在菜单栏中显示 开发 菜单 2 开发者功能可以干什么 2 1 捕获模拟器的请求
  • Android 自定义View :虚线矩形

    预览效果 涉及参数 斜线起点坐标 斜线可以忽略 斜线终点坐标 斜线可以忽略 矩形左上角坐标 矩形右下角坐标 其中 前两个参数用于绘制预览效果中矩形上方的斜线 如果不需要可以移除 本案例涉及视频外一个点指向视频内某块区域 因此参数略微复杂 除
  • CMD 命令换行

    CMD 命令换行 在执行较长的 cmd 命令或制作 cmd 命令脚本时 为了方便编写和阅读 有时需要在命令中加入适当的换行 基于不同的命令 有两种换行方式 普通命令 在要换行的地方输入 然后回车 再继续命令的输入 控制命令 如 if for
  • 如何使实时数据采集处理系统保持数据的高速传输

    如何使实时数据采集处理系统保持数据的高速传输 1引言 当前 越来越多的设计应用领域要求具有高精度的A D转换和实时处理功能 在实时数据采集处理系统设计中 一般需要考虑数据采集以及对采集数据的处理 而对于大数据量的实时数据采集处理系统来说 保
  • Linux服务器Java输出文件中文乱码

    使用下面语句查看编码 String encoding System getProperty file encoding 结果输出 ANSI X3 4 1968 从而导致中文乱码通过 locale 查看服务器系统编码 需要修改 1在tomca
  • 【论文阅读笔记】BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding

    BERT的出现使我们终于可以在一个大数据集上训练号一个深的神经网络 应用在很多NLP应用上面 BERT Pre training of Deep Bidirectional Transformers for Language Underst
  • css实现容器高度 适应 屏幕高度

    元素的高度默认是auto 被内容自动撑开 100 使得html的height与屏幕的高度相等 50 使得html的height等于屏幕的一半 若想让一个 div 的高度与屏幕高度自适应 始终充满屏幕 需要从html层开始层层添加height
  • 文本生成评估指标:ROUGE、BLEU详谈

    目录 1 自动摘要与机器翻译 1 自动摘要和机器翻译的定义和目标 2 自动摘要和机器翻译领域的挑战 2 ROUGE Recall Oriented Understudy for Gisting Evaluation 1 ROUGE 的目的和
  • AI虚拟点读机--详细注释解析恩培作品7

    感谢恩培大佬对项目进行了完整的实现 并将代码进行开源 供大家交流学习 一 项目简介 本项目最终达到的效果为手势控制虚拟点读机 如下所示 项目用python实现 调用opencv等库 使用SVM对字体进行分类 由以下步骤组成 1 使用Open
  • cd命令、pwd命令和环境变量PWD、OLDPWD的关联

    1 cd命令 cd命令这里不多介绍 cd 命令是返回上次所在的目录 2 PWD和OLDPWD环境变量 dai ubuntu env PWD home dai OLDPWD dai ubuntu 3 关联 1 当你输入 cd 命令返回上次的目
  • R语言之匹配篇

    2019独角兽企业重金招聘Python工程师标准 gt gt gt match match函数的声明如下 match x table nomatch NA integer incomparables NULL x 向量 要匹配的值 tabl
  • 深入MTK平台bootloader启动之【 Pre-loader -> Lk】分析笔记

    1 bootloader到kernel启动总逻辑流程图 ARM架构中 EL0 EL1是必须实现 EL2 EL3是选配 ELx跟层级对应关系 EL0 app EL1 Linux kernel lk EL2 hypervisor 虚拟化 EL3
  • Codeforces Round #589 (Div. 2)【数学 + 构造】

    A题 Distinct Digits 因为数的大小最长也就是5位 所以直接暴力求解即可 复杂度O 5 N include