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;
}
相关推荐
.普通人26 分钟前
算法基础(以acwing讲述顺序为主,结合自己理解,持续更新中...)
c++·算法
brzhang30 分钟前
为什么 A2A 和 MCP 缺一不可?
前端·后端·算法
strive-debug38 分钟前
上篇:《排序算法的奇妙世界:如何让数据井然有序?》
数据结构·算法·排序算法
徒步青云43 分钟前
七大排序算法及其优化
算法·排序算法
蔡蓝1 小时前
jwt的无感刷新
算法·哈希算法
HelloDam2 小时前
912. 排序数组 超级通俗易懂、全面的快速排序教程(优化重复元素、实例有序问题)
后端·算法·排序算法
HelloDam2 小时前
leetcode51.N 皇后 回溯算法求解 + 效率优化
后端·算法
DataFunTalk2 小时前
30位数据科学家集结完毕,揭晓大模型时代数据科学的“晋级之路”
前端·后端·算法
ん贤2 小时前
图论基础理论
c语言·数据结构·c++·算法·图论