A. Next Test
链接
这个题非常简单不像1200分的题,就是先排序吧第一个按顺序把第一个没出现的数字打印出来就好了
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no cout<<"NO"<<'\n'
using namespace std;
const int N = 3005;
signed main () {
int a[N] = {0};
int n;
cin >> n;
int i;
for (i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
}
sort(a + 1, a + n + 1);//排序
for (i = 1; i <= n; i++) {
if (a[i] != i) {//a[i]!=i退出循环
break;
}
}
cout << i << '\n';//打印i
return 0;
}
C. Swap Game
链接
这个题也不会看了题解才会,总体来说,就是两个人每次选一个数让对方减小,但是初始的时候已经选好了一个数让Alice减小,最后轮到谁的第一个元素为0谁就输了,所以两个人都要选择最小的给对方减小,所以Alice肯定选择2到n里面最小,又因为Alice比Bob快一步,所以只有存在a[i]小于等于a[2]到a[n]最小的n Bob才可能赢,下面看一下代码
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no cout<<"NO"<<'\n'
using namespace std;
const int N = 100005;
int a[N];
signed main () {
int t;
scanf("%lld", &t);
while (t--) {
int n;
scanf("%lld", &n);
int mmin = 9999999999999;
int x;
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
if (i == 1) {
x = a[i];
} else {
if (a[i] < mmin) {
mmin = a[i];
}
}
}
//判断a[i]和mmin的最小值如果mmin小Alice赢
if (mmin < x) {
printf("Alice\n");
} else //如果mmin>=x的话,Bob赢
{
printf("Bob\n");
}
}
return 0;
}
C. Bracket Sequence Deletion
链接
这个题直接模拟判断一下,但是还是有点技巧的,很容易发现((和))和()和)(这4种情况是两个括号4种组成方式,其中只有)(不符合题目要求(最后一种情况只能满足回文),让我们特别判断一下
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no cout<<"NO"<<'\n'
using namespace std;
const int N = 100005;
int a[N];
signed main () {
int t;
scanf("%lld", &t);
while (t--) {
int lift = 0, right = 0;//用来记录左括号和右括号的个数
int n;
scanf("%lld", &n);
string s;
cin >> s;
int ans = 0;
for (int i = 0; i < n; i++) {
if (s[i] == ')') {//一个括号不是左括号就是右括号
right++;
} else {
lift++;
}
if (lift == 1 && right == 1 && s[i - 1] == '(') {//当满足()这种情况的时候
ans++;
lift = 0;
right = 0;
} else if (lift == 2 && right == 0) {//满足((情况
ans++;
lift = 0;
} else if (right == 2 && lift == 0) {//满足))情况
right = 0;
ans++;
} else if (right == 2 && lift != 0) {//满足)xxxxxx(回文的情况
right = 0;
lift = 0;
ans++;
}
//分别让ans++
}
cout << ans << ' ' << lift + right << '\n';//打印ans和最后剩下的括号数量
}
return 0;
}
标签:03,right,06,++,long,define,lift,include,刷题
From: https://www.cnblogs.com/harper886/p/17195860.html