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范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
随机推荐
- PhP数据库 Mysql dos命令
mysql 这是一个关系型数据库,存在表的概念. 结构 数据库可以存放多张表,每个表可以存放多个字段,每个字段可以存放多个记录. dos命令操作数据库 phpstudy使用终端打开数据库 第一步: 第 ...
- winform 跨线程访问问题
一.问题描述 进行winform 开发我们在进行数据交换时避免不了使用多线程或异步方法,这样操作也将避免不了跨线程对控件进行操作(赋值.修改属性). 下面通过一个测试说明一下问题 点击一个按钮异步对t ...
- 迭代器模式 Iterator 行为型 设计模式(二十)
迭代器模式(Iterator) 走遍天下,世界那么大,我想去看看 在计算机中,Iterator意为迭代器,迭代有重复的含义,在程序中,更有“遍历”的含义 如果给定一个数组,我们可以通过for循 ...
- 弹性布局--flex方向
flex方向 flex方向由flex-direction特性决定,用于定义弹性布局模式.flex-direction共有4种模式:从左向右.从右向左.从上往下.从下往上. 主轴 主轴的起点与终点定义了 ...
- 高通平台如何避免误入FFBM模式
前面两篇博客分别介绍了通过fastboot和QFIL工具退出FFBM模式的方法.虽然售后的同学可以这么指导用户做恢复,但步骤多操作也麻烦,且属于事后处理,如果大面积高概率地出现,会严重影响用户体验.这 ...
- MyDAL - 快速使用
索引: 目录索引 一.安装 在 VS 中执行一下 package 命令: PM> Install-Package MyDAL 二.API-快速使用 1.命名空间,只需: using MyDAL; ...
- sql Server 2008 数据库自动备份维护计划
数据库中右键-‘管理’-新建维护计划 创建执行计划,设置备份时间 点击保存 完成 执行后报 ‘’错误5:拒绝访问 ’,时需到文件目录‘属性’→‘安全’设置用户的 ‘写入’ 权限
- jquery各大学选择插件
地址:http://www.jq22.com/jquery-info5565 演示地址:http://www.jq22.com/yanshi5565
- centos7 最小安装初始化
配置阿里yum源 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup \&&cu ...
- win7系统搭建FTP服务器
工作需要,所以研究了一下. 1. 打开: 控制面板 -> 卸载程序 -> (左侧)打开或关闭windows功能 等个一小会,勾选如下图红色方框内的选项. 2. 开始 -> 搜索: I ...