Skip to content

Commit

Permalink
chore: remove dead link
Browse files Browse the repository at this point in the history
  • Loading branch information
alomerry committed Oct 28, 2023
1 parent fb06929 commit 7608451
Show file tree
Hide file tree
Showing 71 changed files with 143 additions and 241 deletions.
1 change: 0 additions & 1 deletion ioi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ IOI赛制:每道题提交之后都有反馈,可以看到“通过”、“
IOI赛制的比赛:PAT、团体程序设计天梯赛、CCF CCSP、洛谷月赛。

- [PTA](https://pintia.cn/problem-sets/dashboard)
- [LeetCode]()
44 changes: 19 additions & 25 deletions ioi/leetcode-medium/16.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,43 @@
---
title: 16. 最接近的三数之和
problem_no: 16
date: 2022-09-18
description:
timeline: false
article: false
category:
- LeetCode
---
# [16\. 3Sum Closest](https://leetcode.cn/problems/3sum-closest/)

## [Description]((https://leetcode.cn/problems/3sum-closest/))
## Description

Related Topics: [数组](https://leetcode.cn/tag/array/), [双指针](https://leetcode.cn/tag/two-pointers/), [排序](https://leetcode.cn/tag/sorting/)
Difficulty: **中等**

Related Topics: [Array](https://leetcode.cn/tag/https://leetcode.cn/tag/array//), [Two Pointers](https://leetcode.cn/tag/https://leetcode.cn/tag/two-pointers//), [Sorting](https://leetcode.cn/tag/https://leetcode.cn/tag/sorting//)

给你一个长度为 `n` 的整数数组 `nums`和 一个目标值 `target`。请你从 `nums`中选出三个整数,使它们的和与 `target` 最接近。

返回这三个数的和。
Given an integer array `nums` of length `n` and an integer `target`, find three integers in `nums` such that the sum is closest to `target`.

假定每组输入只存在恰好一个解。
Return _the sum of the three integers_.

**示例 1:**
You may assume that each input would have exactly one solution.

**Example 1:**

```
输入:nums = [-1,2,1,-4], target = 1
输出:2
解释:与 target 最接近的和是 2 (-1 + 2 + 1 = 2)
Input: nums = [-1,2,1,-4], target = 1
Output: 2
Explanation: The sum that is closest to the target is 2\. (-1 + 2 + 1 = 2).
```

**示例 2:**
**Example 2:**

```
输入:nums = [0,0,0], target = 1
输出:0
Input: nums = [0,0,0], target = 1
Output: 0
Explanation: The sum that is closest to the target is 0\. (0 + 0 + 0 = 0).
```

**提示:**
**Constraints:**

* `3 <= nums.length <= 1000`
* `3 <= nums.length <= 500`
* `-1000 <= nums[i] <= 1000`
* -10<sup>4</sup> <= target <= 10<sup>4</sup>


## Solution

Language: **C++**
Language: **Go**

@[code](@IOI/16-main.cpp)
2 changes: 1 addition & 1 deletion ioi/pat-a/1006-sign-in-and-sign-out.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ where times are given in the format `HH:MM:SS`, and `ID_number` is a string with

## Code

[Github (C++)](https://github.com/Alomerry/algorithm/blob/master/pat/a/){button.button--outline-info.button--rounded}{target="_blank"}



```cpp
Expand Down
2 changes: 1 addition & 1 deletion ioi/pat-a/1008-elevator.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ For each test case, print the total time on a single line.

## Code

[Github (C++)](https://github.com/Alomerry/algorithm/blob/master/pat/a/){button.button--outline-info.button--rounded}{target="_blank"}



```cpp
Expand Down
2 changes: 1 addition & 1 deletion ioi/pat-a/1009-product-of-polynomials.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ For each test case you should output the product of $A$ and $B$ in one line, wit

## Code

[Github (C++)](https://github.com/Alomerry/algorithm/blob/master/pat/a/){button.button--outline-info.button--rounded}{target="_blank"}



```cpp
Expand Down
2 changes: 1 addition & 1 deletion ioi/pat-a/1010-radix.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ equation is impossible, print `Impossible`. If the solution is not unique, outpu

## Code

[Github (C++)](https://github.com/Alomerry/algorithm/blob/master/pat/a/){button.button--outline-info.button--rounded}{target="_blank"}



```cpp
Expand Down
2 changes: 1 addition & 1 deletion ioi/pat-a/1011-world-cup-betting.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ T T W 39.31

## Code

[Github (C++)](https://github.com/Alomerry/algorithm/blob/master/pat/a/){button.button--outline-info.button--rounded}{target="_blank"}



```cpp
Expand Down
2 changes: 1 addition & 1 deletion ioi/pat-a/1012-the-best-rank.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ If a student is not on the grading list, simply output `N/A`.

## Code

[Github (C++)](https://github.com/Alomerry/algorithm/blob/master/pat/a/){button.button--outline-info.button--rounded}{target="_blank"}



```cpp
Expand Down
2 changes: 1 addition & 1 deletion ioi/pat-a/1013-battle-over-cities.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ For each of the _*K*_ cities, output in a line the number of highways need to be

## Code

[Github (C++)](https://github.com/Alomerry/algorithm/blob/master/pat/a/){button.button--outline-info.button--rounded}{target="_blank"}



```cpp
Expand Down
4 changes: 2 additions & 2 deletions ioi/pat-a/1016-phone-bills.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ category:

## Problem

Source: [PAT 1016](){target="_blank"}
Source: [PAT 1016]

### Description

Expand Down Expand Up @@ -104,7 +104,7 @@ Total amount: $638.80

## Code

[Github (C++)](https://github.com/Alomerry/algorithm/blob/master/pat/a/){button.button--outline-info.button--rounded}{target="_blank"}



```cpp
Expand Down
4 changes: 2 additions & 2 deletions ioi/pat-a/1018-public-bike-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ category:

## Problem

Source: [PAT ](){target="_blank"}
Source: [PAT ]

### Description

Expand Down Expand Up @@ -78,7 +78,7 @@ PBMC. The judge’s data guarantee that such a path is unique.

## Code

[Github (C++)](https://github.com/Alomerry/algorithm/blob/master/pat/a/){button.button--outline-info.button--rounded}{target="_blank"}



dijsktra + dfs
Expand Down
4 changes: 2 additions & 2 deletions ioi/pat-a/1020-tree-traversals.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ category:

## Problem

Source: [PAT 1020](){target="_blank"}
Source: [PAT 1020]

### Description

Expand Down Expand Up @@ -51,7 +51,7 @@ numbers in a line must be separated by exactly one space, and there must be no e

## Code

[Github (C++)](https://github.com/Alomerry/algorithm/blob/master/pat/a/){button.button--outline-info.button--rounded}{target="_blank"}



```cpp
Expand Down
2 changes: 1 addition & 1 deletion ioi/pat-a/1021-deepest-root.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Error: 2 components

## Code

[Github (C++)](https://github.com/Alomerry/algorithm/blob/master/pat/a/){button.button--outline-info.button--rounded}{target="_blank"}



```cpp
Expand Down
4 changes: 2 additions & 2 deletions ioi/pat-a/1025-pat-ranking.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ category:

## Problem

Source: [PAT 1025](){target="_blank"}
Source: [PAT 1025]

### Description

Expand Down Expand Up @@ -81,7 +81,7 @@ numbers.

## Code

[Github (C++)](https://github.com/Alomerry/algorithm/blob/master/pat/a/){button.button--outline-info.button--rounded}{target="_blank"}



::: code-tabs
Expand Down
4 changes: 2 additions & 2 deletions ioi/pat-a/1028-list-sorting.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ category:

## Problem

Source: [PAT 1028](){target="_blank"}
Source: [PAT 1028]

### Description

Expand Down Expand Up @@ -100,7 +100,7 @@ same name or grade, they must be sorted according to their ID's in increasing or

## Code

[Github (C++)](https://github.com/Alomerry/algorithm/blob/master/pat/a/){button.button--outline-info.button--rounded}{target="_blank"}



```cpp
Expand Down
4 changes: 2 additions & 2 deletions ioi/pat-a/1030-travel-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ category:

## Problem

Source: [PAT 1030](){target="_blank"}
Source: [PAT 1030]

### Description

Expand Down Expand Up @@ -60,7 +60,7 @@ be no extra space at the end of output.

## Code

[Github (C++)](https://github.com/Alomerry/algorithm/blob/master/pat/a/){button.button--outline-info.button--rounded}{target="_blank"}


::: code-tabs

Expand Down
4 changes: 2 additions & 2 deletions ioi/pat-a/1043-is-it-a-binary-search-tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ category:

## Problem

Source: [PAT 1043](){target="_blank"}
Source: [PAT 1043]

### Description

Expand Down Expand Up @@ -85,7 +85,7 @@ NO

## Code

[Github (C++)](https://github.com/Alomerry/algorithm/blob/master/pat/a/){button.button--outline-info.button--rounded}{target="_blank"}



```cpp
Expand Down
101 changes: 2 additions & 99 deletions ioi/pat-a/1053-path-of-equal-weight.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ category:

## Problem

Source: [PAT 1053](){target="_blank"}
Source: [PAT 1053]

### Description

Expand Down Expand Up @@ -75,101 +75,4 @@ such that A~i~ =B~i~ for i=1,⋯,k, and A~k+1~>B~k+1~.

## Code

[Github (C++)](https://github.com/Alomerry/algorithm/blob/master/pat/a/){button.button--outline-info.button--rounded}{target="_blank"}


```cpp
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#define max_size 101
using namespace std;
int n, m, s, total;
struct node
{
int w;
vector<int> sons;
};
node tree[max_size];
vector<int> path;
bool isRoot[max_size];
bool cmp(int a, int b)
{
if (tree[a].w != tree[b].w)
{
return tree[a].w > tree[b].w;
}
else
{
return false;
}
}
void dfs(int root)
{
total += tree[root].w;
path.push_back(tree[root].w);
if (total > s)
{
total -= tree[root].w;
path.pop_back();
return;
}
else if (total == s)
{
if (tree[root].sons.size() == 0)
for (int i = 0; i < path.size(); i++)
{
cout << path[i];
if (i == path.size() - 1)
{
cout << endl;
}
else
cout << " ";
}
total -= tree[root].w;
path.pop_back();
return;
}
sort(tree[root].sons.begin(), tree[root].sons.end(), cmp);
for (int i = 0; i < tree[root].sons.size(); i++)
{
dfs(tree[root].sons[i]);
}
total -= tree[root].w;
path.pop_back();
}
int main()
{
cin >> n >> m >> s;
fill(isRoot, isRoot + n, true);
for (int i = 0; i < n; i++)
{
cin >> tree[i].w;
}
for (int i = 0; i < m; i++)
{
int a, b, c;
string sa, sc;
cin >> sa >> b;
a = (sa[0] - '0') * 10 + sa[1] - '0';
for (int j = 0; j < b; j++)
{
cin >> sc;
c = (sc[0] - '0') * 10 + sc[1] - '0';
tree[a].sons.push_back(c);
isRoot[c] = false;
}
}
int root;
for (root = 0; root < n; root++)
{
if (isRoot[root])
break;
}
dfs(root);
return 0;
}
```
<!-- [Github (C++)](https://github.com/Alomerry/algorithm/blob/master/pat/a/) -->
2 changes: 1 addition & 1 deletion ioi/pat-a/1062-talent-and-virtue.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ The first line of output must give $M(≤N)$, the total number of people that ar

## Code

[Github (C++)](https://github.com/Alomerry/algorithm/blob/master/pat/a/){button.button--outline-info.button--rounded}{target="_blank"}



```cpp
Expand Down
Loading

0 comments on commit 7608451

Please sign in to comment.