当前位置:网站首页>Acwing week 58
Acwing week 58
2022-07-06 04:47:00 【Zqchang】
List of articles
The longest subsequence
This is a greedy question , Greedy heel dp It's very similar , That is, we can also divide all subsets into several categories , If proved , The answer must be in a certain category , This is greed , If you find that the answer is not in a certain category , If each category requires , Namely dp
This topic is not difficult to understand , The fun part is , Its proof , How to prove that the answer must be continuous
hypothesis a i a_i ai and a k a_k ak In the subsequence of answers , however a j a_j aj be not in , Prove whether it is true 

That's how it turns out , The result is a j a_j aj eligible , You can put it in the answer , Then contradict the assumption , So the answer must be a large continuous segment , Then double pointer scan once
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
const int N = 200010;
int n;
int w[N];
signed main()
{
cin >> n;
for(int i=1; i<=n; i++) cin >> w[i];
int res = 0;
for(int i=1; i<=n; i++)
{
int j = i + 1;
while(j <= n && w[j] <= w[j - 1] * 2) j++;// Here is the enumeration to the j individual , The first j If not, quit , So let's go straight to i - j
res = max(res, j - i);
i = j - 1;
}
cout << res << endl;
return 0;
}
dyeing
dyeing
It means , Dye a tree with the specified color , How many steps does it take to ask , When dyeing , One point , Including its subtree will be dyed , therefore , Whenever a root node is dyed , All operations before its subtree are invalid , So it must be from top to bottom , Dye the root node first , Then check whether the color of the child node is consistent with that of the root node , If not, dye , If you agree, look at the child nodes
So there are two ways , The first is to build drawings , Then record the color of the parent node every time , If it is different from the child node, dye it , In this way
The second is not to build a map , Directly see how many points are different from the color of child nodes , So you have to dye once , Finally, add an operation of the root node , That's the answer.
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define int long long
const int N = 10010;
int n;
int p[N], c[N];
signed main()
{
fast;
cin >> n;
for(int i=2; i<=n; i++) cin >> p[i];
for(int i=1; i<=n; i++) cin >> c[i];
int res = 0;
for(int i=1; i<=n; i++)
if(c[i] != c[p[i]]) res ++;
cout << res << endl;
return 0;
}
D - Trophy
Write a handy abc, It's all about water , The reason for writing is because , There are some small points , I didn't notice before , such as ,long long The maximum range of is 9e18 many
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <cstring>
#include <cmath>
#include <stack>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define sc(a) scanf("%lld",&a)
#define pf(a) printf("%d",a)
#define endl "\n"
#define int long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define LL long long
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define x first
#define y second
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
int a[N], b[N];
int suma[N], sumb[N];
int res[N];
signed main()
{
fast;
int n, x;
cin >> n >> x;
int ans = 8e18;
for(int i=1; i<=n; i++)
{
cin >> a[i] >> b[i];
suma[i] = suma[i-1] + a[i];
sumb[i] = sumb[i-1] + b[i];
res[i] = suma[i] + sumb[i] + b[i] * (x - i);
}
for(int i=1; i<=n; i++)
{
if(i > x) break;// Note that if x Than i Big to break, Because I can't go so far
ans = min(ans, res[i]);
}
cout << ans << endl;
return 0;
}
边栏推荐
- Leetcode 186 Flip the word II in the string (2022.07.05)
- Guitar Pro 8.0最详细全面的更新内容及全部功能介绍
- [Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity
- Etcd database source code analysis -- etcdserver bootstrap initialization storage
- Zynq learning notes (3) - partial reconfiguration
- Yyds dry goods inventory OSI & tcp/ip
- [05-1, 05-02, 05-03] network protocol
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- What should the project manager do if there is something wrong with team collaboration?
- Delete subsequence < daily question >
猜你喜欢

Use sentinel to interface locally

Introduction of several RS485 isolated communication schemes

Case of Jiecode empowerment: professional training, technical support, and multiple measures to promote graduates to build smart campus completion system

The IPO of mesk Electronics was terminated: Henan assets, which was once intended to raise 800 million yuan, was a shareholder

Weng Kai C language third week 3.1 punch in
![[数学建模] 微分方程--捕鱼业的持续发展](/img/7c/2ab6f2a34bc2c97318537ec8e0b0c5.png)
[数学建模] 微分方程--捕鱼业的持续发展

Patent | subject classification method based on graph convolution neural network fusion of multiple human brain maps

SQL注入漏洞(MSSQL注入)

Etcd database source code analysis -- etcdserver bootstrap initialization storage

Postman管理测试用例
随机推荐
Platformio create libopencm3 + FreeRTOS project
Postman前置脚本-全局变量和环境变量
Etcd database source code analysis -- etcdserver bootstrap initialization storage
On the solution of es8316's audio burst
coreldraw2022新版本新功能介绍cdr2022
Is the mode of education together - on campus + off campus reliable
MIT CMS. 300 session 8 – immersion / immersion
How does vs change the project type?
Excellent PM must experience these three levels of transformation!
Codeforces Round #804 (Div. 2)
Case of Jiecode empowerment: professional training, technical support, and multiple measures to promote graduates to build smart campus completion system
It is also a small summary in learning
L'introduction en bourse de MSK Electronics a pris fin: 800 millions de RMB d'actifs de Henan étaient des actionnaires
The most detailed and comprehensive update content and all functions of guitar pro 8.0
SharedPreferences source code analysis
Database - MySQL storage engine (deadlock)
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
程序员在互联网行业的地位 | 每日趣闻
Distributed transaction solution
二叉树基本知识和例题