Skip to content

Commit 4c1248f

Browse files
committed
Update: 2020/04/10
1 parent 7d15c4c commit 4c1248f

12 files changed

+164
-32
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* @lc app=leetcode.cn id=198 lang=cpp
3+
*
4+
* [198] 打家劫舍
5+
*/
6+
#include "main.h"
7+
8+
// @lc code=start
9+
class Solution {
10+
public:
11+
int rob(vector<int> &nums) {
12+
int n = nums.size();
13+
if (n == 0)
14+
return 0;
15+
if (n == 1)
16+
return nums[0];
17+
vector<int> dp(n, 0);
18+
dp[0] = nums[0];
19+
dp[1] = max(nums[0], nums[1]);
20+
int res = dp[1];
21+
for (int i = 2; i < n; i++) {
22+
dp[i] = max(dp[i - 1], dp[i - 2] + nums[i]);
23+
res = max(res, dp[i]);
24+
}
25+
return res;
26+
}
27+
};
28+
// @lc code=end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* @lc app=leetcode.cn id=238 lang=cpp
3+
*
4+
* [238] 除自身以外数组的乘积
5+
*/
6+
#include "main.h"
7+
8+
// @lc code=start
9+
class Solution {
10+
public:
11+
vector<int> productExceptSelf(vector<int> &nums) {
12+
vector<int> res;
13+
int t = 1;
14+
for (int num : nums) {
15+
res.push_back(t);
16+
t *= num;
17+
}
18+
t = 1;
19+
for (int i = nums.size() - 1; i >= 0; --i) {
20+
res[i] *= t;
21+
t *= nums[i];
22+
}
23+
return res;
24+
}
25+
};
26+
// @lc code=end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* @lc app=leetcode.cn id=279 lang=cpp
3+
*
4+
* [279] 完全平方数
5+
*/
6+
#include "main.h"
7+
8+
// @lc code=start
9+
class Solution {
10+
public:
11+
int numSquares(int n) {
12+
vector<int> dp(n + 1);
13+
for (int i = 1; i <= n; i++) {
14+
dp[i] = i;
15+
for (int j = 1; j * j <= i; ++j)
16+
dp[i] = min(dp[i], dp[i - j * j] + 1);
17+
}
18+
return dp[n];
19+
}
20+
};
21+
// @lc code=end

LeetCode/C/55-greedy-跳跃游戏.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
class Solution {
1010
public:
1111
bool canJump(vector<int> &nums) {
12-
int m_pos = 0;
12+
int max_pos = 0;
1313
for (int i = 0; i < nums.size(); i++) {
14-
if (i > m_pos)
14+
if (i > max_pos)
1515
return false;
16-
m_pos = max(m_pos, i + nums[i]);
16+
max_pos = max(max_pos, i + nums[i]);
1717
}
1818
return true;
1919
}

MIOJ/001.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
long long a, b;
5+
while (scanf("%lld%lld", &a, &b) != EOF)
6+
printf("%lld\n", a + b);
7+
return 0;
8+
}

MIOJ/001.cpp

Lines changed: 0 additions & 10 deletions
This file was deleted.

MIOJ/002.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
int res = 0, t;
5+
while (scanf("%d", &t) != EOF)
6+
res ^= t;
7+
printf("%d\n", res);
8+
return 0;
9+
}

MIOJ/002.cpp

Lines changed: 0 additions & 14 deletions
This file was deleted.

MIOJ/010.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
int n;
5+
scanf("%d", &n);
6+
if (n <= 2)
7+
printf("%d", n);
8+
else {
9+
int a = 1, b = 2;
10+
for (int i = 3; i <= n; i++) {
11+
b = a + b;
12+
a = b - a;
13+
}
14+
printf("%d", b);
15+
}
16+
return 0;
17+
}

PTA/DataStructure/C/7-4.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
5+
#define MAXN 100010
6+
7+
int a[MAXN], b[MAXN];
8+
9+
void build(int n, int t[]) {
10+
memset(t, -1, sizeof(int) * MAXN);
11+
int data, idx;
12+
while (n--) {
13+
idx = 1;
14+
scanf("%d", &data);
15+
while (1) {
16+
if (t[idx] == -1) {
17+
t[idx] = data;
18+
break;
19+
} else if (data < t[idx])
20+
idx <<= 1;
21+
else
22+
idx = idx * 2 + 1;
23+
}
24+
}
25+
}
26+
27+
int check(int n) {
28+
for (int i = 1; i <= 2 * n + 1; i++)
29+
if (a[i] != b[i])
30+
return 0;
31+
return 1;
32+
}
33+
34+
int main() {
35+
int n, l;
36+
while (scanf("%d", &n) != EOF && n != 0) {
37+
scanf("%d", &l);
38+
build(n, a);
39+
while (l--) {
40+
build(n, b);
41+
if (check(n))
42+
printf("Yes\n");
43+
else
44+
printf("No\n");
45+
}
46+
}
47+
return 0;
48+
}

0 commit comments

Comments
 (0)