蒟蒻和以前一样还是只能做 $4$ 题, 希望有一天可以 水到 $5$ 题!!
不过也终于上了蓝了。。。
 

A. Benches

Description

给出$N$个座位, 每个座位上初始有$a_i$ 个人, 这些人都不能移动。

另外还有$M$个人, 要求让他们坐到座位上, $max$ 为所有座位上人数最多 的 人数。

求出 $max$ 的可能最大值和 最小值。

Solution

最大值就是 给出的最多的人数 的座位 加上 $M$

最小值可以二分答案, 容易求出

Code

 #include<cstdio>
#include<cstring>
#include<algorithm>
#define rd read()
using namespace std; const int N = 1e3; int n, m, a[N], maxn; int read() {
int X = , p = ; char c = getchar();
for(; c > '' || c < ''; c = getchar()) if(c == '-') p = -;
for(;c >= '' && c <= ''; c = getchar()) X = X * + c - '';
return X * p;
} bool jud(int minn) {
int rest = m;
for(int i = ; i <= n; ++i) {
if(a[i] > minn) return false;
rest -= minn - a[i];
}
if(rest > ) return false;
else return true;
} int main()
{
n = rd; m = rd;
for(int i = ; i <= n; ++i)
a[i] = rd;
for(int i = ; i <= n; ++i)
maxn = max(maxn, a[i]);
int l = , r = 2e4 + , ans = ;
while(l <= r) {
int mid = (l + r) >> ;
if(jud(mid)) r = mid - , ans = mid;
else l = mid + ;
}
printf("%d %d\n", ans, maxn + m);
}

A. Benches

B. Vitamins

Description

给出$N$种维生素药, 第$a_i$种药包含了$A,B,C,$中的其中一种或多种维生素, 每一种药都有其价格$cost_i$

现要求出 能吃到维生素 $A,B,C$ 至少花费多少钱。

Solution

显然, 药最多只有7种, 用$2$进制 $S$ 表示是否含有某种维生素, 该种药的最小价格记为 $minn[S]$

在输入时,我们把第 $i$ 种药 更新到对应的 含有维生素的集合S。

求最后的答案时, 只需要三种枚举就行了:

$1$ : 买一种药, 对应集合 $111(B)$

$2$ : 买两种药 $i$ 和 $j$, 并且$i \ | \ j \ = \ 111(B)$

$3$: 买三种药 $i$ 和 $j$, 并且$i \ | \ j \ | \ k \ = \ 111(B)$

求其中的最小值即可。

Code

 #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; const int N = 1e3 + ;
const int inf = ~0U >> ; int n, v[], minn[], ans = inf; char s[]; struct node {
int cost, vis;
}a[N]; int main()
{
for(int i = ; i < ; ++i)
minn[i] = inf;
scanf("%d", &n);
for(int i = ; i <= n; ++i) {
memset(s, ,sizeof(s));
memset(v, , sizeof(v));
scanf("%d%s", &a[i].cost, s);
for(int j = , len = strlen(s); j < len; ++j)
a[i].vis |= << (s[j] - 'a');
minn[a[i].vis] = min(minn[a[i].vis], a[i].cost);
}
ans = min(ans, minn[]);
for(int i = ; i < ; ++i)
for(int j = ; j < ; ++j)
if((i | j) == ) ans = min(ans, minn[i] + minn[j]);
for(int i = ; i < ; ++i)
for(int j = ; j < ; ++j)
for(int k = ; k < ; ++k)
if((i | j | k) == )
ans = min(ans, minn[i] + minn[j] + minn[k]);
printf("%d\n", ans == inf ? - : ans);
}

B. Vitamins

C. Array Product

Description

给出一个有$N$项的序列${a}$, 有两种操作

$1$: 选择两个数 $i$  $j$, 把$j$ 位置上的数更新为$a_j * a_i$, 将$i$ 位置上的数删去(删去后不能再进行操作)

$2$: 选择一个数$i$, 将 $i$ 位置上的数直接删去 ( 该种操作最多只能进行$1$次)

问如何操作才能使 $N-1$ 次操作后剩下的那个数最大, 输出操作的方案。

Solution

