随笔分类 -  手敲代码

摘要:package homwk; import java.util.Arrays; import java.util.Scanner; public class hmwk6 { public static void main(String[] args) { @SuppressWarnings("res 阅读全文
posted @ 2020-12-16 17:50 然终酒肆 阅读(78) 评论(0) 推荐(0)
摘要:二分查找 主要是其中的细节 这些位置的判断 不去自己调试真的不知道。。。到了考场上如果要手写,连bug也不知道 我也不知道程序设计要笔试是什么意思 本身就是很傻的行为 考作业题 考背诵么? package Test; public class Main { public static void ma 阅读全文
posted @ 2020-12-16 11:10 然终酒肆 阅读(73) 评论(0) 推荐(0)
摘要:package Test; import java.util.Scanner; import java.text.DecimalFormat; import java.util.Random; public class Main { static DecimalFormat df = new Dec 阅读全文
posted @ 2020-12-16 10:36 然终酒肆 阅读(72) 评论(0) 推荐(0)
摘要:1. 斐波那契 package Test; import java.util.Scanner; //import java.util.*; public class Main { public static int f(int a) { if(a<0) return -1; if(a == 0) { 阅读全文
posted @ 2020-12-16 10:30 然终酒肆 阅读(90) 评论(0) 推荐(0)
摘要:递归: import java.util.Scanner; //import java.util.*; public class Main { public static String f(int base,int num){ String str=""; String wait="01234567 阅读全文
posted @ 2020-12-16 09:50 然终酒肆 阅读(130) 评论(0) 推荐(0)
摘要:今天复习dfs 这个题很简单 我们用dfs搜 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val 阅读全文
posted @ 2020-12-16 09:30 然终酒肆 阅读(84) 评论(0) 推荐(0)
摘要:给定一个整数数组,判断是否存在重复元素。 如果任意一值在数组中出现至少两次,函数返回 true 。如果数组中每个元素都不相同,则返回 false 。 最简洁的代码: set函数去重 class Solution: def containsDuplicate(self, nums: List[int] 阅读全文
posted @ 2020-12-13 14:51 然终酒肆 阅读(639) 评论(0) 推荐(0)
摘要:水题 主要是发现poj一堆练这个的 不明所以 所以练练 http://poj.org/problem?id=3320 思路很简单 找到包含所有id的一个区间 对那个区间进行缩小 注意要count最少的出连续的个数 1 #include<iostream> 2 #include<cstdio> 3 # 阅读全文
posted @ 2020-10-30 12:29 然终酒肆 阅读(83) 评论(0) 推荐(0)
摘要:#include<bits/stdc++.h> using namespace std; #define MAXSIZE 1000 typedef struct Linklist { char data; struct Linklist *lchild,*rchild; }Node; Linklis 阅读全文
posted @ 2020-10-10 15:32 然终酒肆 阅读(146) 评论(0) 推荐(0)
摘要:本质上字符串这种题都可以暴力穷举 但是还是要用更好的算法试试 我开始没有想到这是一道可以用动态规划解决的问题 1 class Solution { 2 public: 3 string longestPalindrome(string s) { 4 int n = s.size(); 5 vecto 阅读全文
posted @ 2020-10-03 10:53 然终酒肆 阅读(156) 评论(0) 推荐(0)
摘要:并不是很难 因为完全可以暴力去做 也可以参照kmp 但是我要说的是 这种题也可以用很经典得到滑动窗口 1 class Solution { 2 public: 3 int lengthOfLongestSubstring(string s) { 4 // 哈希集合,记录每个字符是否出现过 5 uno 阅读全文
posted @ 2020-10-03 10:29 然终酒肆 阅读(184) 评论(0) 推荐(0)
摘要:1 class Solution { 2 public: 3 int minimumOperations(string leaves) { 4 int n = leaves.size(); 5 vector<vector<int>> f(n, vector<int>(3)); 6 f[0][0] = 阅读全文
posted @ 2020-10-03 00:51 然终酒肆 阅读(170) 评论(0) 推荐(0)
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 int w[1001],v[100003],f[1001]={0}; 4 int main() 5 { 6 int m,n; 7 scanf("%d %d",&m,&n); //m容量 n种药材 8 阅读全文
posted @ 2020-10-01 23:15 然终酒肆 阅读(116) 评论(0) 推荐(0)
摘要:1 #include <iostream> 2 #include <string> 3 #include <stdio.h> 4 #include <cmath> 5 #include <algorithm> 6 using namespace std; 7 8 bool judge(string 阅读全文
posted @ 2020-09-30 12:43 然终酒肆 阅读(290) 评论(0) 推荐(0)
摘要:1 #include <cstdio> 2 #include <set> 3 #include <iostream> 4 #include <cstring> 5 using namespace std; 6 7 8 9 int main() 10 { 11 int n, i, cnt = 0;in 阅读全文
posted @ 2020-09-30 10:29 然终酒肆 阅读(267) 评论(0) 推荐(0)
摘要:Description给定一个n*n的棋盘,棋盘中有一些位置不能放皇后。现在要向棋盘中放入n个黑皇后和n个白皇后,使任意的两个黑皇后都不在同一行、同一列或同一条对角线上,任意的两个白皇后都不在同一行、同一列或同一条对角线上。问总共有多少种放法?n小于等于8。Input输入描述:输入的第一行为一个整数 阅读全文
posted @ 2020-09-30 09:40 然终酒肆 阅读(121) 评论(0) 推荐(0)
摘要:西洋棋中的皇后可以直线前进,吃掉遇到的所有棋子,如果棋盘上有八个皇后, 则这八个皇后如何相安无事的放置在棋盘上 解法 关于棋盘的问题,都可以用递归求解, 然而如何减少递归的次数?在八个皇后的问题中, 不必要所有的格子都检查过,例如若某列检查过,该该列的其它格子就不用再检查了,这个方法称为分支修剪。 阅读全文
posted @ 2020-09-28 23:39 然终酒肆 阅读(140) 评论(0) 推荐(0)
摘要:1 /** 2 * C: Dijkstra算法获取最短路径(邻接矩阵) 3 * 6 */ 7 8 #include <stdio.h> 9 #include <stdlib.h> 10 #include <malloc.h> 11 #include <string.h> 12 13 #define 阅读全文
posted @ 2020-09-27 11:59 然终酒肆 阅读(437) 评论(0) 推荐(0)
摘要:如果我每一步迈上1个或两个台阶,先迈左脚,然后左右交换,最后一步迈右脚,也就是一共要走偶数步, 那么,上完39级台阶,有多少种不同的算法 1 #include "stdio.h" 2 int total=0;//计数 3 int Sum(int num,int step) 4 { 5 if(num< 阅读全文
posted @ 2020-09-26 16:21 然终酒肆 阅读(139) 评论(0) 推荐(0)
摘要:其实用现成的c++ 库中的sort排序就可以完美解决 但是为了体会算法的本质 我还要敲一遍别的 问题描述 给定一个长度为n的数列,将这个数列按从小到大的顺序排列。 1<=n<=200 输入格式 第一行为一个整数n。 第二行包含n个整数,为待排序的数,每个整数的绝对值小于 10000。 输出格式 输出 阅读全文
posted @ 2020-09-26 15:45 然终酒肆 阅读(364) 评论(0) 推荐(0)