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范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
随机推荐
- SpringBoot 2.0 更优雅的配置注入
application.properties jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://127.0.0.1:33 ...
- Java笔记(day1~day6)
绪论: Java版本区别:J2EE (企业版) J2SE(标准版) J2ME(小型版) Java特性:跨平台 JVM.JRE.JDK介绍 ...
- 章节十、5-CSS---用CSS 通配符定位元素
以下演示操作以该网址中的输入框为例:https://learn.letskodeit.com/p/practice 一.css样式中有三种通配符“^.$.*” 语法:tag[attribute< ...
- 从0开始的Python学习015输入与输出
简介 在之前的编程中,我们的信息打印,数据的展示都是在控制台(命令行)直接输出的,信息都是一次性的没有办法复用和保存以便下次查看,今天我们将学习Python的输入输出,解决以上问题. 复习 得到输入用 ...
- RobotFramework第二篇之web自动化
(1)安装seleniumLibrary库: pip install --upgrade --pre robotframework-seleniumlibrary 使用第三方库关键字: (1)sett ...
- LeetCode算法题-Self Dividing Numbers(Java实现)
这是悦乐书的第305次更新,第324篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第173题(顺位题号是728).自分割数是一个可被其包含的每个数字整除的数字.例如,12 ...
- SQL FIRST() 函数
FIRST() 函数 FIRST() 函数返回指定的字段中第一个记录的值. 提示:可使用 ORDER BY 语句对记录进行排序. SQL FIRST() 语法 SELECT FIRST(column_ ...
- android获取string.xml的值
在android开发过程中,编写java代码中的常量过一般情况下,我们是定义在string.xml这个文件中.这样修改起来也很方便,而且做国际化也很简单. 这个string.xml的值会被R文件映射, ...
- Jsp监听器
监听器: 监听器就是对内置对象的状态或者属性变化进行监听,并且做出反应的特殊的servlet,在web.xml文件中对监听器进行的配置. 内置对象有两种状态变化:产生.销毁,就是当产生内置对象的时候能 ...
- day11(函数参数,函数对象,打散机制,函数嵌套调用)
一,复习 # 什么是函数:具体特定功能的代码块 - 特定功能代码块作为一个整体,并给该整体命名,就是函数 # 函数的优点: # 1.减少代码的冗余 # 2.结构清晰,可读性强 # 3.具有复用性,开发 ...