2022/1/22
2022/1/22
[ 深渊水妖 ]( A-深渊水妖_牛客小白月赛44 (nowcoder.com) )
枚举每一个上升字段,与之前找到的上升字段最大值作比较。
#include<bits/stdc++.h>
#define ll long long
#define pii pair<long long , long long >
#define se second
#define pb push_back
#define pf push_front
#define si size()
#define db double
#define ls (p<<1)
#define rs (p<<1|1)
#define fi first
#define se second
using namespace std;
ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
inline void Prin(ll x){if(x < 0){putchar('-');x = -x;}if(x > 9) Prin(x / 10);putchar(x % 10 + '0');}
const int qs=1e6+7;
const ll mod=998244353;
ll T,n;
ll a[qs];
vector< pii > ans;
int main(){
T=read();
while(T--){
ans.clear();
n=read();
for(int i=1;i<=n;++i){
a[i]=read();
}
a[n+1]=-1;
int max_ans=-1,ml=1,mr=1;
for(int i=1;i<=n+1;++i){
if(a[i]<a[i-1]){
int p=(a[mr]-a[ml]-max_ans);
// cout<<"ml="<<ml<<" mr="<<mr<<" p="<<p<<"\n";
if(p>0){
max_ans=a[mr]-a[ml];
ans.clear();
ans.pb({ml,mr});
}
else if(p==0) ans.pb({ml,mr});
ml=i;mr=i;
}
else mr=i;
}
for(auto x: ans){
cout<<x.fi<<" "<<x.se<<" ";
}
cout<<"\n";
}
return 0;
}
[ 顽皮恶魔 ]( B-顽皮恶魔_牛客小白月赛44 (nowcoder.com) )
字符串直接遍历8各位置标记一下即可
#include<bits/stdc++.h>
#define ll long long
#define pii pair<long long , long long >
#define se second
#define pb push_back
#define pf push_front
#define si size()
#define db double
#define ls (p<<1)
#define rs (p<<1|1)
#define fi first
#define se second
using namespace std;
ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
inline void Prin(ll x){if(x < 0){putchar('-');x = -x;}if(x > 9) Prin(x / 10);putchar(x % 10 + '0');}
const int qs=1e6+7;
const ll mod=998244353;
ll T,n,m,mp[1003][1003];
char c[1003][1003];
int mv[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
int main(){
T=read();
while(T--){
n=read(),m=read();
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j) mp[i][j]=0;
for(int i=1;i<=n;++i) cin>>c[i]+1;
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
if(c[i][j]=='*'){
for(int k=0;k<8;++k){
int x=i+mv[k][0],y=j+mv[k][1];
if(x<1||x>n||y<1||y>m) continue;
mp[x][y]=1;
}
}
}
}
int ans=0;
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
if(c[i][j]=='P'&& !mp[i][j]) ans++;
}
}
cout<<ans<<"\n";
}
return 0;
}
[ 绝命沙虫 ]( C-绝命沙虫_牛客小白月赛44 (nowcoder.com) )
直接对着题意模拟即可,不过求b的时候转换成int求,double会有精度问题。
#include<bits/stdc++.h>
#define ll long long
#define pii pair<long long , long long >
#define se second
#define pb push_back
#define pf push_front
#define si size()
#define db double
#define ls (p<<1)
#define rs (p<<1|1)
#define fi first
#define se second
using namespace std;
ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
inline void Prin(ll x){if(x < 0){putchar('-');x = -x;}if(x > 9) Prin(x / 10);putchar(x % 10 + '0');}
const int qs=1e6+7;
const ll mod=998244353;
ll T,n,x;
db m;
int main(){
T=read();
while(T--){
cin>>n>>m;
x=m*100-100;
ll ans=0;
while(n){
ll fx=n*100/10;
ll fy=min(n*x,(ll)10000)/10;
//cout<<"n="<<n<<" fx="<<fx<<" fy="<<fy<<"\n";
ans=ans+fx+fy;
n/=2;
}
cout<<ans<<"\n";
}
return 0;
}
[ 丛林木马 ]( D-丛林木马_牛客小白月赛44 (nowcoder.com) )
按照样例来看的话,就是每一位的贡献次数是另一个字符串的长度。那么求出这一位的初始贡献*另一个字符串的长度,就是这一位的总贡献/
#include<bits/stdc++.h>
#define ll long long
#define pii pair<long long , long long >
#define se second
#define pb push_back
#define pf push_front
#define si size()
#define db double
#define ls (p<<1)
#define rs (p<<1|1)
#define fi first
#define se second
using namespace std;
ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
inline void Prin(ll x){if(x < 0){putchar('-');x = -x;}if(x > 9) Prin(x / 10);putchar(x % 10 + '0');}
const int qs=1e6+7;
const ll mod=998244353;
ll T,n,x;
string a,b;
int main(){
T=read();
while(T--){
cin>>a>>b;
ll cnt=1,ans=0;
for(int i=a.si-1;i>=0;--i){
ll p=cnt*(a[i]-'0')%mod;
ans=ans+p*b.si%mod;
ans%=mod;
cnt=cnt*10%mod;
}
cnt=1;
for(int i=b.si-1;i>=0;--i){
ll p=cnt*(b[i]-'0')%mod;
ans=ans+p*a.si%mod;
ans%=mod;
cnt=cnt*10%mod;
}
cout<<ans<<"\n";
}
return 0;
}
[ 变异蛮牛 ]( E-变异蛮牛_牛客小白月赛44 (nowcoder.com) )
先dfs染色,求出黑点的个数cnt,手推后发现答案是\(cnt+C_{cnt}^{2}\)。
#include<bits/stdc++.h>
#define ll long long
#define pii pair<long long , long long >
#define se second
#define pb push_back
#define pf push_front
#define si size()
#define db double
#define ls (p<<1)
#define rs (p<<1|1)
#define fi first
#define se second
using namespace std;
ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
inline void Prin(ll x){if(x < 0){putchar('-');x = -x;}if(x > 9) Prin(x / 10);putchar(x % 10 + '0');}
const int qs=2e5+7;
const ll mod=998244353;
int T,n,x;
ll cnt;
vector<int> v[qs];
void dfs(int x,int fa,int dis){
if(dis&1) cnt++;
for(int i=0;i<v[x].si;++i){
int p=v[x][i];
if(p==fa) continue;
dfs(p,x,dis+1);
}
}
int main(){
T=read();
while(T--){
n=read();
cnt=0;
for(int i=1;i<=n;++i) v[i].clear();
ll x,y;
for(int i=1;i<n;++i){
x=read(),y=read();
v[x].pb(y),v[y].pb(x);
}
dfs(1,0,1);
ll ans=cnt+cnt*(cnt-1)/2;
cout<<ans<<"\n";
}
return 0;
}