随笔分类 -  刷题

摘要:我用的方法是新开一个数组来保存,然后再用assign函数复制到原函数中,注意该函数void类型的,所以不能直接返回新函数。 更好的方法: 先将整个数组左右翻转,然后根据k分别反转左右两部分,用双指针进行swap class Solution { public: void reverse(vector 阅读全文
posted @ 2022-01-15 22:41 Tomorrow1126 阅读(15) 评论(0) 推荐(0) 编辑
摘要:注意从下面往上走。 #include<cstdio> #include<iostream> #include<string> #include<cstring> #include<cmath> #include<stdlib.h> #include<algorithm> #include<vecto 阅读全文
posted @ 2020-10-07 22:04 Tomorrow1126 阅读(64) 评论(0) 推荐(0) 编辑
摘要:一开始用queue超时了,可能是因为太慢了? queue方法: #include<cstdio> #include<iostream> #include<string> #include<cstring> #include<cmath> #include<stdlib.h> #include<alg 阅读全文
posted @ 2020-08-11 14:40 Tomorrow1126 阅读(114) 评论(0) 推荐(0) 编辑
摘要:#include<cstdio> #include<iostream> #include<string> #include<cstring> #include<cmath> #include<stdlib.h> #include<algorithm> #include<vector> #includ 阅读全文
posted @ 2020-08-11 13:22 Tomorrow1126 阅读(96) 评论(0) 推荐(0) 编辑
摘要:还没测试代码能不能通过。 主要思想: 首先把第一个柱子上N-1个移动到第三个上,然后最大的移动到第二个柱子上,然后N-1个再移动回到第一个,最大的移动到第三个,然后剩下N-1移动到第三个。 也就是 2+hannuota(n-1)*3。 N=1时是2次。剩下的递归求解。 之前用的int错了!!! 改成 阅读全文
posted @ 2020-08-10 12:53 Tomorrow1126 阅读(92) 评论(0) 推荐(0) 编辑
摘要:1、最短时间,每个蚂蚁都朝最短的路走 2、最长时间,每个蚂蚁都朝最长的路走。虽然题目说碰到会反方向,但是可以把每个蚂蚁想成是一样的,也就是碰到后,继续朝原来的方向前进。 阅读全文
posted @ 2020-08-09 16:39 Tomorrow1126 阅读(57) 评论(0) 推荐(0) 编辑
摘要:#include<cstdio> #include<iostream> #include<string> #include<cstring> #include<cmath> #include<stdlib.h> #include<algorithm> #include<vector> #includ 阅读全文
posted @ 2020-08-07 15:05 Tomorrow1126 阅读(65) 评论(0) 推荐(0) 编辑
摘要:使用队列queue 数到m,先输出,然后pop 其他的先添加到队尾,再pop #include <cstdio> #include <iostream> #include<string> #include<cstring> #include<cmath> #include<stdlib.h> #in 阅读全文
posted @ 2020-08-02 12:32 Tomorrow1126 阅读(61) 评论(0) 推荐(0) 编辑
摘要:缓冲区是什么:缓冲区又称为缓存,它是内存空间的一部分。也就是说,在内存空间中预留了一定的存储空间,这些存储空间用来缓冲输入或输出的数据,这部分预留的空间就叫做缓冲区。 缓冲区根据其对应的是输入设备还是输出设备,分为输入缓冲区和输出缓冲区。 为什么要引入缓冲区: 比如我们从磁盘里取信息,我们先把读出的 阅读全文
posted @ 2020-08-01 15:09 Tomorrow1126 阅读(394) 评论(0) 推荐(0) 编辑
摘要:#include <cstdio> #include <iostream> #include<string> #include<cstring> #include<cmath> #include<algorithm> using namespace std; int n; int a[105]; i 阅读全文
posted @ 2020-08-01 14:56 Tomorrow1126 阅读(116) 评论(0) 推荐(0) 编辑
摘要:自己尝试使用的方法:超时了 #include <cstdio> #include <iostream> #include<string> #include<cstring> using namespace std; int main() { for(int n=1000;n<=1111;n++) { 阅读全文
posted @ 2020-07-29 15:55 Tomorrow1126 阅读(174) 评论(0) 推荐(0) 编辑
摘要:gcc/g++ 和 clang/clang++ 都是 Linux 下常用的 C/C++ 编译器。gcc 是 GNU 亲儿子,Ubuntu 等常用发行版标配。clang 是后起之秀,配合 llvm,以优秀的前端闻名于世,现在已经是 Mac(XCode) 的默认编译器,微软等大公司都在往上靠,前景一片光 阅读全文
posted @ 2020-07-29 15:13 Tomorrow1126 阅读(15439) 评论(0) 推荐(3) 编辑
摘要:cout << setiosflags(ios::fixed) << setpresition(6) << a << endl; 为输出a这个变量的六位小数 cout << setprecision(3) << a << endl;为输出a这个变量的3位有效数字 #include <iostream 阅读全文
posted @ 2020-07-18 21:14 Tomorrow1126 阅读(825) 评论(0) 推荐(0) 编辑
摘要:#include<iostream> #include<cmath> #include<vector> #include<cstring> using namespace std; int main() { int n; cin>>n; int a[40]; long long num=(long 阅读全文
posted @ 2020-04-08 23:56 Tomorrow1126 阅读(181) 评论(0) 推荐(0) 编辑
摘要:笔记见平板 #include<iostream> #include<algorithm> #include<cmath> #include<vector> using namespace std; vector<string>v; vector<string>::iterator it; int m 阅读全文
posted @ 2020-04-07 18:05 Tomorrow1126 阅读(118) 评论(0) 推荐(0) 编辑
摘要:思路: 找到第一个不相同的开始翻硬币,一定有偶数个不一样的,否则就永远无法实现。然后挨个判断,不一样就翻一次。这样得到的一定是最少的 阅读全文
posted @ 2020-03-28 14:54 Tomorrow1126 阅读(151) 评论(0) 推荐(0) 编辑
摘要:和01背包的区别是每种物品的个数是无限的。 void solve_1() { for(int i=1; i<=n; i++) for(int j=1; j<=W; j++) { dp[i][j]=-1; for(int k=0; k*w[i]<=j; k++) dp[i][j]=max(dp[i][ 阅读全文
posted @ 2020-02-12 22:25 Tomorrow1126 阅读(99) 评论(0) 推荐(0) 编辑
摘要:1、01背包 例如:https://www.luogu.com.cn/problem/P1060 01背包的状态转换方程 f[i,j] = Max{ f[i-1,j-Wi]+Pi( j >= Wi ), f[i-1,j] } f[i,j]表示在前i件物品中选择若干件放在承重为 j 的背包中,可以取得 阅读全文
posted @ 2020-02-12 17:59 Tomorrow1126 阅读(162) 评论(0) 推荐(0) 编辑
摘要:1、先输入再求勾股定理会超时 2、需要一边输入一边求。 #include<iostream> #include<cmath>#include<cstdio> using namespace std; struct node{ int x,y; }p[100001]; int n; double di 阅读全文
posted @ 2020-02-12 14:03 Tomorrow1126 阅读(199) 评论(0) 推荐(0) 编辑
摘要:古时丧葬活动中经常请高僧做法事。仪式结束后,有时会有“高僧斗法”的趣味节目,以舒缓压抑的气氛。 节目大略步骤为:先用粮食(一般是稻米)在地上“画”出若干级台阶(表示N级浮屠)。又有若干小和尚随机地“站”在某个台阶上。最高一级台阶必须站人,其它任意。(如图1所示) 两位参加游戏的法师分别指挥某个小和尚 阅读全文
posted @ 2020-02-10 22:16 Tomorrow1126 阅读(249) 评论(0) 推荐(0) 编辑

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