目录

A

输出最大值减最小值,或者排序算一下答案

#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
#define inf 0x3f3f3f3f*1ll using namespace std; void solve()
{
int n;
cin>>n;
vector<int>a(n+1);
rep(i,1,n){
cin>>a[i];
}
sort(a.begin()+1,a.end());
int res=0;
rep(i,2,n){
res+=a[i]-a[i-1];
}
cout<<res<<endl;
} signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}

B

B还wa了一发,有点难受一开始推错了,写的太慢了

思路:

考虑对答案能贡献2的放格有多少个。

上面一行\(n\)个能对答案贡献\(2\),下面一行除了两端的两个都能对答案贡献2

所以一共能贡献2的方格有\(2 * n-2\)个

#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
#define inf 0x3f3f3f3f*1ll using namespace std; void solve()
{
int n,k;
cin>>n>>k;
int num2=2*n-2;
if(k>2*num2){
cout<<num2+k-num2*2<<endl;
}else{
cout<<k/2+(k%2!=0)<<endl;
}
} signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}

C

c题溢出了中间应该提前结束

推公式

考虑每次的下注如果在这一轮赢得话就要把之前所有输的钱全部赢回来有点类似倍投的思想】

从一1开始,之前的下注总和记为\(sum\)

下一轮下注要下\(sum/(k-1)+1\)才能赢钱

中间如果\(sum>a\)的话要提前结束,说明下不到就会没钱了

#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
#define inf 0x3f3f3f3f*1ll using namespace std; void solve()
{
int k,x,a;
cin>>k>>x>>a;
int sum=0;
rep(i,1,x){
if(sum>a){
cout<<"NO"<<endl;
return;
}
sum+=sum/(k-1)+1;
}
if((a-sum)*(k-1)>sum){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
} signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}

D

树形dp思路参考的是b站的一个题解

这题和c题的题目描述感觉都有点抽象很难懂。

题意:让我们求点集的方案数,点集中没有3个点在一条直线。

\(f[u][0]:表示以u为根节点的子树中,危险结点数为0个的方案总数\)

\(f[u][1]:表示以u为根节点的子树中,危险结点数为1个的方案总数\)

\(f[u][2]:表示以u为根节点的子树中,危险结点数为2个的方案总数\)

考虑状态转移

\(f[u][0]=1\)只能当前u这个结点是危险结点时,满足

\(f[u][1] * =(f[v][0]+f[v][1])\)当前结点可能是危险结点,也可能不是,

如果是危险结点那么上一个结点就不是危险结点,如果当前结点不是危险结点,那么上一个一定是危险结点

\(f[u][2]=(f[u][2]+f[u][1])\):讨论同\(f[u][1]\)

#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back using namespace std;
const int mod=998244353;
void solve() {
int n;
cin>>n;
vector<vector<int>>g(n+1);
rep(i,1,n-1){
int u,v;
cin>>u>>v;
g[u].pb(v);
g[v].pb(u);
}
vector<vector<int>>f(n+1,vector<int>(3));
auto dfs=[&](auto &&dfs,int u,int fa)->void{
f[u][0]=1;f[u][1]=1;
for(auto v:g[u]){
if(v==fa){
continue;
}
dfs(dfs,v,u);
f[u][1]*=(f[v][0]+f[v][1]);
f[u][2]+=f[v][2]+f[v][1];
rep(i,0,2){
f[u][i]=(f[u][i]+mod)%mod;
}
}
};
dfs(dfs,1,-1);
int ans=0;
rep(i,0,2){
ans=(ans+f[1][i])%mod;
}
cout<<(ans+mod)%mod<<endl;
} signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
cin>>_;
while(_--)
solve();
return 0;
}

