第三题
C-嘤嘤不想买东西喵_牛客周赛 Round 49 (nowcoder.com)
这个是一道最大连续子段和
可以用贪心和dp来写
具体操作代码(贪心)
ll n, x; cin >> n >> x;
ll mx = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] = a[i] - x;
b[i] = a[i] + b[i - 1];
if(b[i-1]<=0)b[i]=a[i];//前一段小于0直接舍去
mx=max(b[i],mx);
}
dp
ll n, x; cin >> n >> x;
ll mx = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] = a[i] - x;
dp[i] =max(0ll, dp[i - 1] + a[i]);
mx=max(mx,dp[i]);
}
cout << mx;
其实dp和贪心差不多
第四题
D-嘤嘤不想求异或喵_牛客周赛 Round 49 (nowcoder.com)
在我另一篇有
ll f(ll x)
{
if(x%4==1)return 1;
else if(x%4==2)return x+1;
else if(x%4==3)return 0;
else return x;
}
void solve()
{
ll l,r;
cin>>l>>r;
ll ans=f(l-1)^f(r);
cout<<ans<<"\n";
}
第五题
E-嘤嘤不想解方程喵_牛客周赛 Round 49 (nowcoder.com)
判别式
1
ll a1,b1,c1,a2,b2,c2;cin>>a1>>b1>>c1>>a2>>b2>>c2;
i128 a=b2*a1;
i128 b=b1*b2+a2;
i128 c=b2*c1+c2;
if(a==0)
{
if(b==0)
{
if(c==0)
{
cout<<"INF\n";//无穷多
}
else cout<<"0\n";//一个解也没有
}
//b*x+c=0
else cout<<"1\n";
}
else{
i128 temp=b*b-4*a*c;
if(temp<0)cout<<"0\n";
else if(temp==0)cout<<"1\n";
else cout<<"2\n";
2
#include<bits/stdc++.h>
using namespace std;
int n;
double a1,b1,c1,a2,b2,c2;
double a,b,c;
int main( ) {
int t;
cin>>t;
while(t--){
cin>>a1>>b1>>c1>>a2>>b2>>c2;
b = a2+b2*b1;
a = a1*b2;
c = b2*c1 + c2;
if(a==0){
if(b==0){
if(c==0){
cout<<"INF";
}
else cout<<0;
}
else cout<<1;
}
else{
if(b*b-4*a*c>0){
cout<<2;
}
else if(b*b-4*a*c==0){
cout<<1;
}
else if(b*b-4*a*c<0){
cout<<0;
}
}
cout<<'\n';
}
}