代码编织梦想

比赛地址

A.Technical Support

题意:

给定一个包含 Q 和 A 的字符串,Q 表示询问,A 表示回答,多个 A 可以回答同一个Q ,问最后是否有 Q 没有回答

思路:

遍历字符串,若出现 Q 则 res ++, 若出现 A 则考虑 res:

  • 若 res > 0,说明前面还有 Q 没有被回答,则 res –
  • 若 res = 0,说明前面的 Q 都被回答了,当前的 A 是补充回答其中某一个 Q,res = 0

AC代码:

#include <bits/stdc++.h>
using namespace std;
 
#define x first
#define y second
#define int long long
#define div() cout << "-----------------------------" << endl
#define deb(n) cout<< #n << " = " << n <<endl

typedef pair<int, int> PII;
typedef pair<string, int> PSI;
 
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
 
const int N = 2e5 + 5, INF = 0x3f3f3f3f;
 
int n, m;
int a[N];

void oper()
{
	cin >> n;
	string s;
	cin >> s;

	int res = 0;
	for (int i = 0; i < n; i ++)
	{
		if (s[i] == 'Q')	res ++;
		else if (s[i] == 'A' && res > 0)		res --;
		else	res = 0;
	}

	if (res)	cout << "NO" <<	endl;
	else	cout << "YES" << endl;
}

signed main() 
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t;	cin >> t;
	while (t--)	oper();
	return 0;
}

B.Kevin and Permutation

题意:

求 1 ~ n 的全排列,使得所有连续两项之差的绝对值的最小值最大,
即 使 得 min ⁡ i = 1 n − 1 ∣ p i + 1 − p i ∣ 最 大 即使得 \min \limits_{i=1}^{n - 1} \lvert p_{i + 1} - p_i \rvert 最大 使i=1minn1pi+1pi

思路:

构造:x, 1, x + 1, 2, x + 2 … … 其中 x = n / 2 + 1

AC代码:

#include <bits/stdc++.h>
using namespace std;
 
#define x first
#define y second
#define int long long
#define div() cout << "-----------------------------" << endl
#define deb(n) cout<< #n << " = " << n <<endl

typedef pair<int, int> PII;
typedef pair<string, int> PSI;
 
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
 
const int N = 2e5 + 5, INF = 0x3f3f3f3f;
 
int n, m;
int a[N];

void oper()
{
    int n;
    cin >> n;
    
    int d = n / 2;
    int a[N];
    
    a[1] = 1 + d;
    a[2] = 1;
    
    for (int i = 3; i <= n; i ++)   a[i] = a[i - 2] + 1;
    for (int i = 1; i <= n; i ++)   cout << a[i] << ' ';
    
    cout << endl;
}

signed main() 
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t;	cin >> t;
	while (t--)	oper();
	return 0;
}
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/m0_52806260/article/details/127951321

Codeforces Round #735 (Div. 2)-爱代码爱编程

Codeforces Round #735 Div. 2 A. CherryB. CobbC. MikasaD. Diane 很废,做了一题。 第二题超时了,删掉一个0就给多了,血亏 做题地址:Codeforces Round #735 Div.2 A. Cherry 题目: 让连续区间内,最大值和最小值的乘积最大

codeforces round #800 (div. 2)_amjieker的博客-爱代码爱编程

div2 唯唯诺诺 文章目录 ABCDE A 0101 输出 大胆猜结论 #define endl '\n'; int t; int main() { cin >> t; while (t --) { int a, b; cin >> a >

codeforces round #818 (div. 2)c_原始森林lja的博客-爱代码爱编程

题目:传送门 思路:首先,排除a和b一开始就全等和a比b大的特殊情况。我们不妨设b中最小的数为minn,则我们第一步可以把a中所有比minn小的全设为minn而不必改其它地方的值(手推一下就知道) 。接着,我们从随意一个minn的位置,从右往左遍历,对于每一个ai-1,如果它能被改变的话,它最大只能达到ai+1。若bi大于这个数,则NO,反之只需要改过来

codeforces round #825 (div. 2)_咸鱼啥也不会的博客-爱代码爱编程

A. Make A Equal to B time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output You are given two arrays a and b of n elements, each

codeforces round #830 (div. 2)_与风做友的博客-爱代码爱编程

A. Bestie 题目链接:A. Bestie 样例:  input: 9 1 1 1 2 2 2 4 3 3 6 9 4 5 10 15 20 5 120 60 80 40 80 6 150 90 180 120 60 30 6 2 4 6 9 12 18 6 30 60 90 120 125 125 output:

codeforces round #829 (div. 2)部分题解a b c1 e_liaobkkk的博客-爱代码爱编程

  原题地址:Dashboard - Codeforces Round #829 (Div. 2) - Codeforces             A. Technical Support 题意:         有一个只包含“Q”和"A"的字符串,Q代表问题,A代表回答,有问必有答,也就是Q后面一定有n个A(n>=0) 代码:    

codeforces round #829 (div. 2)a.b.c1.d_evil_boy__的博客-爱代码爱编程

A. Technical Support 题目链接: Problem - A - Codeforces 题面: 题意: 有一段对话,Q是询问,A是回答,对于每个问题,你可以回答一句或者多句,你也可以后面回答前面的问题,问这个对话框是否每个问题都有回答 思路: 对于每次回答,我们优先假设是没有回答过的询问的回答,然后判断是否每个问题都有

codeforces round #823 (div. 2)-爱代码爱编程

文章目录 前言一、A Planets二、B - Meeting on the Line三、C - Minimum Notation总结 前言 D题想不出来 QAQ 一、A Planets

codeforces round #824 (div. 2) 参考代码-爱代码爱编程

A. Working Week: #include<cstdio> #include<cstring> #include<stdlib.h> #include<algorithm&

codeforces round #830 (div.2) 题解-爱代码爱编程

A 题目链接:Problem - A - Codeforces  input:   9 1 1 1 2 2 2 4 3 3 6 9 4 5 10 15 20 5 120 60 80 40 80 6 150 90 180 120 60 30 6 2 4 6 9 12 18 6 30 60 90 120 125 125 output: 0 1 2

codeforces round #829 (div. 2) (补)-爱代码爱编程

A. 我们只需判断每个Q后面是否有A就好了 #include <bits/stdc++.h> using namespace std; void solve(){ int n;cin>>n; string s;cin>>s;int mp1=0,mp2=0;bool ok=0; for(int i=0;i<s

codeforces round #832 (div. 2)_codeforces round 832 (div. 2)-爱代码爱编程

A. Two Groups 题目链接:Problem - A - Codeforces 样例输入:  4 2 10 -10 4 -2 -1 11 0 3 2 3 2 5 -9 2 0 0 -4 样例输出: 0 8 7 11 题意:给定n个数,我们可以将这n个数划分至2个集合,允许其中一个集合为空集,问第一个集合内的数的和的绝对值-第二个