ACMlecture 02简单数学题

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
第2页共72页201912183从首届舜宇杯说起第3页共72页201912184比赛背景由于前一年的邀请赛很多学校没有做出一道题所以这次的比赛特意准备了几道简单的题目目的就是让大多数的学校都能拿个气球回去也好有个交待于是有
第二讲
老少皆宜之数学题
2020/3/22
1
第1页/共72页
ACM数学题特点分析:
2020/3/22
16
第16页/共72页
Input
There are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed.
31
第31页/共72页
1021 Fibonacci Again
2020/3/22
32
第32页/共72页
Problem Description
There are another kind of Fibonacci numbers:
F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).
2020/3/22
17
第17页/共72页
Output
Print the total time on a single line for each test case.
2020/3/22
18
第18页/共72页
Sample Input 12 3231 0
Sample Output 17 41
12
第12页/共72页
思路分析
设置两个数组:
一个数组color[],每个元素存储一个不同颜色
一个数组count[],每个元素count[i]存储颜色color[i]的出 现次数
5 green red blue red red
color green red
blue
count
1
123
1
2020/3/22
题意容易理解 算法相对简单(有些很难的!!) 编程比较容易 ACM/ICPC入门练习的好选择
下面,分类介绍:
2020/3/22
2
第2页/共72页
从首届“舜宇”杯说起
2020/3/22
3
第3页/共72页
比赛背景
由于前一年的邀请赛很多学校没有做出一道 题,所以,这次的比赛特意准备了几道简单 的题目,目的就是让大多数的学校都能拿个 气球回去,也好有个交待,于是有…
2020/3/22
25
第25页/共72页
Output
For each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of JavaBeans that FatMouse can obtain
13
第13页/共72页
思路分析
(1)对n从1到n做 读入一个颜色str 在color数组中查找,若找不到,在表
尾添加一个颜色,个数为1;若找到,对 应颜色数加1 (2)遍历count数组,找到最大值count[i], 则对应color[i]即所求颜色
2020/3/22
14
第14页/共72页
1008: Elevator
2020/3/22
26
第26页/共72页
Sample Input 53 72 43 52 20 3 25 18 24 15 15 10 -1 -1
Sample Output 13.333 31.500
2020/3/22
27
第27页/共72页
题目特点:
这个题目比前面两个题目稍难,但是属 于能一眼看出解决办法的题目。只要静 下心,还是比较容易解决的。
2020/3/22
9
第9页/共72页
Sample Input 5 green red blue red red 3 pink orange pink 0
Sample Output red pink
2020/3/22
10
第10页/共72页
题目评述:
1. 一个让你看到后兴奋的题目…
A test case with N = 0 terminates the input and this test case is not to be processed.
2020/3/22
8
第8页/共72页
Output
For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.
特点? 关于能否被3整除,这两个数一共有多少种组
合?
2020/3/22
36
第36页/共72页
Hdoj_1021程序清单:
#include<stdio.h>
2020/3/22
4
第4页/共72页
第一类
傻瓜型
2020/3/22
5
第5页/共72页
1004: Let the Balloon Rise
2020/3/22
6
第6页/共72页
Problem Description
Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.
2020/3/22
22
第22页/共72页
1009: FatMouse' Trade
2020/3/22
23
第23页/共72页
Problem Description
FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean. The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and requires F[i] pounds of cat food. FatMouse does not have to trade for all the JavaBeans in the room, instead, he may get J[i]* a% pounds of JavaBeans if he pays F[i]* a% pounds of cat food. Here a is a real number. Now he is assigning this homework to you: tell him the maximum amount of JavaBeans he can obtain.
2020/3/22
33
第33页/共72页
Input Input consists of a sequence of lines, each
containing an integer n. (n < 1,000,000).
Output Print the word "yes" if 3 divide evenly into
2020/3/22
24
第24页/共72页
Input
The input consists of multiple test cases. Each test case begins with a line containing two non-negative integers M and N. Then N lines follow, each contains two non-negative integers J[i] and F[i] respectively. The last test case is followed by two -1's. All integers are not greater than 1000.
This year, they decide to leave this lovely job to you.
2020/3/22
7
第7页/共72页
Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) -- the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.
F(n).
Print the word "no" if not.
2020/3/22
34
第34页/共72页
Sample Input 0 1 2 3 4 5
Sample Output no no yes no no no
2020/3/22
35
第35页/共72页
题目分析:
能被3整除的整数的特点? 如果两个数的和能被3整除,这两个数有什么
For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.
2. 只要懂点C或者C++,就可解决该问题。
2020/3/22
11
第11页/共72页
1004题目分析:
该题算法思想比较简单,就是对输入的字符串 进行比较和统计。值得注意的一点是:
如果用C语言来写,要注意可能会把第一个数 字后的“回车符”误认为是第一个串,字符串 的比较也要用函数和循环语句。
2020/3/22
2020/3/22
15
第15页/共72页
Problem Description
The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.
2020/3/22
28
第28页/共72页
1009算法分析:
输入(J , F 放入数组) 对数组排序(按效益,降序) 输出(按效益高低有序交易)
2020/3/22
29
第29页/共72页
第三类
技巧型
2020/3/22
30
第30页/共72页
小锤抠缝——
先来看一个简单的题目铺垫一下:
2020/3/22
2020/3/22
19
第19页/共72页
题目评述:
实际上,这是本次比赛最简单的一题,浙大、 浙工大等当时训练水平相对较高的学校基本上 10分钟之内解决该题,这也是一个没有算法的 题目。
这种题目大家不会错过的…
2020/3/22
20第20页/共72页不要 Nhomakorabea析 了吧…
第21页/共72页
第二类
基本型
相关文档
最新文档