codeforces 354 D. Transferring Pyramid
3 seconds
256 megabytes
standard input
standard output
Vasya and Petya are using an interesting data storing structure: a pyramid.
The pyramid consists of n rows, the i-th row contains i cells. Each row is shifted half a cell to the left relative to the previous row. The cells are numbered by integers from 1 to as shown on the picture below.
An example of a pyramid at n = 5 is:
This data structure can perform operations of two types:
- Change the value of a specific cell. It is described by three integers: "t i v", where t = 1 (the type of operation), i — the number of the cell to change and v the value to assign to the cell.
- Change the value of some subpyramid. The picture shows a highlighted subpyramid with the top in cell 5. It is described by s + 2numbers: "t i v1 v2 ... vs", where t = 2, i — the number of the top cell of the pyramid, s — the size of the subpyramid (the number of cells it has), vj — the value you should assign to the j-th cell of the subpyramid.
Formally: a subpyramid with top at the i-th cell of the k-th row (the 5-th cell is the second cell of the third row) will contain cells from rows from k to n, the (k + p)-th row contains cells from the i-th to the (i + p)-th (0 ≤ p ≤ n - k).
Vasya and Petya had two identical pyramids. Vasya changed some cells in his pyramid and he now wants to send his changes to Petya. For that, he wants to find a sequence of operations at which Petya can repeat all Vasya's changes. Among all possible sequences, Vasya has to pick the minimum one (the one that contains the fewest numbers).
You have a pyramid of n rows with k changed cells. Find the sequence of operations which result in each of the k changed cells being changed by at least one operation. Among all the possible sequences pick the one that contains the fewest numbers.
The first line contains two integers n and k (1 ≤ n, k ≤ 105).
The next k lines contain the coordinates of the modified cells ri and ci (1 ≤ ci ≤ ri ≤ n) — the row and the cell's number in the row. All cells are distinct.
Print a single number showing how many numbers the final sequence has.
4 5
3 1
3 3
4 1
4 3
4 4
10
7 11
2 2
3 1
4 3
5 1
5 2
5 5
6 4
7 2
7 3
7 4
7 5
26
One of the possible solutions of the first sample consists of two operations:
2 4 v4 v7 v8
2 6 v6 v9 v10
The picture shows the changed cells color-highlighted. The subpyramid used by the first operation is highlighted blue and the subpyramid used by the first operation is highlighted yellow:
————————————————————————
这道题的中文题解似乎没有,贡献一篇
终于体现了板子的优越性【?】
这样的话我们就可以愉快的做完这道题
不过写起来真的超。多。坑。
建议大家写一写,跳一跳坑,有助于代码能力的成长
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#define inf 0x7f7f7f7f
//#define ivorysi
#define siji(i,x,y) for(int i=(x);i<=(y);++i)
#define gongzi(j,x,y) for(int j=(x);j>=(y);--j)
#define xiaosiji(i,x,y) for(int i=(x);i<(y);++i)
#define sigongzi(j,x,y) for(int j=(x);j>(y);--j)
using namespace std;
int n,k;
vector<int> c[];
int ans;
int f[];
int sum[],cost[];//数组不要开小qwq
void init() {
scanf("%d %d",&n,&k);
int a,b;
siji(i,,k) {
scanf("%d%d",&a,&b);
c[b].push_back(n-a+);
}
ans=*k;
}
void solve() {
init();
int t;
siji(i,,n) {
t=min(n-i+,);
memset(sum,,sizeof(sum));
cost[]=f[];
xiaosiji(z,,c[i].size()) {if(c[i][z]<=t)sum[c[i][z]]=;}
//因为我们枚举只到了(6k)^0.5,所以这以后的都不再统计,防止爆数组
siji(z,,t+) sum[z]+=sum[z-];
siji(z,,t) cost[z]=max(cost[z-],f[z]);
if(i==) {
siji(z,,t+) f[z]=-inf;
}
xiaosiji(j,,t) {
if(j==) {
f[j]=max(f[j+],cost[]-)+*sum[j+];
f[j]=max(f[j],cost[]);//0是我们选择不在这一列放的唯一途径
}
else {
f[j]=max(f[j+],cost[j]-(j+)*(j+)/-)+*sum[j+];
}
} }
printf("%d\n",ans-f[]);
}
int main(int argc, char const *argv[])
{
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
solve();
return ;
}
codeforces 354 D. Transferring Pyramid的更多相关文章
- codeforces 354 DIV2
B - Pyramid of Glasses n层杯子,问k分钟能流满多少个杯子?和到香槟一样的过程? 思路:应为水的流速为每分钟一立方体(YY),可以做个转化,把最上层的杯子最原始的容积看成K,每个 ...
- codeforces 354 div2 C Vasya and String 前缀和
C. Vasya and String time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #354 (Div. 2) B. Pyramid of Glasses 模拟
B. Pyramid of Glasses 题目连接: http://www.codeforces.com/contest/676/problem/B Description Mary has jus ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #354 (Div. 2)-B
B. Pyramid of Glasses 题目链接:http://codeforces.com/contest/676/problem/B Mary has just graduated from ...
- Codeforces Round #354 (Div. 2)
贪心 A Nicholas and Permutation #include <bits/stdc++.h> typedef long long ll; const int N = 1e5 ...
- Codeforces Round #354 (Div. 2)-D
D. Theseus and labyrinth 题目链接:http://codeforces.com/contest/676/problem/D Theseus has just arrived t ...
- Codeforces Round #354 (Div. 2)-C
C. Vasya and String 题目链接:http://codeforces.com/contest/676/problem/C High school student Vasya got a ...
- Codeforces Round #354 (Div. 2)-A
A. Nicholas and Permutation 题目链接:http://codeforces.com/contest/676/problem/A Nicholas has an array a ...
随机推荐
- windows下静态编译pthread
1. Building the library as a statically linkable library-------------------------------------------- ...
- 数据分析与展示---Numpy数据存取与函数
简介 一:数据的CSV文件存取(一维或二维) (一)写入文件savetxt (二)读取文件loadtxt 二:多维数据的存取 (一)保存文件tofile (二)读取文件fromfile (三)NumP ...
- src.rpm包的解压
有时候,我们在找源码包时候,发现有src.rpm的包:而不是tar.gz/tgz/zip结尾的. 那么如何去看这个src.rpm里面的详细信息呢? 看完下面这个例子,基本上明白了. 1,首先,生成sp ...
- spring框架学习(六)AOP事务及spring管理事务方式之Template模板
概念 1.事务 1)事务特性:ACID 原子性 :强调事务的不可分割. 一致性 :事务的执行的前后数据的完整性保持一致. 隔离性 :一个事务执行的过程中,不应该受到其他事务的干扰. 持久性 :事务一旦 ...
- [大数据测试]ETL测试或数据仓库测试入门
转载自: http://blog.csdn.net/zhusongziye/article/details/78633934 概述 在我们学习ETL测试之前,先了解下business intellig ...
- 《C语言程序设计基础I》秋季学习总结
希望下学期比这学期轻松,学习能力上升,只是越发丰富. 一步一步的走踏实了
- Android平台介绍
一.Android平台介绍 什么是智能手机 具有独立的操作系统,独立的运行空间,可以由用户自行安装软件.游戏.导航等第三方应用程序,并可以通过移动通讯网络来实现无线网络接入的手机类型总称. 智能手机操 ...
- 编写shell脚本一键启动zookeeper集群!!
踩了一个多小时坑终于解决了: 这里分享给大家,更主要的目的是记住这些坑,避免以后重复走!!! 首先,这里采用ssh秘钥方式进行集群主机之间免密登录执行启动命令 这里简单说下原理: 通过ssh去另外一台 ...
- springcloud的Turbine配置监控多个服务的一些坑!!!!InstanceMonitor$MisconfiguredHostException,No message available","path":"/actuator/hystrix.stream,页面不显示服务或者一直loading
踩了几个小时坑,使用仪表盘监控单个服务的时候很容易,但是一到多个服务,瞬间坑就来了,大概碰到下面三个: 1InstanceMonitor$MisconfiguredHostException, No ...
- phpStudy apache无法启动 apache启动后又停止
一.是防火墙拦截: 二.是80端口已经被别的程序占用,如IIS,迅雷等: 三.是没有安装VC9运行库,php和apache都是VC9编译: 四.虚拟机配置路径中有中文: 五.在检测端口后强制重启 把配 ...