大佬说这是前四题最不可做的, 所以我 先水了D题, 最后还WA了两次才 在1:52的时候过(好像我rank并没有升多少

有如下4中情况:

$1$ : 序列中有 奇数个 负数, 并且 存在 $0$—— 将所有的 $0$ 合并成一个,再把 $0$ 和 绝对值最小的 负数 合并 得到 $0$, 删去这个 $0$ 后 把剩余的数合并。

$2$ : 序列中有 奇数个 负数, 并且 不存在 $0$—— 直接删除 绝对值最小的负数, 剩下的合并。

$3$ : 序列中有 偶数个 负数, 并且存在 $0$—— 把所有的$0$ 合并成一个, 把 $0$ 删去, 剩下的数合并

$4$ : 序列中有 偶数个负数, 并且 不存在 $0$—— 直接合并。

Code

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define rd read()
using namespace std; const int N = 2e5 + ;
const int inf = ~0U >> ; int a[N], vis[N], tot, n, rest; vector<int> cur0, cur1; int read() {
int X = , p = ; char c = getchar();
for(; c > '' || c < ''; c = getchar()) if(c == '-') p = -;
for(; c >= '' && c <= ''; c = getchar()) X = X * + c - '';
return X * p;
} int main()
{
n = rd;
rest = n - ;
a[] = -inf;
for(int i = ; i <= n; ++i) {
a[i] = rd;
if(a[i] < ) tot++;
if(a[i] < ) cur1.push_back(i);
if(a[i] == ) cur0.push_back(i);
}
/*if((tot & 1)) {
int pos = 0;
for(int i = 0, len = cur1.size(); i < len; ++i)
if(a[pos] < a[cur1[i]]) pos = cur1[i];
vis[pos] = 1;
printf("2 %d\n", pos);
rest--;
}
for(int i = 0, len = cur0.size(); i < len - 1 && rest; ++i) {
vis[cur0[i]] = 1;
printf("1 %d %d\n", cur0[i], cur0[i + 1]);
rest--;
}
if(tot % 2 == 0 && cur0.size() && rest) {
printf("2 %d\n", cur0[(int)cur0.size() - 1]);
vis[cur0[(int)cur0.size() - 1]] = 1;
rest --;
}*/ if(tot % && cur0.size()) {
for(int i = , len = cur0.size(); i < len - && rest; ++i) {
vis[cur0[i]] = ;
printf("1 %d %d\n", cur0[i], cur0[i + ]);
rest--;
}
int pos = ;
for(int i = , len = cur1.size(); i < len; ++i)
if(a[pos] < a[cur1[i]]) pos = cur1[i];
printf("1 %d %d\n", cur0[(int)cur0.size() - ], pos);
rest--;
vis[cur0[(int)cur0.size() - ]] = ;
if(rest) {
printf("2 %d\n", pos);
vis[pos] = ;
rest--;
}
}
else if(cur0.size()) {
for(int i = , len = cur0.size(); i < len - && rest; ++i) {
vis[cur0[i]] = ;
printf("1 %d %d\n", cur0[i], cur0[i + ]);
rest--;
}
if(rest) {
printf("2 %d\n", cur0[(int)cur0.size() - ]);
vis[cur0[(int)cur0.size() - ]] = ;
rest --; }
}
else if(!cur0.size() && tot % ) {
int pos = ;
for(int i = , len = cur1.size(); i < len; ++i)
if(a[pos] < a[cur1[i]]) pos = cur1[i];
printf("2 %d\n", pos);
rest--;
vis[pos] = ;
}
for(int i = , j = ; rest;) {
while(vis[i] && i <= n) i++;
j = i + ;
while(vis[j] && j <= n) j++;
printf("1 %d %d\n", i, j);
vis[i] = ;
rest--;
} }

C. Array Product

D. Petya and Array

Description

求出有多少个 子段的 和 $<t$

Solution

跟树状数组求逆序对一样的原理。

我不会用语言表述 $QuQ$ (╥╯^╰╥)

简单说, 就是先求出前缀和$sum$, 当前我们需要求出以$i$ 为结尾的子段有多少个满足$sum[i] \ - \ sum[j] \ < \ t$,$0<=j<i$

这样而树状数组求静态逆序对就相当于 $t = 0$时的做法了。

Code

 #include<cstdio>
#include<cstring>
#include<algorithm>
#define rd read()
#define ll long long
using namespace std; const int N = 2e5 + ; int n, a[N];
ll qsum[N], t, b[N], tot;
ll sum[N], ans; ll read() {
ll X = , p = ; char c = getchar();
for(; c > '' || c < ''; c = getchar()) if(c == '-') p = -;
for(; c >= '' && c <= ''; c = getchar()) X = X * + c - '';
return X * p;
} int fd(ll x) {
int tmp = lower_bound(b + , b + + tot, x) - b;
if(b[tmp] == x) return tmp;
else return tmp - ;
} int lowbit(int x) {
return x & -x;
} ll query(int x) {
ll re = ;
for(; x; x -= lowbit(x)) re += sum[x];
return re;
} void add(int x) {
for(; x <= tot; x += lowbit(x))
sum[x]++;
} int main()
{
n = rd; t = rd;
for(int i = ; i <= n; ++i)
a[i] = rd;
for(int i = ; i <= n; ++i) {
qsum[i] = qsum[i - ] + a[i];
b[++tot] = qsum[i];
}
b[++tot] = ;
sort(b + , b + + tot);
tot = unique(b + , b + + tot) - b - ;
add(fd());
for(int i = ; i <= n; ++i) {
int tmp = fd(qsum[i] - t);
ans += (i - query(tmp));
tmp = fd(qsum[i]);
add(tmp);
}
printf("%I64d\n", ans);
}

D. Petya and Array

codeforces round#510的更多相关文章

  1. Codeforces Round #510 (Div. 2)

    Codeforces Round #510 (Div. 2) https://codeforces.com/contest/1042 A 二分 #include<iostream> usi ...

  2. Codeforces Round #510 (Div. 2) D. Petya and Array(离散化+反向树状数组)

    http://codeforces.com/contest/1042/problem/D 题意 给一个数组n个元素,求有多少个连续的子序列的和<t (1<=n<=200000,abs ...

  3. Codeforces Round #510 (Div. 2) B. Vitamins

    B. Vitamins 题目链接:https://codeforces.com/contest/1042/problem/B 题意: 给出几种药,没种可能包含一种或多种(最多三种)维生素,现在问要吃到 ...

  4. Codeforces Round #510 (Div. 2) D. Petya and Array(树状数组)

    D. Petya and Array 题目链接:https://codeforces.com/contest/1042/problem/D 题意: 给出n个数,问一共有多少个区间,满足区间和小于t. ...

  5. Codeforces Round #510 #C Array Product

    http://codeforces.com/contest/1042/problem/C 给你一个有n个元素序列,有两个操作:1,选取a[i]和a[j],删除a[i],将$a[i]*a[j]$赋值给a ...

  6. Codeforces Round #510 #B

    http://codeforces.com/contest/1042/problem/B 题意: 给出n种饮料,每种饮料还有一种或多种维生素(A或B或C),某人想集齐三种维生素,问最少需要花费多少? ...

  7. Codeforces Round #510 #A

    http://codeforces.com/contest/1042/problem/A 题目大意就是: 现在公园里有n个长椅(要多长有多长),第i个长椅上有a[i]个人(泰山崩于前而不乱),现在又有 ...

  8. Codeforces Round #510 (Div. 2)(C)

    传送门:Problem C https://www.cnblogs.com/violet-acmer/p/9682082.html 题意: 给你n个数,定义有两种操作 ① 1 i j : (i != ...

  9. Codeforces Round #510 (Div. 2)(B)

    传送门:Problem B https://www.cnblogs.com/violet-acmer/p/9682082.html 题意: 如果可以通过喝果汁将维生素A,B,C全部摄取,求最小花费,如 ...

  10. Codeforces Round #510 (Div. 2)(A)

    传送门:Problem A https://www.cnblogs.com/violet-acmer/p/9682082.html 题意: 公园里有n个沙滩,a[i]表示第i个沙滩初始人数,现有m个人 ...

随机推荐

  1. MPI Maelstrom-单源最短路-Djsktra

    BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distribute ...

  2. NYOJ20-吝啬的国度-图-dfs

    20-吝啬的国度 内存限制:64MB时间限制:1000ms特判: No 难度:3 题目描述: 在一个吝啬的国度里有N个城市,这N个城市间只有N-1条路把这个N个城市连接起来.现在,Tom在第S号城市, ...

  3. kafka 删除topic清空数据

    原 kafka 删除topic清空数据 2018年11月20日 18:17:50 Ming! 阅读数:1391   版权声明:版权声明:本文为博主原创文章,未经博主允许不得转载. https://bl ...

  4. requests库的文档--快速上手

    快速上手 迫不及待了吗?本页内容为如何入门 Requests 提供了很好的指引.其假设你已经安装了 Requests.如果还没有,去安装一节看看吧. 首先,确认一下: Requests 已安装 Req ...

  5. java工程师基础笔试题(一)

    一.选择和填空  (不定项哦!) 1,如下是一份文件名为Test2.java的源文件,请问,编译该文件之后会生成几份字节码文件 class Test{ class Inner{} static cla ...

  6. centos7 关闭 防火墙

    CentOS 7 默认使用的是firewall作为防火墙 关闭firewall: systemctl stop firewalld.service  #停止firewall systemctl dis ...

  7. javascript sourcemap

    [javascript sourcemap] 暂时只有Chrome浏览器支持这个功能.在Developer Tools的Setting设置中,确认选中"Enable JavaScript s ...

  8. 安装FP

    一.安装Oracle 11.2 64-bit数据库 1.安装数据库软件并将SEINESCM数据库还原到服务器上, 2.配置监听和TNS信息 二.安装数据库32位客户端(为SSIS配套使用).安装ORA ...

  9. MongoDB之Limit选取Skip跳过Sort排序

    1.Limit选取 我要从Document中取出多少个 只要2条Document db.Wjs.find().limit(2) 2.Skip跳过 我要跳过多少个Document 我要跳过前两个Docu ...

  10. AVL树与红黑树(R-B树)的区别与联系

    AVL树(http://baike.baidu.com/view/593144.htm?fr=aladdin),又称(严格)高度平衡的二叉搜索树.其他的平衡树还有:红黑树.Treap.伸展树.SBT. ...