牛客小白月赛84_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ (nowcoder.com)
A
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
int T;cin>>T;
for(int i=1;i<=T;i++)
{
ll n,m,x,y;cin>>n>>m>>x>>y;
if(x>y) cout<<"No"<<endl;
else if(y-x<=n-m) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}
B
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
void solve()
{
int x,y;cin>>x>>y;
if(y%x==0) {
cout<<x<<" "<<y<<endl;
}
else cout<<"-1"<<endl;
}
int main()
{
int T;cin>>T;
while(T--)
{
solve();
}
return 0;
}
C
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+10;
int a[N];
void solve()
{
int n,k;cin>>n>>k;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
int tem = a[1]-k;
int flag=1;
for(int i=2;i<=n;i++)
{
if(a[i]+k<tem){
flag=0;
break;
}
else tem = max(a[i]-k,tem);
}
if(flag) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
signed main()
{
int T;cin>>T;
while(T--)
{
solve();
}
return 0;
}
这题要保证b非降序,除了贪心每次选最小的以外还要else tem = max(a[i]-k,tem);,保证选的数不比前一个小;
D
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;i++)
const int N=1e6+10;
char s[N];
signed main()
{
int n,q;
cin>>n>>q;
scanf("%s",s+1);
s[0]=s[n+1]='0';
int ans=0;
rep(i,1,n){
if(s[i]=='1'&&s[i+1]=='0') ans++;
}
int l,r;
while(q--)
{
scanf("%d%d",&l,&r);
if(s[l-1]==s[r+1]||s[l]==s[r]) printf("%d\n",ans);
else{
if(s[l-1]!=s[l]) printf("%d\n",ans-1);
else printf("%d\n",ans+1);
}
}
return 0;
}
E
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e6+5;
ll a[N];
ll n;
ll T;
int main()
{
std::ios::sync_with_stdio(false);std::cin.tie(0);
cin>>T;
while(T--)
{
cin>>n;
ll sum=0,zero=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
sum+=a[i];
zero+=(a[i]==0);
}
if(zero*2>=n){
cout<<"Dog"<<"\n";
continue;}
if(n==2){
if(abs(a[0]-a[1])==1)
cout<<"Cat"<<"\n";
else cout<<"Dog"<<"\n";
continue;
}
if((sum-n/2+10000000)&1)
cout<<"Dog"<<"\n";
else
cout<<"Cat"<<"\n";
}
return 0;
}
博弈题;
F
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;i++)
void solve()
{
int n;
cin >> n;
vector<int> cons(n + 1,-1);
vector<int> a(n);
for(int i = 1;i < n;i ++) {
cin >> a[i];
}
int m = (n + 1) >> 1;
auto check = [&]() {
for(int i = n;i > m;i --) {
cons[i] = -1;
}
for(int i = n - 1;i >= 1;i --) {
int f = -1,c = 0;
for(int j = 1;j + i <= n;j ++) {
if(cons[j + i] == -1) {
f = j + i;
}
else {
if(!cons[j] && cons[j + i]) {
c ++;
}
}
}
if(c == a[i]) {
if(f != -1) cons[f] = 0;
}
else if(c + 1 == a[i]) {
if(f == -1) return false;
cons[f] = 1;
}
else return false;
}
for(int i = 1;i < n;i ++) {
int c = 0;
for(int j = 1;j + i <= n;j ++) {
if(!cons[j] && cons[j + i]) c ++;
}
if(c != a[i]) return false;
}
return true;
};
for(int i = 0;i < (1 << m);i ++) {
for(int j = 0;j < m;j ++) {
if(i >> j & 1) cons[j + 1] = 0;
else cons[j + 1] = 1;
}
if(check()) {
for(int i = 1;i <= n;i ++) {
cout << cons[i];
}
return;
}
}
cout << -1 << '\n';
}
int main()
{
solve();
}
折半状压,还没学,这题不会