2019nc#9
题号 | 标题 | 已通过代码 | 题解/讨论 | 通过率 | 团队的状态 |
---|---|---|---|---|---|
A | The power of Fibonacci | 点击查看 | 进入讨论 | 69/227 | 未通过 |
B | Quadratic equation | 点击查看 | 高次剩余 | 391/888 | 未通过 |
C | Inversions of all permutations | 点击查看 | 进入讨论 | 28/61 | 未通过 |
D | Knapsack Cryptosystem | 点击查看 | 进入讨论 | 606/2251 | 通过 |
E | All men are brothers | 点击查看 | 进入讨论 | 425/1117 | 通过 |
F | Birthday Reminders | 点击查看 | 进入讨论 | 5/11 | 未通过 |
G | Checkers | 点击查看 | 进入讨论 | 0/15 | 未通过 |
H | Cutting Bamboos | 点击查看 | 二分,主席树 | 187/834 | 通过 |
I | KM and M | 点击查看 | 进入讨论 | 19/296 | 未通过 |
J | Symmetrical Painting | 点击查看 | 进入讨论 | 227/930 | 通过 |
H Cutting Bamboos
这道题用主席树过的,记录下区间权值。
// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize(4)
#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert>
#include <unordered_map>
// #include<bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a) typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll; const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9+; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
}
/**********showtime************/ const int N = 2e5 + , M = 4e6 + ;//M为节点个数,为Q*log(N)
int root[N], lson[M], rson[M], value[M], tot = ;
ll sum[M];
const double eps = 1e-;
//建树
void build(int &x, int l, int r) {
x = ++tot;
value[x] = ;
sum[x] = ;
if(l == r) {
return ;
}
int m = (l+r) >> ;
build(lson[x], l, m);
build(rson[x], m+, r);
value[x] = value[lson[x]] + value[rson[x]];
}
// 将某个历史版本p位置的值加v
void update(int old, int &x, int p, int v, int l, int r) {
x = ++tot;
lson[x] = lson[old], rson[x] = rson[old], value[x] = value[old] + v, sum[x] = sum[old] + p;
if(l == r) return ;
int m = (l+r) >> ;
if(p <= m) update(lson[x], lson[x], p, v, l, m);
else update(rson[x], rson[x], p, v, m+, r);
}
//访问某个历史版本L到R的区间和
int query(int L, int R, int x, int l, int r) {
if(L <= l && r <= R) return value[x];
int m = (l+r) >> , ans = ;
if(L <= m) ans += query(L, R, lson[x], l, m);
if(R > m) ans += query(L, R, rson[x], m+, r);
return ans;
}
ll query2(int L, int R, int x, int l, int r) {
if(L <= l && r <= R) return sum[x];
int m = (l+r) >> ;
ll ans = ;
if(L <= m) ans += query2(L, R, lson[x], l, m);
if(R > m) ans += query2(L, R, rson[x], m+, r);
return ans;
}
const int maxn = 2e5+;
ll pre[maxn], a[maxn];
double cal(double val, int L, int R) {
int hi = floor(val);
int cnt = query(, hi, root[R], , ) - query(, hi, root[L-], , );
double ss = (R - L + - cnt) * val;
ss += 1.0*query2(, hi,root[R], , ) - query2(, hi, root[L-], , );
return ss;
}
int main(){
int n,m;
scanf("%d%d", &n, &m);
build(root[], , );
for(int i=; i<=n; i++) {
scanf("%lld", &a[i]), pre[i] = pre[i-] + a[i];
update(root[i-], root[i], a[i], , , );
}
while(m--) {
int L, R, x, y;
scanf("%d%d%d%d", &L, &R, &x, &y);
ll ss = pre[R] - pre[L-];
double nd = ss*1.0 / y *(y - x);
double le = , ri = , res = ;
//debug(nd);
while(le + eps < ri) {
double mid = (le + ri) / ;
if(cal(mid, L, R) <= nd) le = mid, res = mid;
else ri = mid;
}
printf("%.10f\n", res);
}
return ;
}
J Symmetrical Painting
题意:
有n个矩形,宽度都为1,排列在坐标轴上,问消去一些矩形的一部分,使得原来的图形上下对称。这个对称图形最大可能面积。
思路:
有点类似扫描线的做法。
/*
* @Author: chenkexing
* @Date: 2019-08-16 15:34:14
* @Last Modified by: chenkexing
* @Last Modified time: 2019-08-16 15:41:12
*/ // #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize(4)
#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert>
// #include<bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a) typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll; const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f;
const int mod = ; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} /**********showtime************/
const int maxn = ;
pii a[maxn * ]; int main(){
int n;
scanf("%d", &n);
int tot = ;
for(int i=; i<=n; i++) {
int le,ri;
scanf("%d%d", &le, &ri);
// 在底,中点,高上有可能取到极值。
a[++tot] = pii(*le, );
a[++tot] = pii(le + ri, -);
a[++tot] = pii(*ri, );
}
sort(a+, a++tot);
ll ans = , sum = ;
ll cnt = a[].se;
for(int i=; i<=tot; i++) {
sum += cnt * (a[i].fi - a[i-].fi);
ans = max(ans, sum);
cnt += a[i].se;
}
printf("%lld\n", ans);
return ;
}
2019nc#9的更多相关文章
- 2019nc#2
A Eddy Walker 题意 你有n个点(0-n-1),按顺序形成一个环,初始时你在0的位子,你随机顺时针走一步或者逆时针走一步, 一旦你走到一个点后,环上所有点都被经过至少一次后,你就必须停下来 ...
- 2019nc#10
题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A Blackjack 点击查看 背包DP 32/109 补好了 B Coffee Chicken 点击查看 进入讨论 738/2992 通过 ...
- 2019NC#8
题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A All-one Matrices 点击查看 单调栈+前缀和 326/2017 通过 B Beauty Values 点击查看 进入讨论 8 ...
- 2019nc#7
题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A String 点击查看 进入讨论 566/3539 通过 B Irreducible Polynomial 点击查看 规律 730/229 ...
- 2019nc#6
https://ac.nowcoder.com/acm/contest/886#question 题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A Garbage Classificatio ...
- 2019nc#5
题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A digits 2 点击查看 1017/2384 通过 B generator 1 点击查看 567/3692 通过 C generato ...
- 2019nc#4
题号 标题 已通过代码 题解 通过率 团队的状态 A meeting 点击查看 树直径 604/2055 B xor 点击查看 线段树维护线性基交 81/861 未通过 C sequence 点击 ...
- 2019nc#3
题号 标题 已通过代码 题解/讨论 通过率 团队的状态 A Graph Games 点击查看 进入讨论 18/292 未通过 B Crazy Binary String 点击查看 1107/3615 ...
- 2019NC#1
LINK B Integration 题意: 给定$a_1,a_2,...,a_n$, 计算 $$\frac{1}{π}\int_{0}^{\infty}\frac{1}{\prod\limits_{ ...
随机推荐
- JUint4的下载、配置及对一个算法编写单元测试用例(测试多组数据每组多个参数)
一.JUnit4 jar包下载 链接:https://pan.baidu.com/s/1AdeVGGikcY5dfL151ZnWHA 提取码:h1am 下载完成后,解压一下即可. 二.导入JUnit4 ...
- Codeforces Round #192 (Div. 2) (330A) A. Cakeminator
题意: 如果某一行没有草莓,就可以吃掉这一行,某一列没有也可以吃点这一列,求最多会被吃掉多少块蛋糕. //cf 192 div2 #include <stdio.h> #include & ...
- Hadoop 系列(一)—— 分布式文件系统 HDFS
一.介绍 HDFS (Hadoop Distributed File System)是 Hadoop 下的分布式文件系统,具有高容错.高吞吐量等特性,可以部署在低成本的硬件上. 二.HDFS 设计原理 ...
- Python基础总结之初步认识---clsaa类(上)。第十四天开始(新手可相互督促)
最近的类看着很疼,坚持就是胜利~~~ python中的类,什么是类?类是由属性和方法组成的.类中可能有很多属性,以及方法. 我们这样定义一个类: 前面是class关键字 后面school是一个类的名字 ...
- 插入Oracle数据库后返回当前主键id
最近做一个spring版本3.0.4的老项目功能,应用场景要用到插入oracle表后返回主键ID拿来和其他表关联. 用oralce的可以一直用这种处理方式,高兼容低,搜索网上的资料都不能和这个Spri ...
- 理解分布式一致性与Raft算法
理解分布式一致性与Raft算法 永远绕不开的CAP定理 出于可用性及负载方面考虑,一个分布式系统中数据必然不会只存在于一台机器,一致性简单地说就是分布式系统中的各个部分保持数据一致 但让数据保持一致往 ...
- 对API进行版本控制的重要性和实现方式
我在API设计中收到的最常见问题之一就是如何对API进行版本控制.虽然并非所有API都完全相同,但我发现在API版本控制方面,某些模式和实践适用于大多数团队.我已经将这些内容收集起来,下面将提供一些关 ...
- 详解阿里P7架构师是怎么在Spring中实现事务暂停
摘要 Spring框架是一个流行的基于轻量级控制反转容器的Java/J2EE应用框架,尤其在数据访问和事务管理方面的能力是众所周知的.Spring的声明性事务分离可以应用到任何POJO目标对象,并且包 ...
- Day3 AntV/G2图表的组成
简介 为了更好的使用G2进行数据可视化,我们需要先了解G2图表的组成及其相关概念. 完整的G2图表组成如下图所示:可以看出图表主要由axes(坐标轴axis的复数),tooltip(提示信息),gui ...
- 100天搞定机器学习|Day23-25 决策树及Python实现
算法部分不再细讲,之前发过很多: [算法系列]决策树 决策树(Decision Tree)ID3算法 决策树(Decision Tree)C4.5算法 决策树(Decision Tree)CART算法 ...