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范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
随机推荐
- String-StringBuffer-StringBuilder的区别和源码分析
一,String,StringBuffer,StringBuilder三者之间的关系 三个类的关系:StringBuffer和StringBuilder都继承自AbstractStringBuilde ...
- Android视频录制从不入门到入门系列教程(三)————视频方向
运行Android视频录制从不入门到入门系列教程(二)————显示视频图像中的Demo后,我们应该能发现视频的方向是错误的. 由于Android中,Camera给我们的视频图片的原始方向是下图这个样子 ...
- PMM Client 安装异常报错
1.PMM架构 如下图所示 2.Client主要组件 PMM Client是安装在你要监视的MySQL或MongoDB主机上的一组代理组件.组件收集关于一般系统和数据库性能的各种数据,并将该数据发送到 ...
- 解析SQL Server之任务调度
在前面两篇文章中( 浅谈SQL Server内部运行机制 and 浅谈SQL Server数据内部表现形式 ),我们交流了一些关于SQL Server的一些术语,SQL Sever引擎 与SSMS抽象 ...
- Python之Pandas的一些理解
Pandas的功能: 1. 结构化的数据分析; 相比excel,可以处理更大量的数据和更好的性能 2. 对数据的清洗
- C/C++中容器vector用法
C++中数组非常坑,有没有相似Python中list的数据类型呢?相似的就是vector!vector 是同一种类型的对象的集合,每一个对象都有一个对应的整数索引值. 和 string 对象一样.标准 ...
- Python爬虫爬取网页图片
没想到python是如此强大,令人着迷,以前看见图片总是一张一张复制粘贴,现在好了,学会python就可以用程序将一张张图片,保存下来. 今天逛贴吧看见好多美图,可是图片有点多,不想一张一张地复制粘贴 ...
- [题解] Codeforces Round #549 (Div. 2) B. Nirvana
Codeforces Round #549 (Div. 2) B. Nirvana [题目描述] B. Nirvana time limit per test1 second memory limit ...
- ansible roles
roles 特点 目录结构清晰 重复调用相同的任务 目录结构相同 web - tasks - install.yml - copfile.yml - start.yml - main.yml - t ...
- Python之操作HBASE数据库
目前有两个库可以操作HBASE:hbase-thrift 和 happybase happybase使用起来比较简单方便,因此重点学习该库,hbase-thrift只做简要介绍. (一)hbase- ...