CODEFORCES ROUND #740 ANALYSES BY TEAM:RED & BLACK
Problems: 给你一个数n和代价分别为a, b, c、数量不限的1, 2, 3,求将n凑成4的倍数的最小代价
Analysis:
cj:取个模随便凑一凑就好
Tags: Implementation
#define PRON "pa"
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll; inline ll _min(ll a, ll b, ll c){
return min(a, min(b, c));
} int main(){
ll n, a, b, c;
cin >> n >> a >> b >> c; ll r = n % , ans = ;
if (r == )
ans = _min( * a, a + b, c);
if (r == )
ans = _min( * a, b, c * );
if (r == )
ans = _min(a, b * + c, c * ); cout << ans;
}
code by cj
Problems: 一个数列,每次操作选择一个区间[l, r];若a[i]被选择了b[i]次,则Alyona的幸福值增加a[i] * b[i];保留一些操作使得最后幸福值最高。
Analysis:
cj:对于每次操作,对于幸福值的贡献是sum{a[l], a[l + 1], ... , a[r]},只要贡献是正的的操作就保留
Tags: Implementation
#define PRON "pb"
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll; const int maxn = + ; int n, m, a[maxn]; int main(){
#ifndef ONLINE_JUDGE
freopen(PRON ".in", "r", stdin);
#endif cin >> n >> m;
for (int i = ; i <= n; i ++)
cin >> a[i]; int ans = , temp, l, r;
while (m --){
cin >> l >> r; temp = ;
for (int i = l; i <= r; i ++)
temp += a[i];
if (temp > )
ans += temp;
} cout << ans << endl;
}
code by cj
Problems: 给定m个区间,构造一个长度为n的数列,使得每个区间的mex的最小值最大。
Analysis:
cj:首先这个mex的最小值的最大值显然是min_mex = min{r[i] - l[i] + 1};最简单的构造办法就是用{1, 2, 3 ..., min_mex - 1}来填充这个数列。
Tags: Constructive Algorithms
#define PRON "pc"
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll; const int maxn = 2e5 + ; int n, m;
pair<int, int> a[maxn]; bool cmp(pair<int, int> A, pair<int, int> B){
return A.second - A.first < B.second - B.first;
} int main(){
#ifndef ONLINE_JUDGE
freopen(PRON ".in", "r", stdin);
#endif cin >> n >> m; int mex = inf;
for (int i = ; i < m; i ++){
cin >> a[i].first >> a[i].second;
mex = min(mex, + a[i].second - a[i].first);
} cout << mex << endl; for (int i = ; i <= n; i ++)
cout << i % mex << " ";
cout << endl;
}
code by cj
Problems: 一棵以1为根的树和各边的长度,给定每个点有一个值a。当dis(v, u) < a[u]并且u在v的子树中就认为u控制了v。问每个点控制了多少个点。
Analysis:
cj:dis(v, u) < a[u]可以变成d[u] - d[v] < a[u],即:d[v] > d[u] - a[u],其中d[i]表示dis(1, i)。用vector来维护dfs序,显然d是递增的,所以每次二分查找这个v,使得v以上的所以点都不能控制u,以下的点都可以控制u。用数组c来记录答案,初值赋1,装作能被控制的样子,对于一个点x,c[x] = sum{c[i]},i是x的子树中的点。所以当查找到v之后,将这条链上v的亲爸爸的c减1,这样的话更新答案的时候就不会加上这个点及其以上的点。最后输出c[i] - 1即可。
Tags: binary search, dfs
#define PRON "pd"
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll; const int maxn = 2e5 + ; struct Edge {
int to, d;
Edge * next;
} e[maxn], * head[maxn]; vector<int> q;
vector<ll> dis;
int n, ne = , a[maxn], c[maxn];
ll d[maxn]; inline void add_edge(int f, int to, int d){
e[ne].to = to, e[ne].d = d;
e[ne].next = head[f];
head[f] = e + ne ++;
} void dfs(int u){
for (Edge * p = head[u]; p; p = p -> next){
d[p -> to] = d[u] + (ll)p -> d;
dfs(p -> to);
}
} void solve(int u){
c[u] = ;
q.push_back(u);
dis.push_back(d[u]); int anc = lower_bound(dis.begin(), dis.end(), d[u] - (ll)a[u]) - dis.begin(); if (anc >= )
c[q[anc - ]] --; for (Edge * p = head[u]; p; p = p -> next){
solve(p -> to);
c[u] += c[p -> to];
} q.pop_back();
dis.pop_back();
} int main(){
#ifndef ONLINE_JUDGE
freopen(PRON ".in", "r", stdin);
#endif scanf("%d", &n);
for (int i = ; i <= n; i ++)
scanf("%d", &a[i]); int fa, dis;
for (int i = ; i <= n; i ++){
scanf("%d %d", &fa, &dis);
add_edge(fa, i, dis);
} d[] = ;
dfs();
solve(); for (int i = ; i <= n; i ++)
printf("%d ", c[i] - );
printf("\n");
}
code by cj
Problems:给一个数列a,每次操作让[l, r]上的数增加的,每次操作后求满足al < al + 1 < al + 2 < ... < ak > ak + 1 > ak + 2 > ... > ar的最大区间长度。
Analysis:
cj:把数列换成差,这样的话每次区间修改操作,因为区间中的差是不变的,只有diff(arr[l - 1], arr[l])增加了d,diff(arr[r], arr[r + 1])减少了d,所以就变成了修改两个点的操作。用线段树维护一下就好了。不过要注意一下int要爆炸...并且要特判n = 1的情况。
Tags: Data structure
#define PRON "740e"
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define inf 0x3f3f3f3f
#define ls root << 1
#define rs root << 1 | 1
#define mid ((l + r) >> 1)
#ifdef UNIX
#define LL "%lld"
#else
#define LL "%I64d"
#endif
using namespace std;
typedef long long ll; const int maxn = 3e5 + ; struct node {
int lans, rans, ans;
} t[maxn << ]; int n, m;
ll arr[maxn], a[maxn]; void push_up(int l, int r, int root){
t[root].ans = max(t[ls].ans, t[rs].ans);
t[root].lans = t[ls].lans;
t[root].rans = t[rs].rans; if ((a[mid] > && a[mid + ] != ) || (a[mid] < && a[mid + ] < )){
t[root].ans = max(t[root].ans, t[ls].rans + t[rs].lans);
if (mid - l + == t[ls].lans)
t[root].lans = t[ls].lans + t[rs].lans;
if (r - mid == t[rs].rans)
t[root].rans = t[ls].rans + t[rs].rans;
}
} void build_tree(int l, int r, int root){
if (l == r){
t[root].ans = t[root].lans = t[root].rans = a[l] ? : ;
return;
} build_tree(l, mid, ls);
build_tree(mid + , r, rs); push_up(l, r, root);
} void update(int l, int r, int pos, int root){
if (l == r && l == pos){
t[root].ans = t[root].lans = t[root].rans = a[l] ? : ;
return;
} if (l <= pos && pos <= mid)
update(l, mid, pos, ls);
else
update(mid + , r, pos, rs); push_up(l, r, root);
} int main(){
#ifndef ONLINE_JUDGE
freopen(PRON ".in", "r", stdin);
#endif scanf("%d", &n);
for (int i = ; i < n; i ++){
scanf(LL, &arr[i]);
if (i)
a[i] = arr[i] - arr[i - ];
} if (n != )
build_tree(, n - , ); int l, r, d;
scanf("%d", &m);
while (m --){
scanf("%d %d %d", &l, &r, &d);
if (n == ){
printf("1\n");
continue;
}
if (l > ){
a[l - ] += d;
update(, n - , l - , );
}
if (r < n){
a[r] -= d;
update(, n - , r, );
} printf("%d\n", t[].ans + );
}
}
code by cj
CODEFORCES ROUND #740 ANALYSES BY TEAM:RED & BLACK的更多相关文章
- CODEFORCES ROUND #761 ANALYSES BY TEAM:RED & BLACK
A. Dasha and Stairs Problems: 一个按照1,2,3……编号的楼梯,给定踩过的编号为奇数奇数和偶数的楼梯数量a和b,问是否可以有区间[l, r]符合奇数编号有a个,偶数编号有 ...
- Codeforces Round #233 (Div. 2) B. Red and Blue Balls
#include <iostream> #include <string> using namespace std; int main(){ int n; cin >&g ...
- Codeforces Round #379 (Div. 2) Analyses By Team:Red & Black
A.Anton and Danik Problems: 给你长度为N的,只含'A','D'的序列,统计并输出何者出现的较多,相同为"Friendship" Analysis: lu ...
- Codeforces Round #740 Div. 2
题目跳转链接 A. Simply Strange Sort 题意 定义一个函数\(f_{i}\) : 如果\(a_i \ge a_{i+1}\) swap(\(a_i\) \(a_{i+1}\)) 定 ...
- Codeforces Round #486 (Div. 3) A. Diverse Team
Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Des ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- CodeForces Round
CodeForces Round 199 Div2 完了,这次做扯了,做的时候有点发烧,居然只做出来一道题,差点被绿. My submissions # When Who Problem ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)
Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放 ...
- Codeforces Round #485 (Div. 2)
Codeforces Round #485 (Div. 2) https://codeforces.com/contest/987 A #include<bits/stdc++.h> us ...
随机推荐
- Matplotlib-画图种类
Scatter 散点图 本节我们将讲述各种不同的plot的方式.之前我们讲到了如何plot线,今天我们讲述如何plot散点图. # 首先,先引入matplotlib.pyplot简写作plt,再引入模 ...
- Windows、Linux的环境变量
Windows操作系统 什么是环境变量?环境变量一般是指在操作系统中用来指定操作系统运行环境的一些参数,比如临时文件夹位置和系统文件夹位置等. 这点有点类似于DOS时期的默认路径,当你运行某些程序时除 ...
- 使用mysqldump以分隔文本格式转储数据
1.使用mysqldump以分隔文本格式转储数据 mysqldump --tab=/tmp/data --fields-terminated-by=, --fields-enclosed-by=&qu ...
- Taro开发小程序移动地图固定中间获取地址
效果图如下: 绿色地标固定在中间,移动地图的时候获取对应信息. 先定义map. <Map className="location" id={location} latitud ...
- linux 安装 mysql
二进制安装mysql 1,下载安装包,使用国内站点速度会比较快,如清华站点https://mirrors.tuna.tsinghua.edu.cn 登陆linux系统后,使用wget 进行下载mysq ...
- JavaScript图片上传前的图片预览功能
JS代码: //js本地图片预览,兼容ie[6-9].火狐.Chrome17+.Opera11+.Maxthon3 function PreviewImage(fileObj, imgPreviewI ...
- 微信小程序如何实现和微信客服通话?
微信小程序如何实现和微信客服通话?
- python异常捕捉以及处理
看标题觉得高大上,好像能处理所有的异常.但是,事实是只能按照字面的意思来理解这一段话. 众所周知写代码哪有不出bug的? 那么出现了bug 我们不想让程序因为bug的存在而退出.那么要怎么做呢? 今天 ...
- django之组件
(Django) 组件:本质上就是将一个写好的功能模块的html文件直接引入html目标文件,利用其功能. 标准语法: {% include 'html文件名' %} 如:{% include 'na ...
- webpack优化以及node版本
最近做的这个项目webpack用的是1.X的版本,真的非常多的坑,然后最近在疯狂的做优化: 事情的起因是每次我npm run dev的时侯都需要5分钟+,这个速度真的是难以忍受,然后就尝试去做项目的优 ...