Codeforces Round #804 (Div. 2)
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)的更多相关文章
- Codeforces Round #804 (Div. 2) C(组合 + mex)
Codeforces Round #804 (Div. 2) C(组合 + mex) 本萌新的第一篇题解qwq 题目链接: 传送门QAQ 题意: 给定一个\(\left [0,n-1 \right ] ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- 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 ...
- 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 ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
随机推荐
- 伪元素 Before & Aster
1. html 结构 <label class="is-required" for="name">姓名</label> <inpu ...
- Docker安装 Ubuntu Centos
Ubuntu 安装Dokcer 1. 删除旧版本Docker安装包和依赖项 sudo apt-get remove docker docker-engine docker.io containerd ...
- OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: "ip": executable file not found in $PATH: unknown (Docker容器没有ip addr命令:exec ip addr 报错)
一.报错 1.报错信息1: OCI runtime exec failed: exec failed: container_linux.go:380: starting container proce ...
- mask-image实现聚光灯效果
大家好,我是半夏,一个刚刚开始写文的沙雕程序员.如果喜欢我的文章,可以关注 点赞 加我微信:frontendpicker,一起学习交流前端,成为更优秀的工程师-关注公众号:搞前端的半夏,了解更多前端知 ...
- C++基础-2-引用
2. 引用 2.1 引用的基本语法 1 #include<iostream> 2 using namespace std; 3 4 5 int main() { 6 7 //引用的基本语法 ...
- GitHub 桌面版 v3.0 新特性「GitHub 热点速览」
新版本一般意味着更强的功能特性,比如 GitHub Desktop v3.0.虽然未发布新版本,但本周收录的 7 个开源项目颇有"新版"味.比如,破解(恢复)密码能力 Max 的 ...
- Node.js 中的进程和线程
线程和进程是计算机操作系统的基础概念,在程序员中属于高频词汇,那如何理解呢?Node.js 中的进程和线程又是怎样的呢? 一.进程和线程 1.1.专业性文字定义 进程(Process),进程是计算机中 ...
- AC自动机:Tire树+KMP
简介 AC自动机是一个多模式匹配算法,在模式匹配领域被广泛应用,举一个经典的例子,违禁词查找并替换为***.AC自动机其实是Trie树和KMP 算法的结合,首先将多模式串建立一个Tire树,然后结合K ...
- JS作用域与闭包
JS作用域与闭包 在JavaScript中,作用域是可访问变量,对象,函数的集合. 变量分为全局变量和局部变量.全局变量在函数外定义,HTML中全局变量是window对象,所有数据对象都属于windo ...
- 好客租房29-从jsx中抽离事件处理程序
从jsx中抽离过多js逻辑代码 会显得非常混乱 推荐:将逻辑抽离到单独的方法中 保证jsx结构清晰 //导入react import React from 'react' ...