A.Alyona and copybooks

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

B.Alyona and flowers

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

C.Alyona and mex

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

D. Alyona and a tree

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

E. Alyona and towers

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的更多相关文章

  1. CODEFORCES ROUND #761 ANALYSES BY TEAM:RED & BLACK

    A. Dasha and Stairs Problems: 一个按照1,2,3……编号的楼梯,给定踩过的编号为奇数奇数和偶数的楼梯数量a和b,问是否可以有区间[l, r]符合奇数编号有a个,偶数编号有 ...

  2. Codeforces Round #233 (Div. 2) B. Red and Blue Balls

    #include <iostream> #include <string> using namespace std; int main(){ int n; cin >&g ...

  3. Codeforces Round #379 (Div. 2) Analyses By Team:Red & Black

    A.Anton and Danik Problems: 给你长度为N的,只含'A','D'的序列,统计并输出何者出现的较多,相同为"Friendship" Analysis: lu ...

  4. Codeforces Round #740 Div. 2

    题目跳转链接 A. Simply Strange Sort 题意 定义一个函数\(f_{i}\) : 如果\(a_i \ge a_{i+1}\) swap(\(a_i\) \(a_{i+1}\)) 定 ...

  5. Codeforces Round #486 (Div. 3) A. Diverse Team

    Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Des ...

  6. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  7. CodeForces Round

    CodeForces Round 199 Div2   完了,这次做扯了,做的时候有点发烧,居然只做出来一道题,差点被绿. My submissions     # When Who Problem ...

  8. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)

    Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放 ...

  9. Codeforces Round #485 (Div. 2)

    Codeforces Round #485 (Div. 2) https://codeforces.com/contest/987 A #include<bits/stdc++.h> us ...

随机推荐

  1. JEECG 3.7.8 新版表单校验提示风格使用&升级方法(validform 新风格漂亮,布局简单)

    JEECG 表单校验采用的是validform,默认的校验提示需要占用页面布局,提示效果较传统.jeecg这个自定义的校验提示风格,不占用页面布局,提示效果也更美观,简单易用,让表单看起来更漂亮!!! ...

  2. python安装selenium和下载浏览器驱动

    1.安装selenium     方法一:可以用在cmd中用pip命令安装. python默认自带pip工具,如果在电脑上配置了pip的环境变量,打开cmd命令窗口后可以直接输入命令pip insta ...

  3. [Sw] Swoole-4.2.9 可以尝试愉快应用 Swoole 协程

    大家知道 Swoole 提供了方便于服务器.网络编程的模式,简化了多进程编程. 这直接让 PHP 的运行很容易变成常驻内存的 Server 程序,执行效率上有了数倍的提升. 但是这一切还没有让人足够兴 ...

  4. onenet简介

    物联科技|物联网开放平台探秘之移动OneNET平台(上) 物联科技 百家号17-07-1008:57 当前,国内外物联网行业发展如火如荼,众多传统行业也在谋求向物联网转型.许多电子工程师或出于个人意愿 ...

  5. tensorflow,model,object_detection,训练loss先下降后递增,到几百万,解决tensorflow,model,object,detection,loss,incease

    现象:训练loss一开始下降一部分,跌代到若干次(具体多少和你的learning rate大小有关,大就迭代小就发生,小就需要多几次迭代) 日志如下(下面的日志来源于网络,我自己的日志已经clear掉 ...

  6. python day04笔记总结

    2019.4.1 S21 day04笔记总结 昨日内容补充 1.解释器/编译器 1.解释型语言.编译型语言 2.解释型:写完代码后提交给解释器,解释器将代码一行行执行.(边接收边解释/实时解释) 常用 ...

  7. 大数据入门到精通17--union all 和disctinct 的用法

    一.union all 的用法.使用union all 或者 unionselect * from rental where rental_id <10union allselect * fro ...

  8. session的简单应用

    session的作用:服务器端保存信息. 用户登陆后,服务器端保存了 自定义的key:value 如下: if username == 'xxx' and password == 'xxxx': re ...

  9. myhaits if test判断字符串

    判断参数是否为字符串0 <if test='Type=="0"'><!-- 注意单双引号 --> <include refid="selec ...

  10. 【c# 数据库】对数据库进行增删查改

    1.DataGridView链接数据库 2.链接数据库 using System.Data.SqlClient; SqlConnection con = null; //创建SqlConnection ...