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范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
随机推荐
- ASP.NET Core 部署IIS及 OFFSET 附近有语法错误解决
今天自己开发了一个订机票的微信公众号,功能基本已经完成,然后想部署到服务器实际测试下.结果部署上去出现各种问题.先安装asp.net core模块,然后发现数据库并不像在开发时一样,执行ef的命令行语 ...
- phpstorm:如何设置代码自动换行
File->Settings->Editor 点击general,如下如所示: 勾选 “ Use soft wrap in editor ” ,这样就可以自动换行了
- Android项目实战(五十二):控制EditText输入内容大小写转换
今日需求,EditText内容为一串字符串,要求将用户软键盘输入的小写字母在输入的时候自动转为大写字母,反之亦然. 效果如下: 第一次做该需求,原先想法: EditText.addTextChange ...
- Java 基于ArcFace人脸识别2.0 服务端Demo
源代码传送:https://github.com/itboyst/ArcSoftFaceDemo 开发环境准备: ###开发使用到的软件和工具: Jdk8.mysql5.7.libarcsoft_fa ...
- 第五篇Scrum冲刺博客
一.Daily Scrum Meeting照片 二.每个人的工作 成员 ItemID 已完成工作 明天计划完成的工作 遇到的困难 张鸿 o1 整合界面至游戏中 将其他剩余功能进行整合 游戏状态的切换 ...
- AngularJS学习之旅—AngularJS 模块(十五)
一.AngularJS 模块 模块定义了一个应用程序. 模块是应用程序中不同部分的容器. 模块是应用控制器的容器. 控制器通常属于一个模块. 1.创建模块 通过 AngularJS 的 angular ...
- SQL Server数据库————增删改查
--增删改查--增 insert into 表名(列名) value(值列表) --删 delect from 表名 where 条件 --改 update 表名 set 列名=值1,列名2=值2 w ...
- Delphi 拦截输入法输入结果
{ 拦截输入法输入的字符串.向编辑框中输入中文查看效果. Delphi XE7 } unit Unit1; interface uses Winapi.Windows, Winapi.Messages ...
- C# -- 使用 Task 执行多线程任务
C# -- 使用 Task 执行多线程任务 1. 使用 Task 执行多线程任务 class Program { static void Main(string[] args) { Task task ...
- Microsoft Visual Studio 2012 添加实体数据模型
Microsoft Visual Studio 2012 添加实体数据模型 1.创建一个web项目 2.添加ADO实体数据模型,如下图: 3.选择 从数据库生成,然后下一步 4.新建连接,如下图: ...