# 蓝桥算法训练营—普及组 day01 (c++)

5tayhumb1e 2023-02-05 18:03:24

## 1.P2694 接金币

### 1.c++代码

``````#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

const int N = 10000;

struct graph{
int x,y;
}graphs[N];

int t;

bool cmp(graph a,graph b){
return a.y <= b.y;
}

int main(){
ios::sync_with_stdio(false);
cin.tie(0);

cin >> t;
while(t --){
int n;
cin >> n;
for(int i = 1; i <= n; i ++){
cin >> graphs[i].x >> graphs[i].y;
}
sort(graphs + 1,graphs + 1 + n,cmp);

int x = 0;
int y = 0;
bool flag = true;
for(int i = 1; i <= n; i ++){
if(abs(x - graphs[i].x) <= graphs[i].y - y){
x = graphs[i].x;
y = graphs[i].y;
}else{
flag = false;
break;
}
}
if(flag){
cout << "Abletocatch" << endl;
}else{
cout << "Notabletocatch" << endl;
}
}
return 0;
}
``````

## 2.P1372 又是毕业季I

### 1.c++代码

``````#include<iostream>

using namespace std;

int main(){
int n,k;
cin >> n >> k;
cout << n / k;
return 0;
}
``````

## 3.P1106 删数问题

### 1.c++代码

``````#include<iostream>

using namespace std;

const int N = 1e3 + 10;
int q[N],hh = 0,tt = -1;

int main(){
string a;
int k;
cin >> a >> k;
for(int i = 0; i < (int)a.size(); i ++){

if(k >= 0){
while(hh <= tt && (a[i] - '0' < q[tt]) && k > 0){
tt --;
k --;
}
while(hh <= tt && q[tt] == 0 && k != 0){
tt --;
}
q[++tt] = a[i] - '0';
}
}

if(tt - k < 0){
cout << 0;
return 0;
}else{
bool flag = true;
if(tt - k == 0){
cout << q[0];
return 0;
}
for(int i = 0; i <= tt - k; i ++){
if(q[i] != 0 ){
flag = false;
}
if(!flag){
cout << q[i];
}
}
}
return 0;
}
``````

## 4.谈判 - 蓝桥云课 (区间dp)

### 1.c++代码

``````#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;

int n;

int main(){
ios::sync_with_stdio(false);
cin.tie(0);

cin >> n;
priority_queue<int,vector<int>,greater<int> > heap;
for(int i = 0; i < n; i ++){
int x;
cin >> x;
heap.push(x);
}

int res = 0;
while(heap.size() > 1){
int a = heap.top();
heap.pop();

int b = heap.top();
heap.pop();
res += a + b;
heap.push(a + b);
}

cout << res;
return 0;
}
``````
...全文
41 回复 打赏 收藏 举报

3.8w+

2023-02-08 18:50

2023-02-05 18:10

2023-02-05 18:03

刷题！