3月18 周作业题解
寒冰王座
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 38 Accepted Submission(s) : 18
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
死亡骑士:"我要买道具!"
地精商人:"我们这里有三种道具,血瓶150块一个,魔法药200块一个,无敌药水350块一个."
死亡骑士:"好的,给我一个血瓶."
说完他掏出那张N元的大钞递给地精商人.
地精商人:"我忘了提醒你了,我们这里没有找客人钱的习惯的,多的钱我们都当小费收了的,嘿嘿."
死亡骑士:"......"
死亡骑士想,与其把钱当小费送个他还不如自己多买一点道具,反正以后都要买的,早点买了放在家里也好,但是要尽量少让他赚小费.
现在死亡骑士希望你能帮他计算一下,最少他要给地精商人多少小费.
Input
注意:地精商店只有题中描述的三种道具.
Output
Sample Input
2 900 250
Sample Output
0 50 思路:简单的完全背包,模板题。
#include<iostream> #include<cstdio> #include<string> #include<vector> #include<cstring> #include<algorithm> #include<map> #include<set>using namespace std;int T; int n; int money[3]={150,200,350}; int dp[10005];int main() {cin>>T;for(int i=0;i<3;i++){for(int j=money[i];j<10005;j++){dp[j]=max(dp[j],dp[j-money[i]]+money[i]);}}while(T--){cin>>n;cout<<n-dp[n]<<endl;}return 0; }
悼念512汶川大地震遇难同胞——珍惜现在,感恩生活
Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 70 Accepted Submission(s) : 11
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
为了挽救灾区同胞的生命,心系灾区同胞的你准备自己采购一些粮食支援灾区,现在假设你一共有资金n元,而市场有m种大米,每种大米都是袋装产品,其价格不等,并且只能整袋购买。
请问:你用有限的资金最多能采购多少公斤粮食呢?
后记:
人生是一个充满了变数的生命过程,天灾、人祸、病痛是我们生命历程中不可预知的威胁。
月有阴晴圆缺,人有旦夕祸福,未来对于我们而言是一个未知数。那么,我们要做的就应该是珍惜现在,感恩生活——
感谢父母,他们给予我们生命,抚养我们成人;
感谢老师,他们授给我们知识,教我们做人
感谢朋友,他们让我们感受到世界的温暖;
感谢对手,他们令我们不断进取、努力。
同样,我们也要感谢痛苦与艰辛带给我们的财富~
Input
Output
Sample Input
1 8 2 2 100 4 4 100 2
Sample Output
400 思路:多维背包,直接转换成01背包处理即可,推荐使用二进制优化,当然也可以简单的分成一件件(给出的代码就是最基本的转换方法)。
#include<algorithm> #include<iostream> #include<algorithm> #include<cstring>using namespace std; #define M 10000int ans[M]; int sale[M], wei[M], num[M];int main() {int T;int money, spe, count;cin >> T;while (T--){memset(ans, 0, sizeof(ans));cin >> money >> spe;count = spe;for (int i = 1; i <= spe; i++){cin >> sale[i] >> wei[i] >> num[i];}for (int i = 1; i <= spe; i++){while (num[i]>1){num[i]--;count++;wei[count] = wei[i];sale[count] = sale[i];}}for (int i = 1; i <= count; i++) {for (int j = money; j >= sale[i]; j--) {ans[j] = max(ans[j], ans[j - sale[i]] + wei[i]);}}cout << ans[money] << endl;}return 0; }
湫湫系列故事——减肥记I
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 19 Accepted Submission(s) : 9
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
但是对于女生来说,卡路里(热量)是天敌啊!
资深美女湫湫深谙“胖来如山倒,胖去如抽丝”的道理,所以她希望你能帮忙制定一个食谱,能使她吃得开心的同时,不会制造太多的天敌。
当然,为了方便你制作食谱,湫湫给了你每日食物清单,上面描述了当天她想吃的每种食物能带给她的幸福程度,以及会增加的卡路里量。
Input
每组数据以一个整数n开始,表示每天的食物清单有n种食物。
接下来n行,每行两个整数a和b,其中a表示这种食物可以带给湫湫的幸福值(数值越大,越幸福),b表示湫湫吃这种食物会吸收的卡路里量。
最后是一个整数m,表示湫湫一天吸收的卡路里不能超过m。
[Technical Specification]
1. 1 <= n <= 100
2. 0 <= a,b <= 100000
3. 1 <= m <= 100000
Output
Sample Input
3 3 3 7 7 9 9 10 5 1 1 5 3 10 3 6 8 7 5 6
Sample Output
10 20 思路:还是完全背包。。。。。
#include<algorithm> #include<iostream> #include<cstring>using namespace std;int n,limit; int dp[100005]; struct Data {int get;int out; }food[105];int main() {while(cin>>n){memset(dp,0,sizeof(dp));for(int i=1;i<=n;i++){cin>>food[i].get>>food[i].out;}cin>>limit;for(int i=1;i<=n;i++){for(int j=food[i].out;j<=limit;j++){dp[j]=max(dp[j],dp[j-food[i].out]+food[i].get);}}cout<<dp[limit]<<endl;}return 0; }
畅通工程
Time Limit : 4000/2000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 17 Accepted Submission(s) : 8
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
注意:两个城市之间可以有多条道路相通,也就是说
3 3
1 2
1 2
2 1
这种输入也是合法的
当N为0时,输入结束,该用例不被处理。
Output
Sample Input
4 2 1 3 4 3 3 3 1 2 1 3 2 3 5 2 1 2 3 5 999 0 0
Sample Output
1 0 2 998
Hint
Huge input, scanf is recommended.
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio>using namespace std;int ans; int n,m; int u,v; int boss[1010];void init() {ans=0;for(int i=0;i<=n;i++){boss[i]=i;} }int find(int k) {if(boss[k]==k){return k;}boss[k]=find(boss[k]);return boss[k]; }void mercy(int x,int y) {int t_1,t_2;t_1=find(x);t_2=find(y);if(t_1>t_2){boss[t_2]=t_1;}else{boss[t_1]=t_2;} }int main() {while(scanf("%d",&n)!=EOF && n){cin>>m;init();for(int i=1;i<=m;i++){cin>>u>>v;mercy(u,v);}for(int i=1;i<=n;i++){if(boss[i]==i){ans++;}}cout<<ans-1<<endl;}return 0; }
还是畅通工程
Time Limit : 4000/2000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 22 Accepted Submission(s) : 6
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
当N为0时,输入结束,该用例不被处理。
Output
Sample Input
3 1 2 1 1 3 2 2 3 4 4 1 2 1 1 3 4 1 4 1 2 3 3 2 4 2 3 4 5 0
Sample Output
3 5
Hint
Huge input, scanf is recommended.
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio>using namespace std;int n; int m; int ans; int Count; int boss[100]; struct Data {int u;int v;int len; }load[5000];void init() {ans=Count=0;m=n*(n-1)/2;for(int i=1;i<=n;i++){boss[i]=i;} }int cmp(Data &a,Data &b) {return a.len<b.len; }int find(int k) {if(boss[k]==k){return k;}boss[k]=find(boss[k]);return boss[k]; }void mercy(int x,int y) {int t_1,t_2;t_1=find(x);t_2=find(y);if(t_1!=t_2){boss[t_2]=t_1;} }int main() {while(scanf("%d",&n)!=EOF && n){init();for(int i=1;i<=m;i++){cin>>load[i].u>>load[i].v>>load[i].len;}sort(load+1,load+m+1,cmp);for(int i=1;i<=m;i++){if(find(load[i].u)!=find(load[i].v)){mercy(load[i].u,load[i].v);ans+=load[i].len;Count++;}if(Count==n-1){break;}}cout<<ans<<endl;}return 0; }
继续畅通工程
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 10 Accepted Submission(s) : 5
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
当N为0时输入结束。
Output
Sample Input
3 1 2 1 0 1 3 2 0 2 3 4 0 3 1 2 1 0 1 3 2 0 2 3 4 1 3 1 2 1 0 1 3 2 1 2 3 4 1 0
Sample Output
3 1 0 思路:依然是最小生成树,不过有些路已经修好,那就先把这些路排在前面,然后成本设置为0就可以了。
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio>using namespace std;int n; int m; int ans; int Count; int boss[100]; struct Data {int ok;int u;int v;int len; }load[5000];void init() {ans=Count=0;m=n*(n-1)/2;for(int i=1;i<=n;i++){boss[i]=i;} }int cmp(Data &a,Data &b) {if(a.ok==b.ok){return a.len<b.len;}else{return a.ok<b.ok;} }int find(int k) {if(boss[k]==k){return k;}boss[k]=find(boss[k]);return boss[k]; }void mercy(int x,int y) {int t_1,t_2;t_1=find(x);t_2=find(y);if(t_1!=t_2){boss[t_2]=t_1;} }int main() {while(scanf("%d",&n)!=EOF && n){init();for(int i=1;i<=m;i++){scanf("%d%d%d%d",&load[i].u,&load[i].v,&load[i].len,&load[i].ok);if(load[i].ok){mercy(load[i].u,load[i].v);}}sort(load+1,load+m+1,cmp);for(int i=1;i<=m;i++){if(load[i].ok==1){break;}if(find(load[i].u)!=find(load[i].v)){mercy(load[i].u,load[i].v);// cout<<load[i].u<<' '<<load[i].v<<' '<<load[i].len<<endl;ans+=load[i].len;Count++;}if(Count==n-1){break;}}cout<<ans<<endl;}return 0; }
畅通工程续
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 5 Accepted Submission(s) : 2
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
现在,已知起点和终点,请你计算出要从起点到终点,最短需要行走多少距离。
Input
每组数据第一行包含两个正整数N和M(0<N<200,0<M<1000),分别代表现有城镇的数目和已修建的道路的数目。城镇分别以0~N-1编号。
接下来是M行道路信息。每一行有三个整数A,B,X(0<=A,B<N,A!=B,0<X<10000),表示城镇A和城镇B之间有一条长度为X的双向道路。
再接下一行有两个整数S,T(0<=S,T<N),分别代表起点和终点。
Output
Sample Input
3 3 0 1 1 0 2 3 1 2 1 0 2 3 1 0 1 1 1 2
Sample Output
2 -1 思路:最短路练习,有Dijkstra算法,Bellman-Ford算法,Floyd算法和SPFA算法都能解决,下面用到是Floyd算法(简单实现但是容易超时)
#include<iostream> #include<algorithm> using namespace std; #define inf 100000 #define M 2005int n, m; int st, ed; int u, v, len; int Map[M][M];void init() {for (int i = 0; i <= n; i++) {for (int j = 0; j <= n; j++) {if (i == j) {Map[i][j] = 0;}else {Map[i][j] = inf;}}} }int main() {while (scanf("%d%d",&n,&m)!=EOF){init();for (int i = 1; i <= m; i++) {cin >> u >> v >> len;if (Map[u][v] > len) {Map[u][v] = len;Map[v][u] = len;}}cin >> st >> ed;for (int k = 0; k < n; k++) {for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {if (Map[i][j] > Map[i][k] + Map[k][j]) {Map[i][j] = Map[i][k] + Map[k][j];}}}}if (Map[st][ed] == inf) {cout << -1 << endl;}else {cout << Map[st][ed] << endl;}}return 0; }
一个人的旅行
Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 3 Accepted Submission(s) : 2
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
接着有T行,每行有三个整数a,b,time,表示a,b城市之间的车程是time小时;(1=<(a,b)<=1000;a,b 之间可能有多条路)
接着的第T+1行有S个数,表示和草儿家相连的城市;
接着的第T+2行有D个数,表示草儿想去地方。
Output
Sample Input
6 2 3 1 3 5 1 4 7 2 8 12 3 8 4 4 9 12 9 10 2 1 2 8 9 10
Sample Output
9 思路:依然是最短路练习,保存下附近城市和目的城市,后面再比较一下距离就可以了。
#include <iostream> #include<algorithm> #include<cstdio>using namespace std; #define M 1010 #define inf 0x3f3f3f3fint n; int ans; int T, S, D; int u, v, w; int Map[M][M]; int Nei[M], Aim[M];void init() {n = 0;ans = inf;for (int i = 1; i <= 1000; i++) {for (int j = 1; j <= 1000; j++) {if (i == j) { Map[i][j] = Map[j][i] = 0; }else{ Map[i][j] = Map[j][i] = inf; }}} }void Get_data() {for (int i = 1; i <= T; i++) {scanf("%d%d%d", &u, &v, &w);if (Map[u][v] > w) {Map[u][v] = Map[v][u] = w;}n = max(n, max(u, v));}for (int i = 1; i <= S; i++) {scanf("%d", &Nei[i]);}for (int i = 1; i <= D; i++) {scanf("%d", &Aim[i]);} }void Dis_data() {for (int k = 1; k <= n; k++) {for (int i = 1; i <= n; i++) {if (Map[i][k] == inf) { continue; }for (int j = 1; j <= n; j++) {if (i == j) { continue; }if (Map[k][j] == inf) { continue; }if (Map[i][j] > Map[i][k] + Map[k][j]) {Map[i][j] = Map[i][k] + Map[k][j];Map[j][i] = Map[i][j];}}}} }void Ans_data() {for (int i = 1; i <= S; i++) {for (int j = 1; j <= D; j++) {ans = min(ans, Map[Nei[i]][Aim[j]]);}}cout << ans << endl; }int main() {while (scanf("%d%d%d", &T, &S, &D) != EOF){init();Get_data();Dis_data();Ans_data();}return 0; }
转载于:https://www.cnblogs.com/caibingxu/p/10553804.html
3月18 周作业题解相关推荐
- 2019年10月18日作业题解
讲真题目质量很低,各种莫名其面的细节,有的题目提交三四遍都过不了.... 口区... 顺便写个题解吧QWQ A题2的多少次幂 Description 从键盘输入一个数x,x是2的整数次幂(x=2^y) ...
- 山东科技大学2020年6月1日作业题解
山东科技大学2020年6月1日作业题解 题目一: STL--灵活的线性表 Description 数组和链表是我们熟知的两种线性结构,但是它们不够灵活(不能同时实现直接插入.删除和访问操作),给你若干 ...
- 3月18日作业-监理师培训
1.监理单位的体系建设分为哪3部分? 答:①业务体系建设.②质保体系建设.③管理体系建设 2.监理单位监理服务质量管理的方式有2种,哪2种?优缺点是什么? 答:①以单位管理.②以监理项目部自我管理 单 ...
- 软考信息系统监理师2016年3月18日作业
第四章监理单位的组织建设 1.监理单位的体系建设分为哪3部分? 答:1.业务体系,2.质保体系建设,3.管理体系建设 2.监理单位监理服务质量管理的方式有2种,哪2种?优缺点是什么? 答:有2种方式, ...
- 软考信息系统监理师,2016年3月18日作业
第四章 监理单位的组织建设 1.监理单位的体系建设分为哪3部分? (1) 业务体系建设 (2) 质保体系建设 (3) 管理体系建设 2.监理单位监理服务质量管理的方式有2种,哪2种?优缺点是什么? ( ...
- 六周第四次课(1月18日)
六周第四次课(1月18日) 复习 扩展 打印某行到某行之间的内容http://ask.apelearn.com/question/559 例如:有个文件test的内容如下: ert fff ** [ ...
- 分享Silverlight/WPF/Windows Phone/HTML5一周学习导读(12月12日-12月18日)
分享Silverlight/WPF/Windows Phone/HTML5一周学习导读(12月12日-12月18日) 本周Silverlight学习资源更新 Silverlight学习小记 阿里山地方 ...
- Windows8/Silverlight/WPF/WP7周学习导读(11月12日-11月18日)
Windows8/Silverlight/WPF/WP7/HTML5周学习导读(11月12日-11月18日) 本周Windows 8开发学习资源更新 快速构建Windows 8风格应用25-数据绑定 ...
- 分享Silverlight/Windows8/WPF/WP7/HTML5周学习导读(6月18日-6月24日)
分享Silverlight/Windows8/WPF/WP7/HTML5周学习导读(6月18日-6月24日) 本周Silverlight学习资源更新 Silverlight读取与设置Cookies 任 ...
最新文章
- 集群 之 LVS + Keepalived
- 添加类iOS cocos2d 2游戏开发实战(第3版)
- 打孔怎么定位_红米K40将要发布,采用居中打孔屏,极窄边框设计
- 编程之美 --1 : 骨牌覆盖问题·一
- window SDK自定义安装路径选择
- Leecode刷题热题HOT100导航目录
- JAVA程序获取Tomcat的运行状态
- Apache与Subversion的简单配置(Apache SVN版本控制)
- React Native ActivityIndicator(菊花组件)
- JUCE框架教程(4)—— Slider Class入门
- linux系统pcre是什么作用,Linux下安装PCRE
- Ehcache配置详解及CacheManager使用
- BIT-Vehicle Dataset - 车辆车型识别数据集
- 从零开始山寨Caffe·伍:Protocol Buffer简易指南
- JSP野生动物保护网
- **京东撸货是什么,京东撸货具体怎么玩,能不能赚钱,我来告诉你**
- linux如何卸载wps,Ubuntu菜鸟入门(三)—— 无用软件卸载,wps等常用软件安装...
- BC v1.2充电规范
- 用计算机投屏图片,电脑网页投屏到电视
- 嵌入式系统开发笔记91:认识ARM微控制器架构