这是第二次参加的网络比赛,虽然是内部的,但也体会了一把比赛的感觉;题目比上次简单多了,会做的也不少,现在把其中我做的问题拿出来分析一下:
A. 《Watermelon》
time limit per test

1 second       memory limit      per test 64 megabytes

input

standard input

output

standard output

One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.

Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.

Input

The first (and the only) input line contains integer number w (1 ≤ w ≤ 100) — the weight of the watermelon bought by the boys.

Output

Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.

Sample test(s)
input
8

output
YES

Note

For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).

这个问题实在太简单了,当然是在能理解题意的前提下,呵呵,我也是用了很长时间才翻译过来。

题意:两个人买了一个西瓜,两个人想把西瓜分成两份,每一份都是偶数的重量,等不等分都可以,问他们是否能成功。

陷阱:考虑w=2的情况。

源代码:

#include<iostream>
using namespace std;
int main()
{int n;cin>>n;if(n==2)cout<<"NO";else if(n%2==0)cout<<"YES"<<endl;else cout<<"NO"<<endl;return 0;
}

第二个问题:

B. 《Before an Exam》

Tomorrow Peter has a Biology exam. He does not like this subject much, but d days ago he learnt that he would have to take this exam. Peter's strict parents made him prepare for the exam immediately, for this purpose he has to study not less than minTimei and not more than maxTimei hours per each i-th day. Moreover, they warned Peter that a day before the exam they would check how he has followed their instructions.

So, today is the day when Peter's parents ask him to show the timetable of his preparatory studies. But the boy has counted only the sum of hours sumTime spent him on preparation, and now he wants to know if he can show his parents a timetable sсhedule with dnumbers, where each number sсhedulei stands for the time in hours spent by Peter each i-th day on biology studies, and satisfying the limitations imposed by his parents, and at the same time the sum total of all schedulei should equal to sumTime.

Input

The first input line contains two integer numbers d, sumTime (1 ≤ d ≤ 30, 0 ≤ sumTime ≤ 240) — the amount of days, during which Peter studied, and the total amount of hours, spent on preparation. Each of the following d lines contains two integer numbersminTimei, maxTimei (0 ≤ minTimei ≤ maxTimei ≤ 8), separated by a space — minimum and maximum amount of hours that Peter could spent in the i-th day.

Output

In the first line print YES, and in the second line print d numbers (separated by a space), each of the numbers — amount of hours, spent by Peter on preparation in the corresponding day, if he followed his parents' instructions; or print NO in the unique line. If there are many solutions, print any of them.

Sample test(s)
input
1 485 7

output
NO

input
2 50 13 5

output
YES1 4

源代码:
#include<iostream>
using namespace std;
int main()
{int i,d,sum,s=0,w=0;int m[31],n[31],t[31];cin>>d>>sum;for(i=1;i<=d;i++)             //输入每天的Min和MAx,并算出最小值总和和最大值总和{cin>>m[i]>>n[i];s+=n[i];w+=m[i];}if(w>sum||s<sum)cout<<"NO";if(w<=sum&&s>=sum){cout<<"YES"<<endl;     //最小值总和与Sum相等的情况if(w==sum)for(i=1;i<=d;i++)cout<<m[i]<<" ";else {for(i=1;i<=d;i++)      //把第i 天可以补充的时间存起来{t[i]=n[i]-m[i];}int  p=1;int e=m[1];while (w+t[p]<=sum)    //从前往后补充时间{m[p]=n[p];w+=t[p];p++;}m[p]=m[p]+sum-w;   for(i=1;i<=d;i++){cout<<m[i];if(i!=d)cout<<" ";}}}return 0;
}

题目分析:题目也不是很难,大意是:Peter在 d 天之后有一场考试,他父母给他规定了一个复习的总时间Sum,Peter要自己制定一个学习计划表,其中每一天都要包含这天学习的最少时间Mini 和最大时间 Maxi ,每一天学习时间 Mini<= timei <=Maxi 是否能达到 父母的规定,既在d 天里学习时间总和为Sum。

不能达到输出“NO”;能达到输出“YES”和每天的学习时间(一种情况即可)。

思路:知道每天的最小时间和最大时间,那么 如果最小时间总和大于Sum,或者最大时间总和小于Sum,那么不能达到要求。如果Sum在最小值总和 与最大值总和之间,那么符合;

我输出的一种情况是:先比较最小值总和与Sum的大小关系,如果相等,那么输出即可,如果不等,那么从前至后依次补充时间数,直到满足为止,注意,最后补充的那一天要特殊处理;而后输出即可;

转载于:https://www.cnblogs.com/sdauyqy/p/3235958.html

