(0条未读通知) 牛客竞赛_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ (nowcoder.com)
a.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+6;
const int inf=0x3f3f3f3f;
void solve()
{int n,cn1=0,cn2=0;string s,str1="dfs",str2="DFS";cin>>n>>s;for(auto i:s){if(i==str1[cn1])cn1++;if(i==str2[cn2])cn2++;}cout<<(cn2==3)<<' '<<(cn1==3)<<endl;
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);int t=1;cin>>t;while(t--){solve();}return 0;
}
b.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+6;
const int inf=0x3f3f3f3f;
typedef pair<int,int> pii;
void solve()
{int n,ans1=2,ans2=2;cin>>n;set<pii>se;for(int i=0;i<n;i++){int r,c;cin>>r>>c;se.insert({r,c});if(c<=0)ans1=1;if(c>=0)ans2=1;/*让c大于[等于]0是因为如果有{[2,0],[1,1],[2,1]}这种情况,应该输出1,这个时候到下面易知最后ans2=0,此时因为有c等于0的情况,ans1=1,ans1+an2=1,c<=0中的等于类似.*/}for(auto[x,y]:se){for(int i=-1;i<=1;i++){if(se.find({x^3,y+i})!=se.end()){if(y<0)ans1=0;if(y>0)ans2=0;}}}int ans=3-se.count({2,0})-se.count({1,-1})-se.count({1,1});cout<<min(ans,ans1+ans2)<<endl;
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);int t=1;cin>>t;while(t--){solve();}return 0;
}
c.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+6;
const int inf =0x3f3f3f3f;
int a[N],b[N];
void solve()
{int n,q,t;cin>>n>>q>>t;for(int i=1;i<=n;i++){cin>>a[i];}sort(a+1,a+1+n);for(int i=1;i<=n;i++){b[i]=b[i-1]+a[i];}while(q--){int m;cin>>m;int r=m/t;if(r>=n)cout<<t<<endl;else{cout<<b[n-r]+t<<endl;}}
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);int t;t=1;//cin>>t;while(t--){solve();}return 0;
}
d.
e.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+6;
const int inf =0x3f3f3f3f;
int n,m,a[11],u[11],v[11],ans;
void dfs(int x)
{if(x==m+1){int t=0;for(int i=2;i<=n;i++){if(a[1]<a[i])t++;}ans=min(ans,t+1);return ;}a[u[x]]+=3,dfs(x+1),a[u[x]]-=3;a[v[x]]+=3,dfs(x+1),a[v[x]]-=3;a[u[x]]++,a[v[x]]++,dfs(x+1),a[u[x]]--,a[v[x]]--;
}
void solve()
{cin>>n>>m;for(int i=1;i<=n;i++){cin>>a[i];}for(int i=1;i<=m;i++){cin>>u[i]>>v[i];}ans=n+1;dfs(1);cout<<ans<<endl;
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);int t;//t=1;cin>>t;while(t--){solve();}return 0;
}
f.
g.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+6;
const int inf =0x3f3f3f3f;
struct node{int aa,bb,cc;
}a[N];
bool cmp(node l,node r)
{return l.aa<r.aa;
}
void solve()
{int n,m,sum=-inf;cin>>n>>m;for(int i=1;i<=n;i++){cin>>a[i].aa>>a[i].bb;}sort(a+1,a+n+1,cmp);for(int i=1;i<=n;i++){a[i].bb+=a[i-1].bb;a[i].aa-=a[i].bb;if(a[i].aa<=m){sum=max(sum,a[i].bb+m);}}if(sum<=0)cout<<m<<endl;else cout<<sum<<endl;
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);int t;//t=1;cin>>t;while(t--){solve();}return 0;
}
h.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+6;
const int inf=0x3f3f3f3f;
int v[N],w[N],n,m;
int fkue(int x)
{int cn=0;for(int i=1;i<=n;i++){if((x|v[i])==x)cn+=w[i];}return cn;
}
void solve()
{cin>>n>>m;for(int i=1;i<=n;i++){cin>>w[i]>>v[i];//价值,重量}int ans=fkue(m);for(int i=27;i>=0;i--)//1e8的二进制27位{if((m>>i)&1)//将变量 m 右移 i 位后,取得结果的最低位(即最右边的一位)。{int r=(m/(1<<i)-1)*(1<<i)+(1<<i)-1;/*表示将数字 1 左移 i 位。这个操作可以用来快速计算 2 的幂次方。例如,1<<0 等于 1,1<<1 等于 2,1<<2 等于 4,以此类推。*/ans=max(ans,fkue(r));}}cout<<ans<<endl;
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);int t=1;cin>>t;while(t--){solve();}return 0;
}
i.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5;
const int inf=0x3f3f3f3f;
int E=(int)(N*1.0*((141.0*141.0)/(199*199)));
void solve()
{int n,x,y,r,cn=0;cin>>n;for(int i=0;i<n;i++){cin>>x>>y>>r;if(x<=70&&x>=-70&&y<=70&&y>=-70)cn++;}if(abs(cn-E)<2000)cout<<"bit-noob";//"bit-noob"的x,y比"buaa-noob"均匀,因为他的x,y定了就定了,//但"buaa-noob"的不满足还要重新生成,落在-70--70的概率更大。else cout<<"buaa-noob";
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);int t=1;//cin>>t;while(t--){solve();}return 0;
}
j.
k.
l.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int inf = 0x3f3f3f3f;
#define int long long
void solve()
{int t;cin>>t;while(t--){double b,c,d,h,w;cin>>c>>d>>h>>w;cout<<3*w*c<<endl;}
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);solve();return 0;
}
m.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int inf = 0x3f3f3f3f;
#define int long long
void solve()
{int t;cin>>t;while(t--){int n;cin>>n;if(n%6==0)cout<<n/6<<endl;else cout<<(n/6)*2<<endl;}
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);solve();return 0;
}
待续。。。