随笔 - 531  文章 - 0  评论 - 3  阅读 - 10215 

随笔分类 -  杂题

acw 145. 超市
摘要:超市里有n件商品,每件商品都有利润v[i] 和过期时间tm[i] , 每天只能卖一件商品,过期商品不能卖。 求可以得到的最大收益 #include "bits/stdc++.h" using namespace std; const int N=1e5+5; struct T{ int v,tm; 阅读全文
posted @ 2022-12-02 18:14 towboat 阅读(9) 评论(0) 推荐(0) 编辑
一本通1456(哈希表板子
摘要:用map<int,bool> #include "bits/stdc++.h" using namespace std; const int N=1e4+5; #define int unsigned long long const int mod=212370440130137957ll; cha 阅读全文
posted @ 2022-12-01 13:46 towboat 阅读(20) 评论(0) 推荐(0) 编辑
acwing131. 直方图中最大的矩形
摘要:#include "bits/stdc++.h" using namespace std; const int N=1e5+3; #define int long long int n,a[N]; int hh,stk[N],w[N]; void sov(){ hh=0; memset(a,0,si 阅读全文
posted @ 2022-11-30 23:58 towboat 阅读(22) 评论(0) 推荐(0) 编辑
AcWing 130. 火车进出栈问题
摘要:dp (n^2) #include "bits/stdc++.h" using namespace std; int n,f[35][35]; int dp(int i,int j){ if(f[i][j]!=-1) return f[i][j]; f[i][j]=0; if(i==0) retur 阅读全文
posted @ 2022-11-30 22:27 towboat 阅读(24) 评论(0) 推荐(0) 编辑
acw 120. 防线
摘要:给一些区间【l , r】 , 区间i 内间隔 d[i] 有一个点(可能会重复),保证最后只有一个位置的点数为奇数,其他位置的点数为偶数 找出这个点 二分查找 二分点的位置,注意题目中唯一的奇数点 求区间和,判断奇偶性,缩小范围 #include "bits/stdc++.h" using names 阅读全文
posted @ 2022-11-30 16:50 towboat 阅读(12) 评论(0) 推荐(0) 编辑
P1080 [NOIP2012 提高组] 国王游戏
摘要:#include <iostream> #include <algorithm> using namespace std; const int N=1100; struct T{ int x,y; } a[N]; int n; string c[N][2]; int cmp(T &a,T &b){ 阅读全文
posted @ 2022-11-30 14:21 towboat 阅读(120) 评论(0) 推荐(0) 编辑
acwing 112雷达设备
摘要:给n个区间,设置最少的点,每个区间都有至少一个点 区间按照右端点排序,每次贪心取区间右端点 #include <bits/stdc++.h> using namespace std; const int N=5e4+3; struct T{ double l,r; bool operator<(co 阅读全文
posted @ 2022-11-29 22:05 towboat 阅读(26) 评论(0) 推荐(0) 编辑
AcWing 111. 畜栏预定
摘要:有 n头牛在畜栏中吃草。 每个畜栏在同一时间段只能提供给一头牛吃草,所以可能会需要多个畜栏。 给定 n头牛和每头牛开始吃草的时间 A 以及结束吃草的时间 当两头牛的吃草区间存在交集时(包括端点),这两头牛不能被安排在同一个畜栏吃草。 求需要的最小畜栏数目和每头牛对应的畜栏方案。 #include < 阅读全文
posted @ 2022-11-29 18:42 towboat 阅读(20) 评论(0) 推荐(0) 编辑
acwing 110. 防晒
摘要:贪心:按照 a[i] .y 递减排序, 对每个牛取 所有物品的值 最大的 #include <bits/stdc++.h> using namespace std; const int N=2504; struct T{ int x,y; }a[N]; int n,m,cnt[N],val[N]; 阅读全文
posted @ 2022-11-29 16:51 towboat 阅读(9) 评论(0) 推荐(0) 编辑
P1613 跑路 (倍增
摘要:p[i][j][k] 表示 i, j 之间 是否存在 2^k 长度的路径 p[i][j][k] = p[i][mid] && p[mid][j] ,初始化 p[i][j][0] = 0/1 #include <bits/stdc++.h> using namespace std ; const in 阅读全文
posted @ 2022-11-29 15:32 towboat 阅读(13) 评论(0) 推荐(0) 编辑
acwing 103. 电影
摘要:莫斯科正在举办一个大型国际会议,有n个来自不同国家的科学家参会。 每个科学家都只懂得一种语言。 为了方便起见,我们把世界上的所有语言用 1到 1e9 间的整数编号。 电影院里一共有m部电影正在上映,每部电影的语音和字幕都采用不同的语言。 对于观影的科学家来说,如果能听懂电影的语音,他就会很开心;如果 阅读全文
posted @ 2022-11-29 13:23 towboat 阅读(33) 评论(0) 推荐(0) 编辑
acwing113. 特殊排序
摘要:记录交互题这个东西 class Solution { public: vector<int> specialSort(int N) { vector<int> res; res.push_back(1); for(int i=2;i <= N;i++){ int l=0,r=res.size()-1 阅读全文
posted @ 2022-11-29 11:27 towboat 阅读(12) 评论(0) 推荐(0) 编辑
acw 102. 最佳牛围栏
摘要:求一个序列中平均值最大的子序列(长度为m) 二分这个平均值,检验答案:每个数- average , 看能否找到长度为m的序列 #include <iostream> #include <algorithm> #include <map> using namespace std; const int 阅读全文
posted @ 2022-11-29 10:50 towboat 阅读(6) 评论(0) 推荐(0) 编辑
acwing101. 最高的牛
摘要:有 n头牛站成一行,每头牛的身高都为整数。 当且仅当两头牛中间的牛身高都比它们矮时,两头牛方可看到对方。 我们只知道其中最高的牛是第 pos 头,它的身高是H , 剩余牛的身高未知。 知道这群牛之中存在着 t 对关系,每对关系都指明了某两头牛B 可以相互看见。 求每头牛的身高的最大可能值是多少。 # 阅读全文
posted @ 2022-11-29 10:17 towboat 阅读(15) 评论(0) 推荐(0) 编辑
Acwing100 增减序列
摘要:给定一个长度为 n的数列 每次可以选择一个区间 使每个数都加一或者都减一。 求至少需要多少次操作才能使数列中的所有数都一样,并求出在保证最少次数的前提下,最终得到的数列可能有多少种。 求差分数组,操作变为 df[i]++ ,df[j]-- 或者 df[i]-- ,df[j]++ 正负数贪心的对消,剩 阅读全文
posted @ 2022-11-29 09:23 towboat 阅读(16) 评论(0) 推荐(0) 编辑
二维前缀和 P2280 激光炸弹
摘要:#include <iostream> #include <algorithm> using namespace std; int s[5005][5005],n,r; void sov(){ int i,j,ans=0; int x,y,z; cin>>n>>r; r=min(r,5001); f 阅读全文
posted @ 2022-11-29 08:53 towboat 阅读(19) 评论(0) 推荐(0) 编辑
uva 442
摘要:矩阵连乘 用 栈 处理表达式 ((AB)C) #include <iostream> #include <cstdio> #include <string> #include <stack> using namespace std ; struct M{ int a,b; M(int a0=0,in 阅读全文
posted @ 2022-10-30 12:52 towboat 阅读(16) 评论(0) 推荐(0) 编辑
一本通1282 二维前缀和
摘要:找最大子矩阵 数据水 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 阅读(30) 评论(0) 推荐(0) 编辑
uva 1121
摘要:序列 {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 阅读(9) 评论(0) 推荐(0) 编辑
uva 11549
摘要:用缓冲流保存字符串 #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 阅读(15) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示