A watermeten 《Before an Exam》相关推荐

  1. 前端红宝书《JavaScript高级程序设计》核心知识总结

    此文是对<JavaScript 高级程序设计>一书难点的总结,也是笔者在看了 3 遍之后的一些梳理和感想,希望能借此巩固js的基础和对一些核心概念有更深入的了解. 摘要 JS基本的数据类型 ...

  2. 北师大网络教育计算机试题一的答案,北师大网络教育《专科英语一》作业3部分答案...

    北师大2014春网络教育<专科英语一>作业3部分答案 1. Seldom ______ to the library during his college days. he went di ...

  3. 郑大计算机专业英语01章,郑州大学远程教育《大学英语II》第01章在线测试

    郑州大学远程教育<大学英语II>第01章在线测试 1.He was about _____ home when the phone rang. A.leaves C.to leave B. ...

  4. [渝粤教育] 深圳信息职业技术学院 《新理念英语》English For You 参考 资料

    教育 -<新理念英语>English For You-章节资料考试资料-深圳信息职业技术学院[] Which is true about the introduction? 1.[多选题] ...

  5. 东大22春《大学英语(三)》在线平时作业1答案非答案

    <大学英语(三)>在线平时作业11.[单选题] No one had told Smith about _______ a story in the book. 答案资料下载请参考 说明 ...

  6. Paper:《GPT-4 Technical Report》的翻译与解读

    Paper:<GPT-4 Technical Report>的翻译与解读 目录 Paper:<GPT-4 Technical Report>的翻译与解读 Abstract摘要 ...

  7. 电大管理英语4计算机期末考试,2020年7月电大《管理英语4》期末考试试题及参考答案...

    1.试卷代号:1389 国家开放大学2020年春季学期期末统一考试 管理英语4试题 2020年7月 注意事项 一.将你的学号.姓名及分校(工作站)名称填写在答题纸的规定栏 内.考试结束后,把试卷和答题 ...

  8. 前来推荐一本比较喜欢的读物——《浪潮之巅》

    基本属性 书籍介绍:<浪潮之巅>是一本介绍IT行业兴衰变化的书,书中的内容最早发表在Google黑板报上,经过几年的积累并整理成书. 作者介绍:吴军,美国约翰霍普金斯大学计算机科学博士,其 ...

  9. 《小团团团队》第五次作业:项目需求分析改进与系统设计

    项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 实验九 团队作业5-团队项目需求改进与系统设计 团队名称 小团团团队 作业学习目标 (1)掌握面向对象需求分析方法:(2) ...

最新文章

  1. 某大龄程序员哀叹:夫妻双失业后还不起房贷,被迫断供!四年还了80万,60多万都是利息!...
  2. Android NDK的生命周期JNI_OnLoad与JNI_OnUnload(转)
  3. echarts 雷达图_如何把Echarts用成在线数据可视化工具
  4. cmd 中 net start mysql 提示发生系统错误 5
  5. pom.xml中依赖的<optional>true</optional>标签
  6. Centos7利用fpm制作rpm包(fpm安装及使用)
  7. 我们不再需要 Chrome?
  8. linux sed 1的意思,linux命令(1):sed命令
  9. 搜索算法-广度优先和深度优先搜索
  10. MySQL主从复制: MHA
  11. 开发落网电台windows phone 8应用的计划(9)
  12. .net4.0切换2.0时,SplitContainer”的对象强制转换为类型
  13. ART模式下dex2oat出错导致系统无法正常启动
  14. 关于三角形外心性质的探究
  15. wget不是内部命令 windows_wget 不是内部或外部命令 - 卡饭网
  16. c语言程序设计指针何钦铭ppt,C语言程序设计 教学课件 作者 何钦铭 c2.ppt
  17. 8个亿!河南首富再次无偿捐款西湖大学,西湖大学河南籍校董高达11位
  18. vmwaretools与open-vm-tools都无法使用的解决方法
  19. 【加水印】如何批量加文字水印和图片水印,如何批量添加文件名水印到图片里?图片的名称批量写到图片上面?
  20. 传智播客python培训怎么样

热门文章

  1. BZOJ 2957: 楼房重建
  2. 颠倒整数的C语言程序,帮忙解决c语言题目1.编写一个程序,用户输入一个小于5位的正整数,把它的各位数字前后颠倒一下,并输出颠倒后的结果。2.编...
  3. ubuntu14.04安装完ros后常用的其他安装
  4. Qt 2D painting Demo 的翻译
  5. 查询 oracle_关于oracle和mysql数据库的查询问题
  6. 卷积的物理意义(经典)
  7. luogu P4726 多项式指数函数(模板题FFT、多项式求逆、多项式对数函数)
  8. 怎么把一个控件放到tab页面上去?_移动端页面内容切换
  9. python列表换行写入_如何使用Python3中的换行符将列表写入文件
  10. python对大量数据去重_Python对多属性的重复数据去重实例