st

第一周 Largest Rectangle in a Histogram

妖精的绣舞 提交于 2019-11-30 16:04:14
Language: 题目: Largest Rectangle in a Histogram Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 33260 Accepted: 10835 Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heights. For example, the figure on the left shows the histogram that consists of rectangles with the heights 2, 1, 4, 5, 1, 3, 3, measured in units where 1 is the width of the rectangles: Usually, histograms are used to represent discrete distributions, e.g., the frequencies of characters in texts. Note that

[一本通学习笔记] 广度优先搜索和优化

邮差的信 提交于 2019-11-30 15:56:15
BFS的题目没什么好说的,通常优化都是判断可行性,或者状压以后记忆化。几道例题都非常基础。 #10027. 「一本通 1.4 例 2」魔板 暴力写出置换即可。 #include <bits/stdc++.h> using namespace std; int buf[9],tar,ans,src; char vis[99999999]; map <int,string > sta; void A() { swap(buf[1],buf[5]); swap(buf[2],buf[6]); swap(buf[3],buf[7]); swap(buf[4],buf[8]); } void B() { int t1=buf[4], t2=buf[8]; buf[4]=buf[3]; buf[8]=buf[7]; buf[3]=buf[2]; buf[7]=buf[6]; buf[2]=buf[1]; buf[6]=buf[5]; buf[1]=t1; buf[5]=t2; } void C() { int t=buf[2]; buf[2]=buf[6]; buf[6]=buf[7]; buf[7]=buf[3]; buf[3]=t; } int compress() { int ret = 0; for(int i=1;i<=8;i++) ret=ret*10+buf[i]; return

Largest Rectangle in a Histogram 杭电1506

走远了吗. 提交于 2019-11-30 15:52:21
题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=1506 Problem Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heights. For example, the figure on the left shows the histogram that consists of rectangles with the heights 2, 1, 4, 5, 1, 3, 3, measured in units where 1 is the width of the rectangles: Usually, histograms are used to represent discrete distributions, e.g., the frequencies of characters in texts. Note that the order of the rectangles, i.e., their heights, is important.

AtCoder Beginner Contest 116 D - Various Sushi 【贪心+栈】

ぃ、小莉子 提交于 2019-11-30 15:49:58
Problem Statement There are N N pieces of sushi. Each piece has two parameters: "kind of topping" t i ti and "deliciousness" d i di . You are choosing K K among these N N pieces to eat. Your "satisfaction" here will be calculated as follows: The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". The base total deliciousness is the sum of the deliciousness of the pieces you eat. The variety bonus is x ∗ x x∗x , where x x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum

codeforces1156D 0-1-Tree 换根dp

怎甘沉沦 提交于 2019-11-30 14:36:56
题目传送门 题意:   给定一棵n个点的边权为0或1的树,一条合法的路径(x,y)(x≠y)满足,从x走到y,一旦经过边权为1的边,就不能再经过边权为0的边,求有多少边满足条件? 思路:设$f[u]$为以1为根,自下而上到$u$的末节点是1的合法路径数量,$g[u]$代表以1为根,自下而上到$v$末节点是0的合法路径数量,这个可以通过一遍dfs简单求解。   再设$nf[u]$和$ng[u]$代表以u为根的两种合法路径数量,进行换根dfs,在换根的过程中:   若某一条边是0边,则:     $ng[st.to]=ng[u]$,$nf[st.to]=f[st.to]$。这个方程也很好理解,白边的路径是不会变的,所有从父节点自上而下转移过来的黑边到了这里都是非法路径了。   若某一条边是1边,则:     $ng[st.to]=g[st.to]$,$nf[st.to]=nf[u]-g[st.to]+ng[u]$,白边只有从下往上过来的了。黑边要减去 到当前位置为白边与父节点的黑边连接形成的边 ,再加上父节点是白边,加上黑边形成的边。 #pragma GCC optimize (2) #pragma G++ optimize (2) #pragma comment(linker, "/STACK:102400000,102400000") #include<bits/stdc++.h>

圆圈游戏 [扫描线, 计算几何]

左心房为你撑大大i 提交于 2019-11-30 13:19:17
圆 圈 游 戏 圆圈游戏 圆 圈 游 戏 正 解 部 分 \color{red}{正解部分} 正 解 部 分 将所有圆按照 半径 排序, 对第 i i i 个圆, 在 ( i , N ] (i, N] ( i , N ] 中找到一个包含 i i i 的圆 j j j , j j j 向 i i i 连边, 作为 i i i 的父亲, 可以构建出一个森林, 再加一个半径无穷大的圆 N + 1 N+1 N + 1 , 就是一棵树了 . 进行 树形 d p dp d p , 设 F [ i ] F[i] F [ i ] 表示 前 i i i 个圆, i i i 这个圆不选所能得到的最大值, F [ i ] = ∑ max ⁡ ( F [ j ] , w [ j ] ) F[i] = \sum \max(F[j], w[j]) F [ i ] = ∑ max ( F [ j ] , w [ j ] ) , 状态转移复杂度 O ( N ) O(N) O ( N ) , 建树复杂度 O ( N 2 ) O(N^2) O ( N 2 ) . 考虑怎么优化 寻找父亲 的过程, 把所有圆分为上下两个圆弧, 上圆弧 x x x 坐标取左端点, 下圆弧 x x x 坐标取右端点, 按照 x x x 坐标进行排序, 顺序加入 std::set<Hu> 中, 以 过当前的 x x x 坐标且平行于 y y

