POJ-2926-Requirements&&Educational Codeforces Round 56G. Multidimensional Queries 【哈夫曼距离】
先学会这个哈夫曼距离的处理才能做 cf 的G
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
#define maxn 100005
const int inf = (int)1e9;
];
<<+],mx[<<+];
int main(){
int n;
scanf("%d",&n);
;j<n;j++){
;k<;k++){
scanf("%lf",&a[j][k]);
}
}
;j<(<<);j++){
mi[j] = inf;
mx[j] = -inf;
}
// double mx = 0,mi = inf;
double ans = -inf;
;j<n;j++){
//int cur = 0.
;k<(<<);k++){
;
;i<;i++){
<<i)){
cur += a[j][i];
}else{
cur -= a[j][i];
}
}
//cout<<cur<<endl;
mx[k] = max(mx[k],cur);
mi[k] = min(mi[k],cur);
//ans = max(ans,mx[j]-mi[j]);
}
}
;j<(<<);j++){
//cout<<mx[j]<<" "<<mi[j]<<endl;
ans = max(ans,mx[j]-mi[j]);
}
printf("%0.2f\n",ans);
}
点一下 题目链接
CF G 用线段树处理一下
就ok
#include<bits/stdc++.h>
using namespace std;
#define maxn 200005
#define inf (int)1e9
*maxn][];
*maxn][];
int n,m;
void build(int l,int r,int in){
if(l==r){
;j<(<<m);j++){
;
;k<m;k++){
<<k)){
cur+=b[l][k];
}else cur-=b[l][k];
}
//cout<<cur<<endl;
a[in][j] = cur;
}
return ;
}
;
build(l,mid,);
build(mid+,r,+);
;j<(<<m);j++){
a[][j],a[+][j]);
}
}
void up(int l,int r,int x,int in){
if(l==r){
;j<(<<m);j++){
;
;k<m;k++){
<<k)){
cur+=b[l][k];
}else cur-=b[l][k];
}
a[in][j] = cur;
}
return ;
}
;
if(x>mid){
up(mid+,r,x,+);
}else{
up(l,mid,x,);
}
;j<(<<m);j++){
a[][j],a[+][j]);
}
}
int query(int l,int r,int x,int y,int i,int in){
//if(x>y) return inf;
if(l==x&&r==y){
return a[in][i];
}
;
if(x>mid){
,r,x,y,i,+);
}else if(y<=mid){
);
}
),query(mid+,r,mid+,y,i,+));
}
int main(){
cin>>n>>m;
;j<=n;j++){
;k<m;k++){
scanf("%d",&b[j][k]);
}
}
build(,n,);
// for(int j=0;j<(1<<m);j++){
// cout<<a[1][j]<<endl;
// }
int t; cin>>t;
while(t--){
int z;
scanf("%d",&z);
){
int i;
scanf("%d",&i);
;j<m;j++){
scanf("%d",&b[i][j]);
}
up(,n,i,);
}else{
;
scanf("%d%d",&l,&r);
;j<(<<(m-));j++){
,n,l,r,j,);
,n,l,r,j^((<<m)-),);
//cout<<x<<" "<<y<<endl;
mx = max(mx,abs(x+y));
}
printf("%d\n",mx);
}
}
;
}
POJ-2926-Requirements&&Educational Codeforces Round 56G. Multidimensional Queries 【哈夫曼距离】的更多相关文章
- Educational Codeforces Round 2 B. Queries about less or equal elements 水题
B. Queries about less or equal elements Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforc ...
- Educational Codeforces Round 1 B. Queries on a String 暴力
B. Queries on a String Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/59 ...
- Educational Codeforces Round 2 B. Queries about less or equal elements
打开题目连接 题意:给2个数组(无序的)啊a,b,判断b数组中的每一个元素大于a数组中个数. ACcode: #include <iostream> #include <vector ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- [Educational Codeforces Round 16]B. Optimal Point on a Line
[Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
- Educational Codeforces Round 6 C. Pearls in a Row
Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
随机推荐
- Struts2中五个重要的常量
一.五个常量的位置:位于xwork核心包下的Action字节码文件里 二.五个常量的介绍: a: SUCCESS public static final String SUCCESS = " ...
- 责任链模式 职责链模式 Chain of Responsibility Pattern 行为型 设计模式(十七)
责任链模式(Chain of Responsibility Pattern) 职责链模式 意图 使多个对象都有机会处理请求,从而避免请求的发送者和接受者之间的耦合关系 将这些对象连接成一条链,并沿着这 ...
- solr8.0 从数据库导入数据(三)
第一步:导入相关包: 在创建的核心目录下新建lib文件夹(如果有,无需建立),从Solr源码包的dist文件夹中导入两个solr-dataimporthandler包,以及一个mysql驱动包. 第二 ...
- 数据结构:关键路径,利用DFS遍历每一条关键路径JAVA语言实现
这是我们学校做的数据结构课设,要求分别输出关键路径,我查遍资料java版的只能找到关键路径,但是无法分别输出关键路径 c++有可以分别输出的,所以在明白思想后自己写了一个java版的 函数带有输入函数 ...
- Hadoop 3.1.2(HA)+Zookeeper3.4.13+Hbase1.4.9(HA)+Hive2.3.4+Spark2.4.0(HA)高可用集群搭建
目录 目录 1.前言 1.1.什么是 Hadoop? 1.1.1.什么是 YARN? 1.2.什么是 Zookeeper? 1.3.什么是 Hbase? 1.4.什么是 Hive 1.5.什么是 Sp ...
- rabbitmq之基本原理及搭建单机环境
1.RabbitMQ基本原理 1.MQ全称Message Queue,是一种分布式应用程序的通信方法,是消费-生产者模型的典型代表,producer向消息队列中不断写入消息,而另一端consumer则 ...
- 'Attempt to create two animations for cell' iOS
我是在对一个UITableView 一起进行 reloadRows和reloadSections 的操作的时候 出现的
- 数字信号处理专题(2)——利用FPGA进行基本运算及特殊函数定点运算
一.前言 FPGA以擅长高速并行数据处理而闻名,从有线/无线通信到图像处理中各种DSP算法,再到现今火爆的AI应用,都离不开卷积.滤波.变换等基本的数学运算.但由于FPGA的硬件结构和开发特性使得其对 ...
- IOS开发证书常见问题
1.本地Provisioning Profiles存放路径 ~/Library/MobileDevice/Provisioning Profiles 2.this action could not b ...
- 关于Xcode10的那些事
前言 这里主要介绍一下Xcode10 版本主要更新的内容. 随着iOS12的发布,Xcode10已经可以从Mac App Store下载. Xcode10包含了iOS12.watchOS 5.macO ...