Codeforces Round #738 (Div. 2)
A
#include <bits/stdc++.h>
using namespace std;
signed main()
{
int t;
cin>>t;
while (t--)
{
int n,a[101],b[101];
for (int i=0;i<50;i++) b[i] = 1;
cin>>n;
int m = 0;
for (int i=0;i<n;i++)
{
cin>>a[i];
for (int j=31;~j;j--)
{
int u = (a[i]>>j)&1;
if (u==0) b[j] = 0;
}
}
for (int j=31;~j;j--)
{
if (b[j]==1) m = m*2+1;
else m*=2;
}
cout<<m<<endl;
}
}
B
#include <bits/stdc++.h>
using namespace std;
// #define int long long
signed main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
string str;
cin >> str;
int k = -1;
bool flag = false;
for (int i = 0; i < n; i++)
{
if (str[i] != '?' && flag == false)
{
k = i;
flag = true;
char kk;
if (str[i] == 'B')
kk = 'R';
else
kk = 'B';
for (int j = i - 1; j >= 0; j--)
{
if ((j - i )% 2)
str[j] = kk;
else
str[j] = str[i];
}
if (i + 1 < n)
{
if (str[i + 1] == '?')
{
char kk;
if (str[i] == 'B')
kk = 'R';
else
kk = 'B';
str[i + 1] = kk;
}
}
}
else if (str[i] != '?')
{
if (i + 1 < n)
{
if (str[i + 1] == '?')
{
char kk;
if (str[i] == 'B')
kk = 'R';
else
kk = 'B';
str[i + 1] = kk;
}
}
}
}
if (k == -1)
{
for (int i = 0; i < n; ++i)
{
if (i & 1)
str[i] = 'R';
else
str[i] = 'B';
}
}
cout << str << endl;
}
}
C
如果有01就从0过去,从回来1,如果没有,说明都是0,就可以一直过去
#include <bits/stdc++.h>
using namespace std;
// #define int long long
int a[10010];
signed main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
bool flag = false;
int qu, hui;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
if (a[i] == 1 && a[i - 1] == 0 && flag == false)
{
flag = true;
qu = i - 1;
hui = i;
}
}
if (flag)
{
for (int i = 1; i <= qu; i++)
cout << i << " ";
cout << n + 1 << " ";
for (int i = hui; i <= n; i++)
cout << i << " ";
cout << endl;
}
else
{
for (int i = 1; i <= n + 1; i++)
cout << i << " ";
cout << endl;
}
}
}