A-小苯的石子游戏_牛客小白月赛87 (nowcoder.com)
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N=110;
int a[N];
int n;
void solve() {
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+1+n);
reverse(a+1,a+1+n);
int flag=1;
int sum1=0,sum2=0;
for(int i=1;i<=n;i++){
if(flag) sum1+=a[i];
else sum2+=a[i];
flag^=1;
}
if(sum1>sum2) cout<<"Alice"<<endl;
else cout<<"Bob"<<endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
cin>>t;
while(t--) {
solve();
}
return 0;
}
B-小苯的排序疑惑_牛客小白月赛87 (nowcoder.com)
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N=2e5+10;
int a[N],b[N];
int n;
void solve() {
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i],b[i]=a[i];
sort(b+1,b+1+n);
if(a[1]==b[1]||a[n]==b[n]) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
cin>>t;
while(t--) {
solve();
}
return 0;
}
C-小苯的IDE括号问题(easy)_牛客小白月赛87 (nowcoder.com)
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
int n,k;
string s;
stack<char>q;
void solve() {
cin>>n>>k;
cin>>s;
int pos;
for(int i=0;i<n;i++){
if(s[i]=='I'){
pos=i;
break;
}
q.push(s[i]);
}
pos++;
for(int i=0;i<k;i++){
string op;
cin>>op;
if(op=="backspace"){
if(q.size()&&q.top()=='('&&pos<n&&s[pos]==')'){
q.pop();
pos++;
}
else if(q.size()) q.pop();
}
else{
if(pos<n) pos++;
}
}
vector<char>ans;
while(q.size()){
ans.push_back(q.top());
q.pop();
}
reverse(ans.begin(),ans.end());
for(auto v:ans) cout<<v;
cout<<'I';
for(int i=pos;i<n;i++) cout<<s[i];
cout<<endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
// cin>>t;
while(t--) {
solve();
}
return 0;
}
D-小苯的IDE括号问题(hard)_牛客小白月赛87 (nowcoder.com)
利用两个双端队列 ,第一个队列表示光标左边部分,第二个队列表示光标右边部分
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
int n,k;
string s;
deque<char>q1,q2;
void solve() {
cin>>n>>k;
cin>>s;
bool ok=false;
for(int i=0;i<n;i++){
if(s[i]=='I'){
ok=true;
continue;
}
if(!ok) q1.push_back(s[i]);
else q2.push_back(s[i]);
}
for(int i=0;i<k;i++){
string op;
cin>>op;
if(op=="<-"){
if(q1.size()){
char t=q1.back();
q1.pop_back();
q2.push_front(t);
}
}
else if(op=="->"){
if(q2.size()){
char t=q2.front();
q2.pop_front();
q1.push_back(t);
}
}
else if(op=="backspace"){
char t1='.',t2='.';
if(q1.size()){
t1=q1.back();
q1.pop_back();
}
if(q2.size()){
t2=q2.front();
if(t1=='('&&t2==')') q2.pop_front();
}
}
else{
if(q2.size()) q2.pop_front();
}
}
for(auto v:q1) cout<<v;
cout<<'I';
for(auto v:q2) cout<<v;
cout<<endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
// cin>>t;
while(t--) {
solve();
}
return 0;
}
E-小苯的数组构造_牛客小白月赛87 (nowcoder.com)
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N=2e5+10;
int a[N];
int n;
void solve() {
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
cout<<0<<' ';
int tmp=a[1];
for(int i=2;i<=n;i++){
if(a[i]<tmp) cout<<tmp-a[i]<<' ';
else cout<<0<<' ',tmp=a[i];
}
cout<<endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
// cin>>t;
while(t--) {
solve();
}
return 0;
}