当前位置:网站首页>[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 49sample output 1:
4sample input 2:
5 2 10 50 110 250sample output 2:
1sample input 3:
6 4 7 12 100 150 199sample 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 1sample output 1:
3sample input 2:
7 1 1 2 3 1 4 3 3 1 1 1 2 3sample 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;
}边栏推荐
- sqlserver对数据进行加密、解密
- [advanced C language] array & pointer & array written test questions
- 【米哈游2023届秋招】开启【校招唯一专属内推码EYTUC】
- 机器人相关课程考核材料归档实施细则2022版本
- 迷失在Mysql的锁世界
- HDU - 2859 Phalanx(DP)
- Zhiyang innovation signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry
- Exclusive interview of open source summer | new committer Xie Qijun of Apache iotdb community
- bizchart+slider实现分组柱状图
- 网上开户哪家证券公司佣金最低,我要开户,网上开户安全吗
猜你喜欢

Nat. Commun.| 机器学习对可突变的治疗性抗体的亲和力和特异性进行共同优化

赋能数字经济 福昕软件出席金砖国家可持续发展高层论坛

玩转gRPC—深入概念与原理

gtest从一无所知到熟练使用(3)什么是test suite和test case

案例分享|金融业数据运营运维一体化建设
![[optimtool.unconstrained] unconstrained optimization toolbox](/img/ef/65379499df205c068ee9bc9df797ac.png)
[optimtool.unconstrained] unconstrained optimization toolbox

How is the entered query SQL statement executed?

Exclusive interview of open source summer | new committer Xie Qijun of Apache iotdb community

CloudCompare&Open3D DBSCAN聚类(非插件式)

Zhiyang innovation signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry
随机推荐
MongoDB中的索引操作总结
《命令行上的数据科学第二版》校对活动重新启动
ACM multimedia 2022 | counterfactual measurement and elimination of social prejudice in visual language pre training model
传智教育|如何转行互联网高薪岗位之一的软件测试?(附软件测试学习路线图)
WebGIS framework -- kalrry
服装企业为什么要谈信息化?
TCP protocol three times handshake process
QT—绘制其他问题
Relational database
力扣_回文数
AscendEX 上线 Walken (WLKN) - 一款卓越领先的“Walk-to-Earn”游戏
并发网络模块化 读书笔记转
Solve the problem of data disorder caused by slow asynchronous interface
Hash table
WebGIS框架---kalrry
并发优化总结
【C语言进阶篇】数组&&指针&&数组笔试题
Enabling digital economy Fuxin software attends the BRICs high level Forum on Sustainable Development
什么是商业智能(BI),就看这篇文章足够了
Representation of confidence interval



