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范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
随机推荐
- nginx系列9:HTTP反向代理请求处理流程
HTTP反向代理请求处理流程 如下图:
- Java 单例(Singleton)模式
一.什么是单例模式: 单例模式是一种确保了一个类只有一个实例,而且自行实例化并向整个系统提供这个实例.被实例化的类称为单例类. 二.单例模式的特点: 单例类只有一个实例. 单例类必须自行创建自己唯一的 ...
- mysql生成日期的辅助表
为了解决mysql按日期分组查询统计的时候,没有数据补0.可以生成连续的时间表格来辅助查询* 生成按天的数据 * 每一个小时为一个分段 生成如下辅助表 *代码如下 CREATE TABLE num ( ...
- 01. Overview Redis 关于Redis
LOGO
- MyDAL - is null && is not null 条件 使用
索引: 目录索引 一.API 列表 C# 代码中 instance.property == null 生成 SQL 对应的 is null : 如:.Queryer<Agent>() .. ...
- selenium-webdriver的二次封装(十)
接着上篇随笔 selenium-配置文件定位元素 ,进行了配置文件设置后,将配置文件运用到定位元素中 思路:拿到定位的 key 和 value 后,对 webdrvier 中定位进行封装,使可以直接运 ...
- MySQL Error Number 1005 Can’t create table(Errno:150)
mysql数据库1005错误解决方法 MySQL Error Number 1005 Can’t create table ‘.\mydb\#sql-328_45.frm’ (errno: 150) ...
- 【js】js中判断对数是否为空
1.将json对象转化为json字符串,再判断该字符串是否为"{}" var data = {}; var b = (JSON.stringify(data) == "{ ...
- Linux新增和删除环境变量
vi ~/.bashrc 添加 export 变量名=值 使环境变量生效 source ~/.bashrc
- js循环获取table中的值
<script type="text/javascript"> function getTdValue() { var tableId = document.getEl ...