# L2-001. 紧急救援

## 2.思路：

1.在套用最短路算法的时候增加一个数组weightRes，记录走过的路节点上权重的和，每次扩充一个节点进入已确定的点集中，更新顶点的值。
2.判断的依据首先根据路途最短，在路途相等的情况下，再判断是否点上权重最大。

## 3.代码：

#include<iostream>
#include<queue>
#include<cstdio>
#include<cstring>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

const int MAXN = 1004;
const int INF = 0x3f3f3f3f;
int N, M, S, E;
int G[MAXN][MAXN];
int dist[MAXN];
int pre[MAXN];
int nums[MAXN];
int weights[MAXN];
int weightsRes[MAXN];

bool visited[1004];
void shortestPath()
{
memset(dist, INF, sizeof(dist));

//visited[S] = true;
weightsRes[S] = weights[S];
nums[S] = 1;
dist[S] = 0;
for(int i = 0; i < N; i++){
int minPath = INF;
int u = -1;
for(int j = 0; j < N; j++){
if(visited[j] == false && dist[j] < minPath){
minPath = dist[j];
u = j;
}
}
if(u == -1) break;
visited[u] = true;
for(int j = 0; j < N; j++){
if(visited[j] == false && G[u][j] != INF){
if(dist[j] > G[u][j] + dist[u]){
dist[j] = G[u][j] + dist[u];
nums[j] = nums[u];
pre[j] = u;
weightsRes[j] = weightsRes[u] + weights[j];
}else if(dist[j] == G[u][j] + dist[u]){
nums[j] += nums[u];
if(weightsRes[u] + weights[j] > weightsRes[j]){
weightsRes[j] = weightsRes[u] + weights[j];
pre[j] = u;
}
}
}
}
}

}

void initG()
{
memset(G, INF, sizeof(G));
for(int i = 0; i < N; i++){
G[i][i] = 0;
}
for(int i = 0; i < N; i++){
pre[i] = -1;
}
}

int main()
{
//printf("%d\n", gcd(1, 12));

//freopen("in.txt", "r", stdin);
scanf("%d %d %d %d", &N, &M, &S, &E);
initG();

for(int i = 0; i < N; i++){
scanf("%d", &weights[i]);
}

for(int i = 0; i < M; i++){
int u, v, l;
scanf("%d %d %d", &u, &v, &l);
G[u][v] = l;
G[v][u] = l;
}

shortestPath();

//    for(int i = 0; i < N; i++){
//        printf("%d ", nums[i]);
//    }
//    printf("%d\n", G[5][5]);

printf("%d %d\n", nums[E], weightsRes[E]);
vector<int> res;
int p = E;
while(pre[p] != -1){
res.push_back(p);
p = pre[p];
}
res.push_back(S);
int len = res.size();
for(int i = len-1; i > 0; i--){
printf("%d ", res[i]);
}
printf("%d\n", res[0]);

return 0;
}

# L2-002. 链表去重

## 3.代码：

#include<iostream>
#include<queue>
#include<cstdio>
#include<cstring>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

int mp[1000010];
int next0[1000010];
int n;
bool exist[11000];
bool del[1000010];

int next1[1000010];
int next2[1000010];

int main()
{
//freopen("in.txt", "r", stdin);

for(int i = 0; i < n; i++){
scanf("%d %d %d", &add, &key, &ne);
}
while(p != -1){
int key = abs(mp[p]);
if(false == exist[key]){
exist[key] = true;
}else{
del[p] = true;
}
//printf("%d ", key);
p = next0[p];
}

while(p != -1){
if(del[p] == false){
}
p = next0[p];
}

while(p != -1){
if(del[p] == true){
}
p = next0[p];
}

while(p!=-1){
if(next1[p] != -1)
printf("%05d %d %05d\n", p, mp[p], next1[p]);
else{
printf("%05d %d %d\n", p, mp[p], next1[p]);
}
p = next1[p];
}

while(p!=-1){
if(next2[p] != -1)
printf("%05d %d %05d\n", p, mp[p], next2[p]);
else{
printf("%05d %d %d\n", p, mp[p], next2[p]);
}
p = next2[p];
}
return 0;
}


# 1.题意：

https://www.patest.cn/contests/gplt/L2-003

# 3.代码：

#include<iostream>
#include<queue>
#include<cstdio>
#include<cstring>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

int N;
double sum;
struct Node
{
double money;
double n;
};

Node nodes[1314];

bool cmp(Node p1, Node p2)
{
return p1.money/p1.n > p2.money/p2.n;
}

int main()
{
// freopen("in.txt", "r", stdin);

scanf("%d %lf", &N, &sum);

for(int i = 0; i < N; i++){
scanf("%lf", &nodes[i].n);
}

for(int i = 0; i < N; i++){
scanf("%lf", &nodes[i].money);
}

sort(nodes, nodes+N, cmp);

int i;
double cnt = 0;
double res = 0.;
for(i = 0; i < N; i++){
//printf("%lf ", nodes[i].money);
cnt += nodes[i].n;
if(cnt >= sum){
break;
}
res += nodes[i].money;
}
if(i != N){
cnt -= nodes[i].n;
//printf("%lf ", cnt);
//printf("%.2lf\n", res);
//i--;
res+=nodes[i].money/nodes[i].n*(sum-cnt);
}
printf("%.2lf\n", res);
return 0;
}

# L2-005. 集合相似度

## 1.题意：

https://www.patest.cn/contests/gplt/L2-005

## 3.代码

#include <set>
#include <vector>
#include <cstdio>
using namespace std;
int main() {
int n, m, k, temp, a, b;
scanf("%d", &n);
vector<set<int>> v(n);
for(int i = 0; i < n; i++) {
scanf("%d", &m);
set<int> s;
for(int j = 0; j < m; j++) {
scanf("%d", &temp);
s.insert(temp);
}
v[i] = s;
}
scanf("%d", &k);
for(int i = 0; i < k; i++) {
scanf("%d %d", &a, &b);
int nc = 0, nt = v[b-1].size();
for(auto it = v[a-1].begin(); it != v[a-1].end(); it++) {
if(v[b-1].find(*it) == v[b-1].end()) {
nt++;
} else {
nc++;
}
}
double ans = (double)nc / nt * 100;
printf("%.2f%%\n", ans);
}
return 0;
}

03-26 100

03-26 98
03-26 192
03-26 30
03-29 22
03-20 136
03-20 136
03-19 137
03-24 88
03-24 138
03-22 88
03-26 76
03-26 70
03-04 275