当前位置:网站首页>[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;
}
边栏推荐
- 1807. Replace the parentheses in the string
- Master the use of auto analyze in data warehouse
- HBuilder X 常用的快捷键
- PMO:比较25种分子优化方法的样本效率
- 制作条形码的手机App推荐
- AscendEX 上线 Walken (WLKN) - 一款卓越领先的“Walk-to-Earn”游戏
- Representation of confidence interval
- sqlserver对数据进行加密、解密
- 好用app推荐:扫描二维码、扫描条形码并查看历史
- A large number of virtual anchors in station B were collectively forced to refund: revenue evaporated, but they still owe station B; Jobs was posthumously awarded the U.S. presidential medal of freedo
猜你喜欢
Operation of adding material schedule in SolidWorks drawing
Use blocconsumer to build responsive components and monitor status at the same time
B站大量虚拟主播被集体强制退款:收入蒸发,还倒欠B站;乔布斯被追授美国总统自由勋章;Grafana 9 发布|极客头条
Sorting and sharing of selected papers, systems and applications related to the most comprehensive mixed expert (MOE) model in history
El tree combined with El table, tree adding and modifying operations
Locust性能测试 —— 环境搭建及使用
玩转gRPC—深入概念与原理
MongoDB聚合操作总结
Redis 排查大 key 的3种方法,优化必备
赋能数字经济 福昕软件出席金砖国家可持续发展高层论坛
随机推荐
Cloudcompare & open3d DBSCAN clustering (non plug-in)
Hash table
ACM multimedia 2022 | counterfactual measurement and elimination of social prejudice in visual language pre training model
力扣2_1480. 一维数组的动态和
《命令行上的数据科学第二版》校对活动重新启动
Is it safe to open an account in the stock of Caicai college? Can you only open an account by digging money?
Implementation rules for archiving assessment materials of robot related courses 2022 version
From repvgg to mobileone, including mobileone code
现在mysql cdc2.1版本在解析值为0000-00-00 00:00:00的datetime类
PostgreSQL基本结构——表
Ascendex launched Walken (WLKN) - an excellent and leading "walk to earn" game
删库不必跑路!详解 MySQL 数据恢复
vim 从嫌弃到依赖(23)——最后的闲扯
置信区间的画法
并发优化总结
leetcode 72. Edit Distance 编辑距离(中等)
【米哈游2023届秋招】开启【校招唯一专属内推码EYTUC】
Go language loop statement (3 in Lesson 10)
网上开户哪家证券公司佣金最低,我要开户,网上开户安全吗
Use blocconsumer to build responsive components and monitor status at the same time