当前位置:网站首页>[acwing] solution of the 58th weekly match
[acwing] solution of the 58th weekly match
2022-07-04 22:12:00 【Xuanche_】
AcWing 4488. seek 1
AC Code
#include <iostream> using namespace std; int main() { int n; cin >> n; bool f = false; while(n -- ) { int num; cin >> num; if(num == 1) f = true; } if(f) puts("YES"); else puts("NO"); return 0; }
AcWing 4489. The longest subsequence
sample input 1:
10 1 2 5 6 7 10 21 23 24 49
sample output 1:
4
sample input 2:
5 2 10 50 110 250
sample output 2:
1
sample input 3:
6 4 7 12 100 150 199
sample output 3:
3
Make full use of Strictly monotonically increasing This condition
about , The next satisfied number should meet these two conditions
We can know from monotonicity , The scope of completely covers , So choosing the following number can make the selection range larger
Sum up , When the following number is less than or equal to twice the previous number , This number is required ( greedy )
AC Code
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 200010;
int a[N];
int main()
{
int res = 0;
int n; cin >> n;
for(int i = 0; i < n; i ++ ) scanf("%d", &a[i]);
for(int i = 0; i < n; i ++ )
{
int j = i + 1;
while(a[j] <= 2 * a[j - 1] && j < n) j ++ ; j -- ;
res = max(res, j - i + 1);
i = j;
}
cout << res << endl;
return 0;
}
AcWing 4490. dyeing
sample input 1:
6 1 2 2 1 5 2 1 1 1 1 1
sample output 1:
3
sample input 2:
7 1 1 2 3 1 4 3 3 1 1 1 2 3
sample output 2:
5
Because the dyeing operation has Coverage , And for a tree ( Son ) Root node of tree Only at the root node This can dye it
If you dye from child nodes , Finally, the coloring when reaching the root node will overwrite the previous operation , dissatisfaction At least operation This is the nature of
So we need to dye from the root node , And then on and on Recursively process each child node to the leaf node ( Greedy thought )
- If the child node and the parent node Same color , There is no need to repeat dyeing
- If the child node and the parent node Different colors , You need one more dyeing operation , ret ++
AC Code
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 1000010;
int n;
int e[N], ne[N], h[N], idx;
int w[N];
int ret;
void add(int a, int b)
{
e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;
}
void dfs(int u)
{
if(u == 1) ret ++ ;
// Leaf nodes
if(h[u] == -1) return;
for(int i = h[u]; ~i; i = ne[i])
{
// Root node
int j = e[i];
if(h[j] == -1)
{
if(w[j] != w[u]) ret ++ ;
}
else
{
// Not the root node
if(w[j] != w[u]) ret ++ ;
dfs(j);
}
}
return ;
}
int main()
{
cin >> n;
memset(h, -1, sizeof h);
for(int i = 2; i <= n; i ++ )
{
int p; cin >> p;
add(p, i);
}
for(int i = 1; i <= n; i ++ )
{
cin >> w[i];
}
dfs(1);
cout << ret << endl;
return 0;
}
边栏推荐
- Xiangjiang Kunpeng joined the shengteng Wanli partnership program and continued to write a new chapter of cooperation with Huawei
- sqlserver对数据进行加密、解密
- Open3D 曲面法向量计算
- HUAWEI nova 10系列发布 华为应用市场筑牢应用安全防火墙
- 赋能数字经济 福昕软件出席金砖国家可持续发展高层论坛
- NAACL-22 | 在基于Prompt的文本生成任务上引入迁移学习的设置
- Machine learning notes mutual information
- Operation of adding material schedule in SolidWorks drawing
- Nat. Commun.| Machine learning jointly optimizes the affinity and specificity of mutagenic therapeutic antibodies
- Radio and television Wuzhou signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry
猜你喜欢
力扣98:验证二叉搜索树
智洋创新与华为签署合作协议,共同推进昇腾AI产业持续发展
赋能数字经济 福昕软件出席金砖国家可持续发展高层论坛
Redis has three methods for checking big keys, which are necessary for optimization
并发网络模块化 读书笔记转
Bizchart+slider to realize grouping histogram
Sorting and sharing of selected papers, systems and applications related to the most comprehensive mixed expert (MOE) model in history
DevEco Device Tool 3.0 Release带来5大能力升级,让智能设备开发更高效
MongoDB聚合操作总结
QT—绘制其他问题
随机推荐
并发网络模块化 读书笔记转
我在linux里面 通过调用odspcmd 查询数据库信息 怎么静默输出 就是只输出值 不要这个
服务线上治理
GTEST from ignorance to skillful use (1) GTEST installation
WebGIS framework -- kalrry
历史最全混合专家(MOE)模型相关精选论文、系统、应用整理分享
常用的开源无代码测试工具
ApacheCN 翻译、校对、笔记整理活动进度公告 2022.7
Which securities company is better to open an account? Is online account opening safe
湘江鲲鹏加入昇腾万里伙伴计划,与华为续写合作新篇章
# 2156. 查找给定哈希值的子串-后序遍历
文件读取写入
Éducation à la transmission du savoir | Comment passer à un test logiciel pour l'un des postes les mieux rémunérés sur Internet? (joindre la Feuille de route pour l'apprentissage des tests logiciels)
2022 version of stronger jsonpath compatibility and performance test (snack3, fastjson2, jayway.jsonpath)
HDU - 1078 FatMouse and Cheese(记忆化搜索DP)
vim 从嫌弃到依赖(23)——最后的闲扯
【C语言进阶篇】数组&&指针&&数组笔试题
Super detailed tutorial, an introduction to istio Architecture Principle and practical application
Nat. Commun.| Machine learning jointly optimizes the affinity and specificity of mutagenic therapeutic antibodies
GTEST from ignorance to proficiency (4) how to write unit tests with GTEST