Codeforces Round 926 (Div. 2)(A~D)
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)的更多相关文章
- Codeforces Round #316 (Div. 2) (ABC题)
A - Elections 题意: 每一场城市选举的结果,第一关键字是票数(降序),第二关键字是序号(升序),第一位获得胜利. 最后的选举结果,第一关键字是获胜城市数(降序),第二关键字是序号(升序) ...
- Codeforces Round #240 (Div. 2)(A -- D)
点我看题目 A. Mashmokh and Lights time limit per test:1 secondmemory limit per test:256 megabytesinput:st ...
- Codeforces Round #324 (Div. 2) (哥德巴赫猜想)
题目:http://codeforces.com/problemset/problem/584/D 思路: 关于偶数的哥德巴赫猜想:任一大于2的偶数都可写成两个素数之和. 关于奇数的哥德巴赫猜想:任一 ...
- Codeforces Round #395 (Div. 2)(未完)
2.2.2017 9:35~11:35 A - Taymyr is calling you 直接模拟 #include <iostream> #include <cstdio> ...
- B. Nirvana Codeforces Round #549 (Div. 2) (递归dfs)
---恢复内容开始--- Kurt reaches nirvana when he finds the product of all the digits of some positive integ ...
- 【Codeforces】Codeforces Round #491 (Div. 2) (Contest 991)
题目 传送门:QWQ A:A - If at first you don't succeed... 分析: 按照题意模拟 代码: #include <bits/stdc++.h> usin ...
- 【Codeforces】Codeforces Round #492 (Div. 2) (Contest 996)
题目 传送门:QWQ A:A - Hit the Lottery 分析: 大水题 模拟 代码: #include <bits/stdc++.h> using namespace std; ...
- Codeforces Round #671 (Div. 2) (A~E)
Link~ 题面差评,整场都在读题 A 根据奇偶性判断一下即可. #include<bits/stdc++.h> #define ll long long #define N #defin ...
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- Codeforces Round #624 (Div. 3)(题解)
Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...
随机推荐
- LINUX安装和配置
本篇文章为本人从零开始学习linux的学习心得,其中包含了 部署虚拟环境安装linux系统 .其中若有错误之处,请读者积极指出,让本人与读者共同进步. 第一章 部署虚拟环境安装linux系统及配置网路 ...
- OpenIM (Open-Source Instant Messaging) Mac Deployment Guide
This guide provides step-by-step instructions for deploying OpenIM on a Mac, including both source c ...
- VLE基于预训练文本和图像编码器的图像-文本多模态理解模型:支持视觉问答、图文匹配、图片分类、常识推理等
VLE基于预训练文本和图像编码器的图像-文本多模态理解模型:支持视觉问答.图文匹配.图片分类.常识推理等 多模态预训练模型通过在多种模态的大规模数据上的预训练,可以综合利用来自不同模态的信息,执行各种 ...
- 深度学习应用篇-元学习[14]:基于优化的元学习-MAML模型、LEO模型、Reptile模型
深度学习应用篇-元学习[14]:基于优化的元学习-MAML模型.LEO模型.Reptile模型 1.Model-Agnostic Meta-Learning Model-Agnostic Meta-L ...
- 3.2 IDAPro脚本IDC常用函数
IDA Pro内置的IDC脚本语言是一种灵活的.C语言风格的脚本语言,旨在帮助逆向工程师更轻松地进行反汇编和静态分析.IDC脚本语言支持变量.表达式.循环.分支.函数等C语言中的常见语法结构,并且还提 ...
- 苹果正在测试新款Mac mini:搭载M3芯片 配备24GB大内存
据悉苹果目前正在测试新的Mac机型,亮点是采用最新的M3芯片. 据报道,首款搭载M3芯片的设备应该是13英寸的MacBook Pro和重新设计的MacBook Air,Mac mini机型并不在名单上 ...
- UVA12655 Trucks 题解
题目传送门 前言 中文题目可以看 link . 前置知识 Kruskal 重构树 | 最近公共祖先 简化题意 给定一个 \(N\) 个点 \(M\) 条边的有向图,共有 \(S\) 次询问,每次询问从 ...
- NC14419 线路规划
题目链接 题目 题目描述 Q国的监察院是一个神秘的组织. 这个组织掌握了整个帝国的地下力量,监察着Q国的每一个人. 监察院一共有N个成员,每一个成员都有且仅有1个直接上司,而他只听从其上直接司的命令. ...
- NC16527 [NOIP2013]货车运输
题目链接 题目 题目描述 A 国有 n 座城市,编号从 1 到 n ,城市之间有 m 条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有 q 辆货车在运输货物, 司机们想知道每辆车在不超过车辆 ...
- NC24858 [USACO 2009 Nov S]Job Hunt
题目链接 题目 题目描述 Bessie is running out of money and is searching for jobs. Farmer John knows this and wa ...