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 ...
随机推荐
- js常用身份校验规则
js常用身份校验规则 var Validator = { extractBirth: function(id) { // 身份证提取出生年月 var re = null, split, year, m ...
- IAR软件的使用
STM32标准外设库下载 官网下载链接(需要ST账号登陆): http://www.st.com/content/st_com/en/products/embedded-software/mcus-e ...
- Matplotlib-画图种类
Scatter 散点图 本节我们将讲述各种不同的plot的方式.之前我们讲到了如何plot线,今天我们讲述如何plot散点图. # 首先,先引入matplotlib.pyplot简写作plt,再引入模 ...
- win10 开发mfc 64位 ocx控件
问题1.模块“XXX.ocx”加载失败 解决办法:项目--〉属性--〉常规-〉配置类型-〉 动态库(.dll) 修改为 静态库(.lib) 问题2.1>x64\Release\stdafx.o ...
- Jmeter+badboy压力测试总结
流程:badboy导出Jmeter压测脚本 -> Jmeter进行压力测试 软件下载地址: badboy:http://www.badboy.com.au/ Jmeter:http://jmet ...
- python中文件处理--判断文件读取结束方法
一.readline函数 按行遍历读取文件的方法,通过这个方法,readline() 每次只读取一行,通常比 .readlines() 慢得多.仅当没有足够内存可以一次读取整个文件时,才应该使用 .r ...
- C++读取与保持图片
#include<iostream> using namespace std; void main(void) { //保存输入图像文件名和输出图像文件名 ]; ]; //图像数据长度 i ...
- 小组团队项目的NABCD分析
N:1.学校中有很多学生是外省的,然后不知道附近有什么地方周末可以去玩,有时候想记录自己每天发生的乐趣事情并且想跟别人分享.2.学校中学生有很多用不到的东西但是联系不到合适的买家.A:我们可以做一个软 ...
- nodejs设置跨域访问
//设置跨域访问app.all('*', function(req, res, next) { res.header("Access-Control-Allow-Origin", ...
- Game Engine Architecture 7
[Game Engine Architecture 7] 1.SRT Transformations When a quaternion is combined with a translation ...