2022年10月26日
摘要: 找最大子矩阵 数据水 O(n^4) 枚举矩形 + O(1) 求和 可以过 那么主要是写下二维前缀和 #include <iostream> #include <algorithm> #include <cstring> using namespace std; const int inf=1<<30 阅读全文
posted @ 2022-10-26 21:36 towboat 阅读(34) 评论(0) 推荐(0)
摘要: 总公司拥有高效设备M台,准备分给下属的N个分公司。各分公司若获得这些设备,可以为国家提供一定的盈利。问:如何分配这M台设备才能使国家得到的盈利最大?求出最大盈利值。其中M≤15,N≤10。分配原则:每个公司有权获得任意数目的设备,但总台数不超过设备数M 虽然是水题,恰巧写一下这种类似背包输出具体方案 阅读全文
posted @ 2022-10-26 21:26 towboat 阅读(9) 评论(0) 推荐(0)
摘要: 序列 {a} ,求最短子序列,且S>=K (S为序列元素的和)a[i]>=0. 暴力如下O(n^2) if(a[i]-a[j]>=K) ans=min(ans,i-j+1) i<j 变形一下 a[j]<=a[j]-K , 我们现在要找最大的这样的 j 注意a[i]>=0 s[i] 前缀和数组是单调序 阅读全文
posted @ 2022-10-26 20:09 towboat 阅读(14) 评论(0) 推荐(0)
摘要: 用缓冲流保存字符串 #include <iostream> #include <string> #include <sstream> #include <set> using namespace std; int n; void upd(int &t){ stringstream ss; ss<<( 阅读全文
posted @ 2022-10-26 17:48 towboat 阅读(18) 评论(0) 推荐(0)
摘要: shui题 #include <iostream> #include <cstring> #include <algorithm> #include <cmath> using namespace std; const int N=1e5+5; int a[N]; int n,m; void sol 阅读全文
posted @ 2022-10-26 16:54 towboat 阅读(6) 评论(0) 推荐(0)
摘要: 有F+1个人来分N个圆形派,每个人得到的必须是一整块派(比如一个圆的1/5) , 而不是几块拼在一起。派的面积要相同。 求每个人最多得到多大面积的派(不必是圆形) 二分答案 假设为x 一个圆 分为 S/x ,算出能划出几块,和总人数比较 #include <iostream> #include <c 阅读全文
posted @ 2022-10-26 16:18 towboat 阅读(9) 评论(0) 推荐(0)
摘要: n个物品(属性有种类,价值,体积) 每个种类的物品挑一个,装入背包(V) , 体积不超V 问最小价值的物品最大是多少? 二分答案,即这个最小价值md 检验: 贪心,只考虑 V[i] >=md 的物品,每个种类挑体积最小的 看能否满足条件 #include <iostream> #include <c 阅读全文
posted @ 2022-10-26 15:45 towboat 阅读(18) 评论(0) 推荐(0)
摘要: 对1 , 2, ,3, ...n 这个序列操作最少的次数,序列元素都为0 又到了手玩样例环节 f(n) =f (n/2) +1 int m; int f(int x){ return x==1?x:f(x/2)+1; } signed main(){ while(cin>>m) cout<<f(m) 阅读全文
posted @ 2022-10-26 14:51 towboat 阅读(10) 评论(0) 推荐(0)
摘要: a[i]<=1000 !!!! #include <iostream> #include <cmath> #include <cstring> using namespace std; int n,b[1003]; int gcd(int x,int y){ return y==0?x:gcd(y, 阅读全文
posted @ 2022-10-26 11:43 towboat 阅读(13) 评论(0) 推荐(0)
摘要: 已知每支股票的价格序列 a , 进行若干次买卖( 一次买卖的收益a[j] - a[i] ) 求最大收益 f[i][0/1] #include <iostream> #include <vector> #include <cstring> using namespace std; const int 阅读全文
posted @ 2022-10-26 10:59 towboat 阅读(19) 评论(0) 推荐(0)