Codeforces Round 926 (Div. 2)(A-D)

A:Sasha and the Beautiful Array

排序,答案就是最大减最小值

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long
typedef pair<int,int>pii;
#define N 310000
int a[N],b[N];
void solve(){
   int n;
   cin>>n;
   for(int i=0;i<n;i++) cin>>a[i];
   sort(a,a+n);
   cout<<a[n-1]-a[0]<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t=1;
    cin>>t;
   // init();
    while(t--){
        solve();
    }
}

B:Sasha and the Drawing

共有4n-2个对角线

你发现图一个可以增加两个格子共2n-2个剩下都是一个的格子

如果是奇数向上取整

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long
typedef pair<int,int>pii;
#define N 310000
int a[N],b[N];
void solve(){
   int n,k;
   cin>>n>>k;
    if(4*n-2==k) k+=2;
    if(k%2==1) k+=1;
    k/=2;
    cout<<k<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t=1;
    cin>>t;
   // init();
    while(t--){
        solve();
    }
}

C:Sasha and the Casino

常识题,你去赌博肯定是想这一次赢回来,所以每次投资都要赢回来之前的多一点,数学模拟就行

每次比上次多一点,让他不让你赢,后面越拿越多只要你能拿回本就行

sum+now>now*k

now>sum/(k-1)->now=sum/(k-1)+1只要能拿出即可

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long
typedef pair<int,int>pii;
#define N 310000
int a[N],b[N];
void solve(){
   int k,x,a;
   cin>>k>>x>>a;
   int sum=1;
   k--;
   for(int i=0;i<x;i++){
   	   sum+=sum/k+1;
   	   if(sum>a) {
   	      cout<<"No"<<endl;
		  return ;  	
	   }
   }
   cout<<"YES"<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t=1;
    cin>>t;
   // init();
    while(t--){
        solve();
    }
}

D:Sasha and a Walk in the City

树形结构dp并且进行组合

两种情况:1.所有链选的点不超过一2.存在选中两个点的链

f[u]表示非空点集一条链最多选一个点

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long
typedef pair<int,int>pii;
#define N 310000
//int a[N],b[N];
vector<int>g[N];
int f[N];//子树至少一个点没有两个点在一条链
int mod=998244353;
void solve(){
   int n;
   cin>>n;
   int ans=0;
   for(int i=0;i<=n;i++) g[i].clear(),f[i]=0;
   for(int i=0;i<n-1;i++){
   	   int a,b;
   	   cin>>a>>b;
   	   g[a].push_back(b);
   	   g[b].push_back(a);
   }
    function<void(int ,int)>dfs=[&](int u,int fa){
   	    f[u]=1;//如果u选了,子树都不选,没选,子树至少选一个
   	    for(auto x:g[u]){
   	        if(x==fa) continue;
			   dfs(x,u);
			   f[u]=(f[u]*(f[x]+1))%mod;
			   ans+=f[x];	
		}
    };
    dfs(1,0);
   /* for(int i=1;i<=n;i++) cout<<f[i]<<" ";
    cout<<endl;*/
    ans=(ans+f[1]+1)%mod;
    cout<<ans<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t=1;
    cin>>t;
   // init();
    while(t--){
        solve();
    }
}

  • 10
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

多年以后

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值