group:状压dp,轮廓线

喜欢而已 提交于 2019-11-30 07:42:05
神仙题。但是难得的傻孩子cbx没有喊题解,所以也就难得的自己想出来了一个如此神仙的题。 如果是自己想的,说它神仙是不是有点不合适啊。。? 反正的确不好像。关键就在于这个标签。颓完标签就差不多会了。 %%%cbx那么快就想出来了。(2个小时?) 废话多了。 先考虑暴力。对于16的数据范围当然要考虑状压,状态表示每一个位置是否要放兵。 我们只需要考虑左边对右边,上边对下边的贡献,最后把答案×2即可。 然后枚举每一层的状态,逐层转移即可。 复杂度是$O((2^{C})^2 \times C \times R)$,9e12左右 我想到一个没什么用的优化,既然你已经知道了本层的士兵数量,那么那些状态里不合法的就不用枚举了。 预处理一下,复杂度是$O((C_C^{C/2})^2 \times C \times R)$,极端情况3e11左右 但是不要想了,一分也不会多的。 1 #include<cstdio> 2 #include<cstring> 3 #include<vector> 4 #include<iostream> 5 using namespace std; 6 int r,c,num[129],dp[2][1048577],re[1048577][17],loc[1048577][17],scnt[1048577],ANS; 7 char s[129][18]; 8 vector

CF1221G Graph And Number(容斥,搜索,FMT)

我是研究僧i 提交于 2019-11-30 06:18:19
至今觉得这场 edu 的 G 比 EF 都要简单…… 不知道为什么出题人要把 \(m=0\) 放进去,先特判掉。 要求至少一个 \(0\) ,至少一个 \(1\) ,至少一个 \(2\) ,容斥一波,变成总方案数-没有 \(0\) -没有 \(1\) -没有 \(2\) +没有 \(01\) +没有 \(02\) +没有 \(12\) +没有 \(012\) 。 没有 \(0\) 和没有 \(2\) 比较难搞,放到最后讨论。 没有 \(1\) ,考虑一个联通块,这个联通块所有数都一样,方案数是 \(2^{cnt}\) ,其中 \(cnt\) 是联通块个数。 没有 \(01\) ,也就是只有 \(2\) ,如果一个联通块中没有边(单独一个点),那么当然可以随便放,否则这个联通块所有数都是 \(1\) 。方案数 \(2^{cnt2}\) ,其中 \(cnt2\) 是单独一个点的联通块个数。 没有 \(02\) ,也就是只有 \(1\) ,等价于将这个图黑白染色的方案数。如果可以黑白染色,那么方案数是 \(2^{cnt}\) ,否则是 \(0\) 。 没有 \(12\) ,和没有 \(01\) 一样。方案数是 \(2^{cnt2}\) 。 没有 \(012\) ,因为 \(m\ne 0\) ,显然不可能。方案数为 \(0\) 。 接下来就考虑没有 \(0\) 的方案数(没有 \(2\)

个人第二次作业

…衆ロ難τιáo~ 提交于 2019-11-30 03:33:06
GIT地址 https://github.com/fengshikun123/Calculator GIT用户名 fengshikun123 学号后五位 24113 博客地址 https://www.cnblogs.com/q1281037172/ 作业链接 https://edu.cnblogs.com/campus/xnsy/GeographicInformationScience/homework/7582 一、配置环境    1.VS2017安装与配置    2.GIT安装与配置、克隆项目 二、设计随机数四则运算项目   大致上用到switch,也用到了random生成随机数和多个循环语句。然后感觉方法是比较笨的那种,看起来就很长。 运行结果: using System.IO; namespace AchaoCalculate { class CreatFile { public CreatFile(string st) { StreamWriter sw = new StreamWriter("D:/subject.txt", true); sw.WriteLine(st); sw.Close(); } } } using System; using System.IO; using System.Collections.Generic; using System

[洛谷 P1280]尼克的任务

£可爱£侵袭症+ 提交于 2019-11-30 02:58:03
题面 线性DP题,依靠大佬才调出来的我已经不敢说这是简单题了。。 思路: 设f[i]表示从1-i可以休息的时间 状态转移方程; if(is[i]==0) dp[i]=dp[i+1]+1 else dp[i]=max{dp[i],dp[i+a[cnt].last-1]} cnt表示当前的任务序号 AC代码: /* P1280 尼克的任务 */ #include <bits/stdc++.h> #define int long long using namespace std; const int maxn = 1e4 + 10; struct Node { int st, la; } a[maxn]; int tot = 1; int all, n; int dp[maxn]; bool cmp(const Node &a, const Node &b) { return a.st < b.st; } inline int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) f = (ch == '-') ? -1 : 1, ch = getchar(); while (isdigit(ch)) x = x * 10 + (ch - '0'), ch = getchar(); return x *