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 ...
随机推荐
- python框架django-web层
1.demo 命令行:django-admin startproject HelloWorld 命令执行成功后会根据模版生产一个django项目 然后通过 命令:python3 manage.py r ...
- .net Cache 需要注意的地方
CacheItemPolicy policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(ti ...
- sql语句(已在Oracle中测试,之后有添加内容放在评论中)
1增 1.1[创建一张表] create table 表名(列名 类型); 例: ),性别 ),出生日期 date); ),sex ),出生日期 date); 1.2[插入单行]insert [int ...
- Spring再接触 简单属性注入
<bean name="userDAO" class="com.bjsxt.dao.impl.UserDAOImpl"> <property ...
- python数据类型及其详解
一.数据类型介绍 1.字符串(string) 三种类型:单引号,双引号,三引号 a = 'jam' b = "JamHsiao" c = '''JAMHSIAO''' print( ...
- Systemd 教程
目录 Systemd 教程 sshd.service配置模板 开机启动 启动服务 停止服务 配置文件 [Unit] 区块:启动顺序与依赖关系 [Service] 区块:启动行为 1.启动命令 2.启动 ...
- python--第二十一/二天总结
Python的WEB框架 Bottle Bottle是一个快速.简洁.轻量级的基于WSIG的微型Web框架,此框架只由一个 .py 文件,除了Python的标准库外,其不依赖任何其他模块. 1 2 3 ...
- IDEA添加项目依赖(将Tomcat中的servlet-api.jar添加到项目中去)
File -> project structure -> Modules -> 右侧Dependencies -> 然后点加号把配置好的Tomcat的依赖包加进去
- Hadoop2.7.7_HA高可用部署
1. Hadoop的HA机制 前言:正式引入HA机制是从hadoop2.0开始,之前的版本中没有HA机制 1.1. HA的运作机制 (1)hadoop-HA集群运作机制介绍 所谓HA,即高可用(7*2 ...
- 通过ssh StrictHostKeyChecking解决自动化git项目问题
SSH 公钥检查是一个重要的安全机制,可以防范中间人劫持等黑客攻击.但是在特定情况下,严格的 SSH 公钥检查会破坏一些依赖 SSH 协议的自动化任务,就需要一种手段能够绕过 SSH 的公钥检查. 首 ...