A
# include <bits/stdc++.h>
using namespace std;
#define int long long
int n,k;
signed main()
{
int T;
cin>>T;
while(T--)
{
cin>>n>>k;
bool st=0;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
if(x==k)
{
st=1;
}
}
if(st)
cout<<"YES";
else cout<<"NO";
cout<<endl;
}
}
B
奇数一定无法整除偶数
# include <bits/stdc++.h>
using namespace std;
#define int long long
int n;
signed main()
{
int T;
cin>>T;
while(T--)
{
cin>>n;
int l=1;
for(int i=1;i<=n;i++)
{
cout<<l<<" ";
l+=2;
}
cout<<endl;
}
return 0;
}
C
贪心的考虑 所凑出的数位开头前k个到结尾后k数之间
# include <bits/stdc++.h>
using namespace std;
#define int long long
int n,k,s;
signed main()
{
int T;
cin>>T;
while(T--)
{
int mn=0,mx=0;
cin>>n>>k>>s;
mn=(1+k)*k/2;
mx=(n+n-k+1)*k/2;
if(s>=mn&&s<=mx)
cout<<"YES";
else cout<<"NO";
cout<<endl;
}
return 0;
}
E
根据与的操作性质都为一时才为一,否则为零.a[i][j]表示前i个数第j位为1的个数。区间具有单调性当1越多时数越大,反之越小。二分即可
# include <bits/stdc++.h>
using namespace std;
#define int long long
using namespace std;
const int N = 2e5+10;
int t;
int a[N][40];
int l, k;
bool cheek(int l, int r, int k)
{
int s=0;
for (int i = 32; i >= 1; i--)
{
if(a[r][i]-a[l-1][i]==r-l+1)//全1才是1
{
s+=1<<(i-1);
if(s>=k)
return true;//满足直接退出即可
}
}
return false;
}
signed main()
{
cin >> t;
while (t--)
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
int tmp;
cin >> tmp;
for (int j = 1; tmp; j++)
{
a[i][j] = tmp % 2;
tmp >>= 1;
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= 32; j++)
a[i][j] += a[i - 1][j];
}
int q;
cin >> q;
while (q--)
{
cin >> l >> k;
int ll=l-1, rr = n;
while (ll < rr)
{
int mid = (ll + rr + 1) >> 1;
if (cheek(l, mid, k))ll = mid;
else rr = mid - 1;
}
if (ll<l||ll>n)cout << -1 << " ";
else cout << ll << " ";
}
cout << endl;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= 32; j++)a[i][j] = 0;
}
return 0;
}