Codeforces Round 926 (Div. 2)(A~D)的更多相关文章

  1. Codeforces Round #316 (Div. 2) (ABC题)

    A - Elections 题意: 每一场城市选举的结果,第一关键字是票数(降序),第二关键字是序号(升序),第一位获得胜利. 最后的选举结果,第一关键字是获胜城市数(降序),第二关键字是序号(升序) ...

  2. Codeforces Round #240 (Div. 2)(A -- D)

    点我看题目 A. Mashmokh and Lights time limit per test:1 secondmemory limit per test:256 megabytesinput:st ...

  3. Codeforces Round #324 (Div. 2) (哥德巴赫猜想)

    题目:http://codeforces.com/problemset/problem/584/D 思路: 关于偶数的哥德巴赫猜想:任一大于2的偶数都可写成两个素数之和. 关于奇数的哥德巴赫猜想:任一 ...

  4. Codeforces Round #395 (Div. 2)(未完)

    2.2.2017 9:35~11:35 A - Taymyr is calling you 直接模拟 #include <iostream> #include <cstdio> ...

  5. B. Nirvana Codeforces Round #549 (Div. 2) (递归dfs)

    ---恢复内容开始--- Kurt reaches nirvana when he finds the product of all the digits of some positive integ ...

  6. 【Codeforces】Codeforces Round #491 (Div. 2) (Contest 991)

    题目 传送门:QWQ A:A - If at first you don't succeed... 分析: 按照题意模拟 代码: #include <bits/stdc++.h> usin ...

  7. 【Codeforces】Codeforces Round #492 (Div. 2) (Contest 996)

    题目 传送门:QWQ A:A - Hit the Lottery 分析: 大水题 模拟 代码: #include <bits/stdc++.h> using namespace std; ...

  8. Codeforces Round #671 (Div. 2) (A~E)

    Link~ 题面差评,整场都在读题 A 根据奇偶性判断一下即可. #include<bits/stdc++.h> #define ll long long #define N #defin ...

  9. Codeforces Round #524 (Div. 2)(前三题题解)

    这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...

  10. Codeforces Round #624 (Div. 3)(题解)

    Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...

随机推荐

  1. 8.1 Windows驱动开发:内核文件读写系列函数

    在应用层下的文件操作只需要调用微软应用层下的API函数及C库标准函数即可,而如果在内核中读写文件则应用层的API显然是无法被使用的,内核层需要使用内核专有API,某些应用层下的API只需要增加Zw开头 ...

  2. 关闭表单验证/关闭控制台async-validator警告

    找到util.js node_modules -> async-validator -> es -> util.js 将console.warn(type, errors)注释 如果 ...

  3. [vue] 脚手架笔记

    笔记 脚手架文件结构 ├── node_modules ├── public │ ├── favicon.ico: 页签图标 │ └── index.html: 主页面 ├── src │ ├── a ...

  4. 多进程实现socket通信(Python)

    服务器端: #__author__:Kelvin #date:2020/5/9 11:35 import socket from multiprocessing import Process def ...

  5. 小知识:Oracle RAC添加服务名实现单节点访问

    环境:Oracle 11.2.0.4 RAC(2 nodes) 1.查看RAC IP配置信息 2.添加服务名并启动服务 3.停止服务并删除服务名 1.查看RAC IP配置信息 我们先查看下环境的IP分 ...

  6. .NET Core开发实战(第2课:内容综述)--学习笔记

    02 | 内容综述 课程目标 掌握 .NET Core 微服务架构的最佳实践 成长为一个具备良好架构设计能力的架构师 课程内容 第一部分 .NET Core 的必备知识 第二部分 .NET Core ...

  7. Hadoop-基础知识面试题

    1.Hadoop集群的最主要瓶颈 磁盘IO 2.Hadoop三大组件 (1).HDFS HDFS(Hadoop Distributed File System)是 Hadoop 项目的核心子项目,主要 ...

  8. Python实现冒泡排序、选择排序、插入排序

    排序与搜索 排序算法(英语:Sorting algorithm)是一种能将一串数据依照特定顺序进行排列的一种算法. 排序算法的稳定性 稳定性:稳定排序算法会让原本有相等键值的纪录维持相对次序.也就是如 ...

  9. JS leetcode 旋转数组 题解分析

    壹 ❀ 引 今天来做一道同样简单,但是挺有趣的题,题目来自leetcode189. 旋转数组,题目描述如下: 给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数. 示例 1: 输入: ...

  10. CF1833G Ksyusha and Chinchilla

    题目链接 题解 知识点:贪心,树形dp. 当 \(3 \not \mid n\) 时,显然无解. 考虑一种贪心策略,从叶子节点往上只,要以当前节点为根的子树大小能被 \(3\) 整除,就立刻切除这棵子 ...