题目链接

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. Oracle with使用方法以及递归

    数据准备 表结构 -- 部门表 CREATE TABLE DEPT ( dept_no VARCHAR2(5) NOT NULL, dept_name VARCHAR2(255) NOT NULL, ...

  2. docker:registry

    存放docker镜像(mage)的地址,可供人上传下载镜像包: 下载 docker search whalesay --搜索whalesay镜像,该镜像用命令行的形式画了个鲸鱼并说了句话 docker ...

  3. Java面试题资料合集

    Java面试题资料合集 2021年最新版--Java+最常见的+200++面试题汇总+答案总结汇总.pdf BIO,NIO,AIO,Netty面试题 35道.pdf Dubbo面试题 47道.pdf ...

  4. XCTF练习题---MISC---glance-50

    XCTF练习题---MISC---glance-50 flag:TWCTF{Bliss by Charles O'Rear} 解题步骤: 1.观察题目,下载附件 2.下载完成以后,隐隐约约像是一张动图 ...

  5. .Net Core Razor动态菜单实现

    准备 1.框架 .netcore  版本 yishaadmin开源框架 2.模板 本文模板使用adminlte3.0,文档地址https://adminlte.io/docs/3.0/ 3.菜单表 关 ...

  6. 1.SSH协议学习笔记

    一.SSH介绍 介绍: SSH全称是Secure Shell,安全外壳协议. 端口号:22: 如何查看服务端口号: grep ssh /etc/services netstat -antup | gr ...

  7. C++进阶-1-模板基础(函数模板、类模板)

    C++进阶 模板 1.1 函数模板 1 #include<iostream> 2 using namespace std; 3 4 // 模板 5 6 // 模板的简单实例 7 // 要求 ...

  8. Oracle RAC修改监听端口号

    目录 修改OracleRAC监听端口号: 1.查看当前数据库监听状态: 2.修改集群监听端口: 3.手动修改LOCAL_LISTENER: 4.停止集群监听和SCAN: 5.修改listener.or ...

  9. 3┃音视频直播系统之浏览器中通过 WebRTC 直播视频实时录制回放下载

    一.录制分类 在音视频会议.在线教育等系统中,录制是一个特别重要的功能 录制一般分为服务端录制和客户端录制 服务端录制:优点是不用担心客户因自身电脑问题造成录制失败(如磁盘空间不足),也不会因录制时抢 ...

  10. wait、notify和notifyAll方法学习

    wait.notify和notifyAll方法 wait() 方法会使该锁资源释放,然后线程进入等待WAITING状态,进入锁的waitset中,然后等待其他线程对锁资源调用notify方法或noti ...