文章目录
A.Mocha and Math
传送门
题目大意:输出若干次’&‘运算后的最小数
思路:从头到尾&一遍,输出最后的值
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include <limits>
#include<string>
#include<deque>
#include<map>
#include<bitset>
#include<set>
#include<cstdio>
#include<vector>
#define ll long long
#define PI 3.141592653589793
#define E 2.718281828459045
#define HalF (l + r)>>1
#define lsn rt<<1
#define rsn rt<<1|1
#define Lson lsn, l, mid
#define Rson rsn, mid+1, r
#define QL Lson, ql, qr
#define QR Rson, ql, qr
#define myself rt, l, r
#define mem(a,b) memset(a,b,sizeof(a))
#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )
#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )
#define lowbit(a) ((a)&-(a))
typedef unsigned long long ull;
const ll INF=0x3f3f3f3f;
const ll Max=10000;
using namespace std;
int t,n,m;
ll a[110];
/*queue<ll> q;
stack<ll> s;
//升序队列
priority_queue <int,vector<int>,greater<int> > q;
//降序队列
priority_queue <int,vector<int>,less<int> >q;*/
int main()
{
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
scanf("%lld",&a[0]);
for(int i=1;i<m;i++)
{
scanf("%lld",&a[i]);
a[0]&=a[i];
}
printf("%lld\n",a[0]);
}
return 0;
}
B.Mocha and Red and Blue
传送门
题目大意:给你个字符串,里面有‘B’,’R‘和‘?’,其中‘?’可以任意变为‘R’或‘B’,目的是将‘?’变化,使得所得的字符串中连续出现的相同字符最少
思路:首先分为两部分,一部分是第一个非‘?’的字符前边和它本身和后面部分,因为前面只是‘?’,对变化的约束小,后面再进行判断变化即可
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include <limits>
#include<string>
#include<deque>
#include<map>
#include<bitset>
#include<set>
#include<cstdio>
#include<vector>
#define ll long long
#define PI 3.141592653589793
#define E 2.718281828459045
#define HalF (l + r)>>1
#define lsn rt<<1
#define rsn rt<<1|1
#define Lson lsn, l, mid
#define Rson rsn, mid+1, r
#define QL Lson, ql, qr
#define QR Rson, ql, qr
#define myself rt, l, r
#define mem(a,b) memset(a,b,sizeof(a))
#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )
#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )
#define lowbit(a) ((a)&-(a))
typedef unsigned long long ull;
const ll INF=0x3f3f3f3f;
const ll Max=10000;
using namespace std;
int t,n,m;
char a[110];
int b[110];
char d[110];
/*queue<ll> q;
stack<ll> s;
//升序队列
priority_queue <int,vector<int>,greater<int> > q;
//降序队列
priority_queue <int,vector<int>,less<int> >q;*/
int main()
{
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
int k=0,j=0;cin>>a;
for(int i=0;i<m;i++)
{
if(a[i]=='?')
j++;
else break;
}
for(int i=j-1;i>=0;i--)
{
if(a[i+1]=='B') a[i]='R';
else a[i]='B';
}
for(int i=j;i<m;i++)
{
if(a[i]=='?')
{
if(a[i-1]=='B')
a[i]='R';
else a[i]='B';
}
}
cout<<a<<endl;
mem(a,0);
}
return 0;
}
C.Mocha and Hiking
传送门
题目大意:你输入n,有n+1个村庄和2*n-1(有向图,单向的)条路,其中n-1条路是第i个村庄到第i+1个村庄(i>0&&i<=n-1),然后输入n条路,0代表它下标代表的村庄到第n+1个村庄有路,1代表第n+1到它下标代表的村庄有路,目的是怎样每个村庄只走一次,走遍所有的村庄
思路:记录0的个数,如果和为0,输出n+1然后输出1到n即可,剩下的情况需要知道最后一个0,然后在输出最后一个0的下标后直接输出n+1就好,后面正常输出
下面为两种情况
全为1:
输出:4 1 2 3
不全为1;
输出:1 2 4 3
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include <limits>
#include<string>
#include<deque>
#include<map>
#include<bitset>
#include<set>
#include<cstdio>
#include<vector>
#define ll long long
#define PI 3.141592653589793
#define E 2.718281828459045
#define HalF (l + r)>>1
#define lsn rt<<1
#define rsn rt<<1|1
#define Lson lsn, l, mid
#define Rson rsn, mid+1, r
#define QL Lson, ql, qr
#define QR Rson, ql, qr
#define myself rt, l, r
#define mem(a,b) memset(a,b,sizeof(a))
#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )
#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )
#define lowbit(a) ((a)&-(a))
typedef unsigned long long ull;
const ll INF=0x3f3f3f3f;
const ll Max=10010;
using namespace std;
int t,n,m;
int a[Max];
/*queue<ll> q;
stack<ll> s;
//升序队列
priority_queue <int,vector<int>,greater<int> > q;
//降序队列
priority_queue <int,vector<int>,less<int> >q;*/
int main()
{
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
int sum=0,sun=0;
for(int i=1;i<=m;i++)
{
scanf("%d",&a[i]);
if(a[i]==0)
{sum++;sun=i;}
}
if(sum==0)
printf("%d ",m+1);
for(int i=1;i<=m;i++)
{
printf("%d ",i);
if(sun==i) printf("%d ",m+1);
}
cout<<endl;
}
return 0;
}