自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(25)
  • 收藏
  • 关注

原创 Fight Monsters

题目https://codeforces.com/problemset/problem/1296/D大神解法:将h[i]设置为还要额外加打的次数,比如怪14血,我攻击力2,队友攻击力3,那么取模后还剩4血,我再来一招,剩2血,这是正常打法,无需用技能换顺序,之和若再按正常打法则被队友打死,但又可能会因为需要加打的次数太多而不确定是否放技能,所以将额外加打次数存下,为1.然后对加打次数排序,...

2020-02-05 11:07:23 188

原创 Food Buying

题目https://codeforces.com/problemset/problem/1296/B买10送1比如你有141元先买140,送14剩14+1=15于是等价于15能买多少,形成递归#include<bits/stdc++.h>using namespace std;#define ll long longint main(){ ll t; c...

2020-02-05 10:46:12 195

原创 Array Sharpening

题目链接https://codeforces.com/contest/1291/problem/B最小为0,且相邻不重复,只能减不能加从左往右,第一个数最小是0,第二个数最小是1…将满足的dpl[i]令为true,直到第一个不满足跳出从右往右,第一个数最小是0,第二个数最小是1…后面同理若存在i,使得dpl[i]==true&&dpr[i]==true,则有峰#in...

2020-02-03 12:03:24 214

原创 地下城游戏--逆动态规划--LeetCode.174

class Solution {public: int calculateMinimumHP(vector<vector<int>>& dungeon) { int row=dungeon.size(); if(row==0)return 0; int col=dungeon[0].size(); ...

2020-02-01 20:52:07 150

原创 逆波兰表达式的求值

class Solution {public: int evalRPN(vector<string>& tokens) { stack<int>nums; queue<char>op; int size=tokens.size(); int i=0; while(i...

2020-01-31 21:22:55 87

原创 链表的归并排序

class Solution {public: ListNode* sortList(ListNode* head) { if(!head||!head->next)return head; return mergeSort(head); } ListNode*mergeSort(ListNode* head){ if...

2020-01-31 20:23:58 67

原创 LeetCode 143:重排链表

找到中点,反转后一半,合并前后class Solution {public: void reorderList(ListNode* head) { if(head==nullptr||head->next==nullptr){ return; } ListNode* slow=head; L...

2020-01-30 16:41:58 99

原创 same gcds

给m,n找出满足gcd(m,n)==gcd(m+x,n)&&x>=0&&m<n的所有整数x的个数#include<bits/stdc++.h>using namespace std;#define ll long longll gcd(ll m, ll n) { return n % m == 0 ? m : gcd(n %...

2020-01-30 12:49:10 277

原创 LeetCode 86: partition list

method 1: 使用两个空头结点记录 ListNode* partition(ListNode* head, int x) { ListNode*before_head=new ListNode(0); ListNode*before=before_head; ListNode*after_head=new ListNode(0); ...

2020-01-28 10:46:06 72

原创 反转链表

ListNode* reverseList(ListNode* head) { ListNode*pre=NULL; ListNode*post=NULL; if(!head)return head; post=head->next; while(post){ head->next...

2020-01-27 22:54:28 69

原创 c++二维vector用特定元素排序时sort中cmp的重写

Method 1:class Solution { public: vector<int> filterRestaurants(vector<vector<int>>& restaurants, int veganFriendly, int maxPrice, int maxDistance) { int size=...

2020-01-27 13:04:52 1401

原创 collecting packages

使用map存下每一列的最大值与最小值合法条件,后一列最小值大于等于前一列最大值#include<bits/stdc++.h>using namespace std;int main() { int n; cin >> n; while (n--) { int m; cin >> m; map<int, vector<i...

2020-01-23 15:53:25 182

原创 vs2019赋值问题不报错

int a = 225.0000000000000000000000001; cout << a; cout<< typeid(1.0).name();结果a是225,1.0是double所以小数默认double,若赋值给float,虽然不会报错,但精度的损失仍是存在的...

2019-12-27 08:43:29 658

原创 leetcode 4Sums

只能说这题绝妙,亦或是我解法较笨class Solution { public List<List<Integer>> fourSum(int[] nums,int target) { List<List<Integer>> ans=new ArrayList<>(); int size=num...

2019-12-25 23:34:02 67

原创 HashMap的使用

class Solution { public int[] twoSum(int[] nums, int target) { HashMap<Integer,Integer> map=new HashMap<>(); for(int i=0;i<nums.length;i++) { map...

2019-12-25 14:00:27 87

原创 leetcode第55题 跳跃游戏

贪心算法

2019-12-24 22:58:13 134

原创 leetcode 第20题 括号生成

回溯算法,排列问题

2019-12-24 14:23:01 89

原创 leetcode 15 3sum

两个数且只要一个结果的,2sum那题可以用HashMap本题3sum,如果要求只要得到一个结果,那么我们可以用一次循环将两数之和存入HashMap,然后找目标数与数组之差这题此种方法显然不符合要求通过Arrays中的sort函数对nums排序每次找一个nums[i]作为目标,用两个指针指向其后数组的两端,从两端向中间逼近,若sum>给定数(本题为0),r–,反之,l++.此法俗...

2019-12-24 09:22:21 66

原创 Java文件的创建与读写

String path="d:/abcde"; File file=new File(path); if(!file.exists()) { try{file.createNewFile();}catch(Exception e) {} } try{FileOutputStream os=new FileOutputStream(path); String s="i ...

2019-12-23 19:56:32 83

原创 leetcode121,买股票最佳时机

解题思路利用一个min存储已读取数据中的最小值,每新加一个数,比较那个数与min的大小,若更小,则令min等于它,否则,让那个数减去min得到一个temp,比较其与max的大小class Solution { public int maxProfit(int[] prices) { if(prices.length<2) return 0; ...

2019-12-23 19:17:17 63

原创 多线程的两种实现方法

class FileTransThread extends Thread{ private String filename; public FileTransThread(String name) { filename=name; } public void run() { System.out.println("transfer"+" "+filename); try { ...

2019-12-23 16:21:55 103

原创 Java排序sort

ArrayList<Integer>ans=new ArrayList<>(); for(int i=0;i<10;i++) { ans.add((int)(Math.random()*100)); System.out.print(ans.get(i)+" "); } System.out.println(); Collect...

2019-12-23 15:42:57 53

原创 帕斯卡三角形

118. Pascal's Triangle

2019-12-23 14:28:34 94

原创 java数组

Java动态二维数组操作

2019-12-23 13:50:54 68

原创 Java的String类

哈哈哈

2019-12-22 19:51:15 63

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除