当前位置:网站首页>Acwing game 58
Acwing game 58
2022-07-04 04:36:00 【Changersh】
4488. seek 1
Given a length of n Of 01 Sequence a1,a2,…,an.
Please judge , Whether it contains 1.
Input format
The first line contains an integer n.
The second line contains n It's an integer a1,a2,…,an.
Output format
If the sequence contains 1, The output YES, Otherwise output NO.
Data range
The first three test points meet 1≤n≤3.
All test points meet 1≤n≤100,0≤ai≤1.
sample input 1:
3
0 0 1
sample output 1:
YES
sample input 2:
1
0
sample output 2:
NO
Sign in
// Author: Changersh
// Problem: seek 1
// Contest: AcWing
// URL: https://www.acwing.com/problem/content/4491/
// When: 2022-07-02 19:00:21
//
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include<tr1/unordered_map>
#include <tr1/unordered_set>
using namespace std::tr1;
using namespace std;
typedef long long ll;
const int N = 5e4 + 50;
const int MOD = 1e9 + 7;
int main() {
int n, a;
bool flag = false;
scanf("%d", &n);
for (int i = 0; i < n; i ++) {
scanf("%d", &a);
if (a == 1) flag = 1;
}
if (flag) printf("YES");
else printf("NO");
return 0;
}
4489. The longest subsequence
Given a length of n Strictly monotonically increasing sequence of integers a1,a2,…,an.
Sequence a The subsequence of can be expressed as ai1,ai2,…,aip, among 1≤i1<i2<…<ip≤n.
We hope to find one a The subsequence , Make the subsequence satisfy : about j∈[1,p−1],aij+1≤aij×2 Hang up .
We think , The length is 1 The subsequence of always satisfies the condition .
Please calculate and output the maximum possible length of the subsequence that meets the conditions .
Input format
The first line contains an integer n.
The second line contains n It's an integer a1,a2,…,an.
Output format
An integer , Represents the maximum possible length of the subsequence that meets the condition .
Data range
front 5 Test points meet 1≤n≤10.
All test points meet 1≤n≤2×105,1≤a1<a2<…<an≤109.
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
greedy
The minimum length of subsequence is 1, It's convenient to start with the first number , Compare with the number after it , The conditions are met +1, Count the maximum length every time .
As long as there is dissatisfaction, return to zero , Count from the next digit
Then I put +1 The operation of is put at the end , I'm used to writing greedily
// Author: Changersh
// Problem: The longest subsequence
// Contest: AcWing
// URL: https://www.acwing.com/problem/content/4492/
// When: 2022-07-02 19:03:37
//
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include<tr1/unordered_map>
#include <tr1/unordered_set>
using namespace std::tr1;
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
int T;
void solve() {
}
ll n, s[N], cnt, ans;
int main() {
// scanf("%d", &T);while (T--)solve();
scanf("%lld", &n);
for (int i = 0; i < n; i++)
scanf("%lld", &s[i]);
for (int i = 0; i < n - 1; i++) {
if (s[i] * 2 >= s[i + 1]) {
cnt++;
ans = max(ans, cnt);
}
else {
cnt = 0;
}
}
ans++;
printf("%lld", ans);
return 0;
}
4490. dyeing
Given a n Tree of nodes , Node number is 1∼n.
1 Node number is the root node of the tree .
At the beginning , The color of all nodes is 0.
Now? , You need to re dye the tree , Where nodes i The target color of is ci.
The specific process of each dyeing operation is as follows :
Select a node v And a color x.
Will be in the form of nodes v All nodes in the subtree of the root node ( Including nodes v) All dyed in color x.
Please calculate , In order to make each node be dyed into the target color , At least how many dyeing operations are needed .
Input format
The first line contains integers n.
The second line contains n−1 It's an integer p2,p3,…,pn, among pi Representation node i The parent node number of .
The third line contains n It's an integer c1,c2,…,cn, among ci Representation node i Target color of .
Ensure that the input given graph is a tree .
Output format
An integer , Indicates the minimum number of dyeing operations required .
Data range
The first three test points meet 2≤n≤10.
All test points meet 2≤n≤104,1≤pi<i,1≤ci≤n.
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
Trees + greedy
If a node is different in color from its parent node ,namo You need to dye it again , And then , The parent node must be dyed first , Otherwise, the color of the parent node will overwrite the color of the child node .
It needs to be dyed at least once , As long as the color of the child node is different from that of the parent node , frequency +1
// Author: Changersh
// Problem: dyeing
// Contest: AcWing
// URL: https://www.acwing.com/problem/content/4493/
// When: 2022-07-02 19:16:35
//
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include<tr1/unordered_map>
#include <tr1/unordered_set>
using namespace std::tr1;
using namespace std;
typedef long long ll;
const int N = 1e4 + 5;
const int MOD = 1e9 + 7;
int n, tree[N], col[N];
int main() {
scanf("%d", &n);
for (int i = 2; i <= n; i++) {
scanf("%d", &tree[i]);
}
for (int i = 1; i <= n; i++) {
scanf("%d", &col[i]);
}
int ans = 1;
for (int i = 2; i <= n; i++) {
if (col[i] != col[tree[i]]) {
ans++;
}
}
printf("%d", ans);
return 0;
}
边栏推荐
- AcWing第 58 场周赛
- How to view installed r packages in R language
- tdk-lambda电源主要应用
- Redis:有序集合zset类型数据操作命令
- 统计遗传学:第三章,群体遗传
- Rhcsa 08 - automount configuration
- Leetcode 121 best time to buy and sell stock (simple)
- 牛客小白月赛49
- 博朗与Virgil Abloh于2021年为纪念博朗品牌100周年而联合打造的“功能性艺术”将在博物馆展出Abloh作品期间首次亮相
- Cmake compilation option setting in ros2
猜你喜欢

【云原生】那些看起来很牛X,原理却很简单的一行代码

Leetcode brush questions: binary tree 05 (flip binary tree)

R语言dplyr中的Select函数变量列名

十字路口通行优先权,十字路口通行规则图解

Senior developers tell you, how to write excellent code?

苹果CMS仿西瓜视频大气响应式视频模板源码

NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon

NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线

精品网址导航主题整站源码 wordpress模板 自适应手机端

博朗与Virgil Abloh于2021年为纪念博朗品牌100周年而联合打造的“功能性艺术”将在博物馆展出Abloh作品期间首次亮相
随机推荐
[cloud native] those lines of code that look awesome but have a very simple principle
Leetcode skimming: binary tree 08 (maximum depth of n-ary tree)
RPC技术
Leetcode skimming: binary tree 04 (sequence traversal of binary tree)
牛客小白月赛49
最长递增子序列问题(你真的会了吗)
Rhcsa 07 - user and group management
Intersection traffic priority, illustration of intersection traffic rules
The five pictures tell you: why is there such a big gap between people in the workplace?
资深开发人员告诉你,怎样编写出优秀的代码?
Apple CMS imitation watermelon video atmospheric response video template source code
新手找陪驾要注意什么
十字路口通行优先权,十字路口通行规则图解
Leetcode brush question: binary tree 06 (symmetric binary tree)
Asahi Kasei participated in the 5th China International Import Expo (5th ciie) for the first time
1. Mx6u-alpha development board (LED drive experiment in C language version)
I.MX6U-ALPHA开发板(模仿STM32驱动开发实验)
浅谈一篇优质的小红书文案需要具备什么
B. All Distinct
Y55. Chapter III kubernetes from entry to proficiency -- HPA controller and metrics server (28)