![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
寒假算法训练5
yuson_g
这个作者很懒,什么都没留下…
展开
-
寒假算法训练5-G(倍速播放电影)
Sample Input 1 19 Sample Output 1 5 Sample Input 2 13 Sample Output 2 5 Sample Input 3 123456789098765 Sample Output 3 85原创 2021-03-05 20:07:53 · 208 阅读 · 0 评论 -
寒假算法训练5-F(从x=1开始选择数组里若干个区间是否加上2的x-1次方,每次相加,x都会加一,直到数组变为严格非递减序列,问最少需要x为多少)
Input 3 4 1 7 6 5 5 1 2 3 4 5 2 0 -4 Output 2 0 3 思路:找出前i个数中最大的,后n-i个数中最小的。做差,求最小值加到大于等于最大值时x最小值。 #include <bits/stdc++.h> using namespace std; typedef long long ll; int n; ll a[100005]; int main() { int t; scanf("%d",&t); while(t--).原创 2021-03-05 16:57:50 · 98 阅读 · 0 评论 -
寒假算法训练5-J(求树的深度,直接dfs)
Sample Input 5 1 2 1 3 2 4 4 5 Sample Output 4 思路:树的各个节点用vector存储即可。 #include <bits/stdc++.h> using namespace std; int n; vector<int> g[1005]; int ans=-1; void dfs(int x,int cnt) { if(g[x].empty()) {ans=max(ans,cnt);return;} for(int i=.原创 2021-03-05 11:56:37 · 57 阅读 · 0 评论 -
寒假算法训练5-E(电子科大卡消费问题)
Sample Input 1 50 5 10 1 2 3 2 1 1 2 3 2 1 50 0 Sample Output -45 32 思路:01背包+贪心问题。用五块钱去买最贵的菜,减去5元后剩下的钱再尽可能多地买剩余的菜。原创 2021-03-05 11:27:06 · 141 阅读 · 1 评论 -
寒假算法训练5-D(找油矿,直接dfs就行)
#include <bits/stdc++.h> using namespace std; const int maxn=200; int n,m; int dis[8][2]={-1,1,-1,-1,1,-1,1,1,0,-1,0,1,1,0,-1,0}; char s[maxn][maxn]; bool vis[maxn][maxn]; template<class T> T read() { T f=1,k=0; char c=getchar(); while(c&l.原创 2021-03-05 10:42:07 · 93 阅读 · 1 评论 -
寒假算法训练5-C(拿决赛衣服路径最短路,dijkstra)
Sample Input 2 1 1 2 3 3 3 1 2 5 2 3 5 3 1 2 0 0 Sample Output 3 2 思路:直接Dijkstra。 #include <bits/stdc++.h> using namespace std; const int maxn=105; int mp[maxn][maxn],dis[maxn]; bool vis[maxn]; vector<int> g[maxn]; int n,m; struct node { .原创 2021-03-05 10:40:22 · 96 阅读 · 1 评论 -
寒假算法训练5-H(按字典序输出相应数量数字,dfs)
Sample Input 4 2 Sample Output 1 2 1 3 1 4 2 3 2 4 3 4 思路:注意深搜的条件,数字未被访问过而且该数字小于ans数组内上一个数字。以及注意回溯。 #include <bits/stdc++.h> using namespace std; int n,m; int a[50]; bool vis[50]; void dfs(int cnt) { if(cnt>m) { for(int i=1;i<m.原创 2021-03-05 10:40:56 · 109 阅读 · 1 评论