题目链接

A  The Third Three Number Problem

题意

给你一个n,让你求满足的a,b,c。

如果不存在则输出-1.

思路

显然任意a,b,c是不可能得到奇数。

只考虑偶数可以得到一个特殊构造 n/2 , 0 , 0 。

代码

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
const ll N = 1e6;
void solve()
{
int n;
cin >> n;
if (n % 2 == 1)
cout << "-1\n";
else
cout << n / 2 << " 0 0\n";
} int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--)
solve();
return 0;
}

B - Almost Ternary Matrix

题意

构造01矩阵,要求每个数的上下左右最多有两个数相同。

思路

以这个图案  为基本构造单元进行扩展,再根据题意所给的范围截出需要的图案。

代码

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
const ll N = 1e6;
int s[10][65];
void solve()
{
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
cout << s[i % 4][j] << " ";
cout << endl;
}
} int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
s[1][1] = 1, s[1][2] = 0, s[1][3] = 0, s[1][4] = 1;
s[1][0] = 1;
s[2][1] = 0, s[2][2] = 1, s[2][3] = 1, s[2][4] = 0;
s[2][0] = 0;
for (int i = 1; i <= 60; i++)
{
s[0][i] = s[1][i % 4];
s[1][i] = s[1][i % 4];
s[2][i] = s[2][i % 4];
s[3][i] = s[2][i % 4];
}
int t;
cin >> t;
while (t--)
solve();
return 0;
}

C - The Third Problem

题意

给一个长为n的数组a,内容是0到n-1。定义一个操作MEX为集合c1,c2,.....,ck  中没有出现的最小非负数。

例如

让你求一个数组b,内容也是0到n-1。对任意 都有

思路

设是s[x]为 x 在a 中的位置

首先考虑0的位置,因为MEX[0]=1,所以0的位置只能是s[0],可以确定1的位置为s[1]。

接下来确定 2~n-1的方法相同,以 0 和 1 的索引确定区间 [L, R],如果下一个 数x 的索在入区间 [L, R],则更新ans为((区间长度)-(x-1))*ans, 如果 k 的索引位于区间之外则更新L或R增加区间长度。

代码

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
const ll N = 1e5, mod = 1e9 + 7;
void solve()
{
int n;
cin >> n;
int sf[n];
vector<int> s(n);
for (int i = 0; i < n; i++)
{
cin >> sf[i];
s[sf[i]] = i;
}
int l = s[0], r = s[0];
ll ans = 1;
for (int i = 1; i < n; i++)
{
if (s[i] > r)
r = s[i];
else if (s[i] < l)
l = s[i];
else
ans = ans * (r - l + 1 - i) % mod;
}
cout << ans << endl;
} int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--)
solve();
return 0;
}

Codeforces Round #804 (Div. 2)的更多相关文章

  1. Codeforces Round #804 (Div. 2) C(组合 + mex)

    Codeforces Round #804 (Div. 2) C(组合 + mex) 本萌新的第一篇题解qwq 题目链接: 传送门QAQ 题意: 给定一个\(\left [0,n-1 \right ] ...

  2. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  3. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  4. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  5. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  6. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  7. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  8. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  9. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

随机推荐

  1. 罗马数字转整数,Java执行时间超过100%用户的写法

    执行用时:2 ms, 在所有 Java 提交中击败了100.00%的用户 题目 https://leetcode-cn.com/problems/roman-to-integer 罗马数字包含以下七种 ...

  2. 理解ASP.NET Core - 授权(Authorization)

    注:本文隶属于<理解ASP.NET Core>系列文章,请查看置顶博客或点击此处查看全文目录 之前,我们已经了解了ASP.NET Core中的身份认证,现在,我们来聊一下授权. 老规矩,示 ...

  3. 论文解读(GCC)《Graph Contrastive Clustering》

    论文信息 论文标题:Graph Contrastive Clustering论文作者:Huasong Zhong, Jianlong Wu, Chong Chen, Jianqiang Huang, ...

  4. AspNetCore配置多环境log4net配置文件

    前言 在之前的文章中有讲到AspNetCore多环境配置文件的应用,我们根据自己多种环境分别配置多个appsettings.$EnvironmentName.json文件. 在实际的开发中我们可能会遇 ...

  5. CV技术指南免费版知识星球

    ​ 最近公众号的交流群满了,我们决定搞一个免费的知识星球,让大家在里面交流.以往都是我们写原创,大家阅读,读者之间没什么交流.与此同时,在CV技术指南交流群里,大部分问题都得到了很好地解决,但从来没有 ...

  6. Linux下快速拷贝单个大文件的秘诀

    #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <stdlib.h> ...

  7. 微信小程序绑定函数如何携带参数

    一开始以为微信小程序的语法是和VUE的语法一样的,直接@click="click(field)",结果却不是这样的 在微信小程序中我们需要设置一个 data-set ,然后在绑定的 ...

  8. systemd进程管理工具实战教程

    关注「开源Linux」,选择"设为星标" 回复「学习」,有我为您特别筛选的学习资料~ 1. systemd介绍 systemd是目前Linux系统上主要的系统守护进程管理工具,由于 ...

  9. Redis源码漂流记(二)-搭建Redis调试环境

    Redis源码漂流记(二)-搭建Redis调试环境 一.目标 搭建Redis调试环境 简要理解Redis命令运转流程 二.前提 1.有一些c知识简单基础(变量命名.常用数据类型.指针等) 可以参考这篇 ...

  10. apache tomcat 目录session应用信息漏洞

    Tomcat 是一款开源的 Web 应用服务器软件.Tomcat 属于轻量级应用服务器,在中小型系统和并发访问用户不多的场合下被普遍使用,是开发和调试 JSP 程序的首选. 漏洞描述 apache T ...