Codeforces Round 908

Problem - A - Codeforces

cpp 复制代码
// Problem: A. Secret Sport
// Contest: Codeforces - Codeforces Round 908 (Div. 2)
// URL: https://codeforces.com/contest/1894/problem/A
// Memory Limit: 512 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<string>
#include<cstring>
#include<cmath>
#include<bitset>
#include<sstream>//切割strtream头文件
#include<climits>//INT_MAX文件
#include <utility>
#include<memory>//for unique_ptr shared_ptr
using i64 = int64_t;
using namespace std;
#define int i64
#define endl '\n'
#define AC return 0;
#define WA(x) cout << x << endl;
#define lowbit(x) x & -x
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
int n, m, k, d, T = 1, A, B;

template<typename T>void read(T &x) {
    T f = 1;x = 0;char s = getchar();
    while(s < '0' || s > '9') {if(s == '-')f = -1;s = getchar();}
    while(s >= '0' && s <= '9') {x = x * 10 + s - '0';s = getchar();}
    x *= f;
}

template<typename T>void print(T x) {
    if(x < 0) putchar('-'),x = -x;
    if(x > 9) print(x / 10);
    putchar(x % 10 + '0');
    putchar('\n');
}
constexpr int Init(int x)
{
	return x * 2;
}
void solve()
{
	cin >> n;
	char ans;
	for (int i = 0; i < n; i++)cin >> ans;
	std::cout << ans << endl;
}
 
signed main() {
    cin.tie(0) -> sync_with_stdio(false);
    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}

Problem - B - Codeforces

是3个条件有且仅有2个条件被满足

cpp 复制代码
// Problem: B. Two Out of Three
// Contest: Codeforces - Codeforces Round 908 (Div. 2)
// URL: https://codeforces.com/contest/1894/problem/B
// Memory Limit: 512 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<string>
#include<cstring>
#include<cmath>
#include<bitset>
#include<sstream>//切割strtream头文件
#include<climits>//INT_MAX文件
#include <utility>
#include<memory>//for unique_ptr shared_ptr
using i64 = int64_t;
using namespace std;
#define int i64
#define endl '\n'
#define AC return 0;
#define WA(x) cout << x << endl;
#define lowbit(x) x & -x
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
int n, m, k, d, T = 1, A, B;

template<typename T>void read(T &x) {
    T f = 1;x = 0;char s = getchar();
    while(s < '0' || s > '9') {if(s == '-')f = -1;s = getchar();}
    while(s >= '0' && s <= '9') {x = x * 10 + s - '0';s = getchar();}
    x *= f;
}

template<typename T>void print(T x) {
    if(x < 0) putchar('-'),x = -x;
    if(x > 9) print(x / 10);
    putchar(x % 10 + '0');
    putchar('\n');
}
constexpr int Init(int x)
{
	return x * 2;
}

void solve()
{
	cin >> n;
	vector<int>a(n + 1,1);
	map<int,int> M;
	int k = 1,d = -1;
	for(int i = 1;i <= n;i++)
	{
		cin >> m;
		M[m]++;
		if(M[m] >= 2)
		{
			if(k == 1){k++;d = m;}
			if(m == d)a[i] = 2;
			else {a[i] = 3;
			k++;}
		}
	}
	if(k <= 2)cout << -1;
	else 
	for(int i = 1;i <= n;i++)cout << a[i] << " ";
	cout << endl;
}
 
signed main() {
    cin.tie(0) -> sync_with_stdio(false);
    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}

Problem - C - Codeforces

反向模拟即可,若满足题意要求,pos = x && a[x] == x 的左移规则,a[x ]不可能 > n

cpp 复制代码
// Problem: C. Anonymous Informant
// Contest: Codeforces - Codeforces Round 908 (Div. 2)
// URL: https://codeforces.com/contest/1894/problem/C
// Memory Limit: 512 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<string>
#include<cstring>
#include<cmath>
#include<bitset>
#include<sstream>//切割strtream头文件
#include<climits>//INT_MAX文件
#include <utility>
#include<memory>//for unique_ptr shared_ptr
using i64 = int64_t;
using namespace std;
#define int i64
#define endl '\n'
#define AC return 0;
#define WA(x) cout << x << endl;
#define lowbit(x) x & -x
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
int n, m, k, d, T = 1, A, B;

template<typename T>void read(T &x) {
    T f = 1;x = 0;char s = getchar();
    while(s < '0' || s > '9') {if(s == '-')f = -1;s = getchar();}
    while(s >= '0' && s <= '9') {x = x * 10 + s - '0';s = getchar();}
    x *= f;
}

template<typename T>void print(T x) {
    if(x < 0) putchar('-'),x = -x;
    if(x > 9) print(x / 10);
    putchar(x % 10 + '0');
    putchar('\n');
}
constexpr int Init(int x)
{
	return x * 2;
}
int a[maxn];
void solve()
{
	auto x = make_unique<int>();
	cin >> n >> k;
	for(int i = 1;i <= n;i++)cin >> a[i];
	k = min(n,k);
	int pos = n;
	while(k--)
	{
		if(a[pos] > n)
		{
			cout << "No" << endl;
			return;	
		}
		pos -= a[pos];
		if(pos <= 0)pos += n;
	}
	cout << "Yes" << endl;
}
 
signed main() {
    cin.tie(0) -> sync_with_stdio(false);
    int T = 1;
   	cin >> T;
    while (T--) solve();
    return 0;
}
相关推荐
gsfl44 分钟前
贪心算法1
算法·贪心算法
小猪咪piggy1 小时前
【算法】day8 二分查找+前缀和
算法
Word码1 小时前
[排序算法]希尔排序
c语言·数据结构·算法·排序算法
前端小刘哥1 小时前
解析视频直播点播平台EasyDSS在视频点播领域的技术架构与性能优势
算法
QT 小鲜肉1 小时前
【数据结构与算法基础】05. 栈详解(C++ 实战)
开发语言·数据结构·c++·笔记·学习·算法·学习方法
lingran__1 小时前
算法沉淀第七天(AtCoder Beginner Contest 428 和 小训练赛)
c++·算法
前端小刘哥2 小时前
新版视频直播点播平台EasyDSS,打通远程教研与教师培训新通路
算法
2401_840105202 小时前
P1049 装箱问题 题解(四种方法)附DP和DFS的对比
c++·算法·深度优先·动态规划
kobe_t2 小时前
数据安全系列7:常用的非对称算法浅析
算法
靠近彗星2 小时前
3.4特殊矩阵的压缩存储
数据结构·人工智能·算法