当前位置:网站首页>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;
}
边栏推荐
- Keysight n9320b RF spectrum analyzer solves tire pressure monitoring scheme
- Intersection traffic priority, illustration of intersection traffic rules
- Application scheme of Puyuan ds1000z series digital oscilloscope in communication principle experiment
- Experience sharing of epidemic telecommuting | community essay solicitation
- 仿《游戏鸟》源码 手游发号评测开服开测合集专区游戏下载网站模板
- Emlog用户注册插件 价值80元
- Dry goods | detailed explanation of webshell Foundation
- Rhcsa 06 - suid, sgid, sticky bit (to be added)
- Use NRM and NVM to manage your NPM source and node versions
- UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x98 in position 1093: illegal multibyte sequence
猜你喜欢

RPC Technology

leetcode:1314. 矩阵区域和【二维前缀和模板】
![[microservice openfeign] @feignclient detailed explanation](/img/8d/83bcde1355366c7c88a7a9ade7f9eb.png)
[microservice openfeign] @feignclient detailed explanation

牛客小白月赛49

A beautiful API document generation tool

Experience sharing of epidemic telecommuting | community essay solicitation

Apple CMS imitation watermelon video atmospheric response video template source code

6-5漏洞利用-SSH弱口令破解利用

Redis: hash type data operation command

Ppt tutorial, how to save a presentation as a PDF file in PowerPoint?
随机推荐
陪驾注意事项 这23点要注意!
Leetcode brush question: binary tree 06 (symmetric binary tree)
Eig launched Grupo Cerro, a renewable energy platform in Chile
6-4漏洞利用-SSH Banner信息获取
Operation of ES6
[microservice openfeign] @feignclient detailed explanation
[security attack and Defense] how much do you know about serialization and deserialization?
Why use node
How to view installed r packages in R language
Architecture practice camp - graduation project of module 9 of phase 6
架构实战营 - 第 6 期 模块九之毕业设计
多位科技公司创始人向Entrepreneur First提供高达1.58亿美元的C轮融资,协助其投资下一代全球创新者
Intersection traffic priority, illustration of intersection traffic rules
Rhcsa 06 - suid, sgid, sticky bit (to be added)
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
“找工作不要太在意工资”,这是我听过最大的谎言
[cloud native] those lines of code that look awesome but have a very simple principle
什么是上下文?
leetcode 121 Best Time to Buy and Sell Stock 买卖股票的最佳时机(简单)
The "functional art" jointly created by Bolang and Virgil abloh in 2021 to commemorate the 100th anniversary of Bolang brand will debut during the exhibition of abloh's works in the museum