
贪心算法
8yyy
这个作者很懒,什么都没留下…
展开
-
1324:【例6.6】整数区间没看懂
这道题没看懂,输出样例为什么是2???原创 2021-04-05 19:18:42 · 193 阅读 · 0 评论 -
一本通 1323:【例6.5】活动选择
和区间选择有点像,不同可以相交 #include<bits/stdc++.h> using namespace std; int n; int s[10000],t[10000]; pair<int,int>itv[10000]; void solve(){ sort(itv,itv+n); //根据结束时间排序 int ans=0,t=0; for(int i=0;i<n;i++){ if(t<=itv[i].second){ //结束时间<.原创 2021-04-05 11:23:22 · 359 阅读 · 0 评论 -
POJ 3069(Saruman‘s Army)
#include<bits/stdc++.h> using namespace std; const int max_n=10000; int n,r,x[max_n]; void solve(){ sort(x,x+n); //x数组输入可能无序 int i=0,ans=0; while(i<n){ int s=x[i++]; //s是没有被覆盖的最左的点的位置 //一直向右前进知道距离s的距离大于r的点 while(i<n&&x[i]&原创 2021-04-05 10:54:35 · 129 阅读 · 0 评论 -
Best Cow Line
#include<bits/stdc++.h> using namespace std; /* 给定长度N的字串S 构造长度N的字串T,字串T一开始为空串,随后对字串S进行任意操作。 从S头删除一个字符,加到T的尾部 从S尾删除一个字符,加到T的尾部 目标构建字典序尽可能小的T 输入 N = 6 S =“ACDBCB” 输出 ABCBCD 算法思路 通过两个头进行比较,如果相同,向内比较,将比较小的字符插入进字串,每次比较相对较小,自然构建的字串T也是较小 */ int n; ch原创 2021-04-05 10:53:43 · 75 阅读 · 0 评论 -
区间问题
#include<bits/stdc++.h> using namespace std; /* 问题描述 有n项工作,每项工作分别在si开始ti结束。对于每项工作, 你都可以选择参与与否。如果选择参与,则这段时间不可以 干其他工作,尽可能的完成多的工作,那么最多能参与多少 项工作 输入 n = 5 s = {1,2,4,6,8} t = {3,5,7,9,10} 输出 3 最佳思路:在可选的工作中,每次都选取结束最早的工作 */ int n; int s[10000],t[1000原创 2021-04-05 10:51:50 · 106 阅读 · 0 评论 -
硬币问题
思路:每次选择最大的面值 #include<bits/stdc++.h> using namespace std; /* 问题描述 有1元、5元、10元、50元、100元、500元的硬币各C1、C5、C10、C50、C100、C500枚, 先要用这些硬币来支付A元,最少需要多少枚硬币?假定本题存在解。 输入 C1=3,C2=2,C10=1,C50=33,C100=0,C500=2,A=620 输出 6 */ const int v[6]={1,5,10,50,100,500};//记原创 2021-04-05 10:50:59 · 127 阅读 · 0 评论