AtCoder Beginner Contest 087 (ABC)
A - Buying Sweets
题目链接:https://abc087.contest.atcoder.jp/tasks/abc087_a
Time limit : 2sec / Memory limit : 256MB
Score : 100 points
Problem Statement
You went shopping to buy cakes and donuts with X yen (the currency of Japan).
First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop.
How much do you have left after shopping?
Constraints
- 1≤A,B≤1 000
- A+B≤X≤10 000
- X, A and B are integers.
Input
Input is given from Standard Input in the following format:
X
A
B
Output
Print the amount you have left after shopping.
Sample Input 1
1234
150
100
Sample Output 1
84
You have 1234−150=1084 yen left after buying a cake. With this amount, you can buy 10 donuts, after which you have 84 yen left.
Sample Input 2
1000
108
108
Sample Output 2
28
Sample Input 3
579
123
456
Sample Output 3
0
Sample Input 4
7477
549
593
Sample Output 4
405
#include<bits/stdc++.h>
using namespace std; int main()
{
int x,a,b;
while(cin>>x>>a>>b){
x-=a;
x%=b;
cout<<x<<endl;
}
return ;
}
B - Coins
题目链接:https://abc087.contest.atcoder.jp/tasks/abc087_b
Time limit : 2sec / Memory limit : 256MB
Score : 200 points
Problem Statement
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total?
Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
Constraints
- 0≤A,B,C≤50
- A+B+C≥1
- 50≤X≤20 000
- A, B and C are integers.
- X is a multiple of 50.
Input
Input is given from Standard Input in the following format:
A
B
C
X
Output
Print the number of ways to select coins.
Sample Input 1
2
2
2
100
Sample Output 1
2
There are two ways to satisfy the condition:
- Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.
- Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.
Sample Input 2
5
1
0
150
Sample Output 2
0
Note that the total must be exactly X yen.
Sample Input 3
30
40
50
6000
Sample Output 3
213
题解:找零钱
#include<bits/stdc++.h>
using namespace std; int main()
{
int x,a,b,c;
while(cin>>a>>b>>c>>x){
x/=;
int sum=;
for(int i=;i<=a;i++){
for(int j=;j<=b;j++){
for(int k=;k<=c;k++){
if(i*+j*+k==x) sum++;
}
}
}
cout<<sum<<endl;
}
return ;
}
C - Candies
题目链接:https://abc087.contest.atcoder.jp/tasks/arc090_a
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
We have a 2×N grid. We will denote the square at the i-th row and j-th column (1≤i≤2, 1≤j≤N) as (i,j).
You are initially in the top-left square, (1,1). You will travel to the bottom-right square, (2,N), by repeatedly moving right or down.
The square (i,j) contains Ai,j candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them.
At most how many candies can you collect when you choose the best way to travel?
Constraints
- 1≤N≤100
- 1≤Ai,j≤100 (1≤i≤2, 1≤j≤N)
Input
Input is given from Standard Input in the following format:
N
A1,1 A1,2 … A1,N
A2,1 A2,2 … A2,N
Output
Print the maximum number of candies that can be collected.
Sample Input 1
5
3 2 2 4 1
1 2 2 2 1
Sample Output 1
14
The number of collected candies will be maximized when you:
- move right three times, then move down once, then move right once.
Sample Input 2
4
1 1 1 1
1 1 1 1
Sample Output 2
5
You will always collect the same number of candies, regardless of how you travel.
Sample Input 3
7
3 3 4 5 4 5 3
5 3 4 4 2 3 2
Sample Output 3
29
Sample Input 4
1
2
3
Sample Output 4
5 题解:分成两个数组 同时使用前缀和 取最大值
#include<bits/stdc++.h>
using namespace std;
int a[],b[];
int suma[],sumb[];
int main()
{
int n;
while(cin>>n){
for(int i=;i<n;i++){
cin>>a[i];
}
for(int i=;i<n;i++){
cin>>b[i];
}
suma[]=a[];sumb[]=b[];
for(int i=;i<n;i++){
suma[i]=suma[i-]+a[i];
sumb[i]=sumb[i-]+b[i];
}
int maxn=suma[]+sumb[n-];
for(int i=;i<n;i++){
int sum=suma[i]+sumb[n-]-sumb[i-];
maxn=max(maxn,sum);
}
cout<<maxn<<endl;
}
return ;
}
AtCoder Beginner Contest 087 (ABC)的更多相关文章
- AtCoder Beginner Contest 088 (ABC)
A - Infinite Coins 题目链接:https://abc088.contest.atcoder.jp/tasks/abc088_a Time limit : 2sec / Memory ...
- AtCoder Beginner Contest 050 ABC题
A - Addition and Subtraction Easy Time limit : 2sec / Memory limit : 256MB Score : 100 points Proble ...
- AtCoder Beginner Contest 087 D - People on a Line
Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement There are N people sta ...
- AtCoder Beginner Contest 087 B - Coins
Time limit : 2sec / Memory limit : 256MB Score : 200 points Problem Statement You have A 500-yen coi ...
- AtCoder Beginner Contest 087 D People on a Line(DFS)
题意 给出n个点,m组关系L,R,D,L在R的左边距离D,判断是否存在n个人的位置满足m组关系 分析 Consider the following directed graph G: There ar ...
- AtCoder Beginner Contest 100 2018/06/16
A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 076
A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...
- AtCoder Beginner Contest 068 ABCD题
A - ABCxxx Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement This contes ...
随机推荐
- mysql show prifile基本详解
show profile默认情况下,参数处于关闭状态,并保存最近15次的运行结果查看profile是否开启 show variables like '%profi%';开启profile记录功能 se ...
- TCP路由网络通信
路由器 实现跨网段通信 路由器的工作原理是基于路由器中的路由表来实现数据包的路径选择 当路由器收到一个数据包的时候,会读取数据包的目标IP地址,根据目标IP地址来匹配路由表中的规则 单个路由器不会 ...
- 开发十年,只剩下这套Java开发体系了
蓦然回首自己做开发已经十年了,这十年中我获得了很多,技术能力.培训.出国.大公司的经历,还有很多很好的朋友.但再仔细一想,这十年中我至少浪费了五年时间,这五年可以足够让自己成长为一个优秀的程序员,可惜 ...
- 【RPC】综述
RPC定义 RPC(Remote Procedure Call)全称远程过程调用,它指的是通过网络,我们可以实现客户端调用远程服务端的函数并得到返回结果.这个过程就像在本地电脑上运行该函数一样,只不过 ...
- JDBC 接口学习
说明:文章所有内容皆选自实验楼教程[JDBC 入门教程],想要学习更多JDBC,可以点击教程进行学习~ JDBC 简介 JDBC 的全称是 Java Database Connectivity,叫做 ...
- [Java in NetBeans] Lesson 17. File Input/Output.
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: We want to handle the bad Error. (e.g bad input / bugs in program) ...
- js计算最大公约数和最小公倍数
一.计算最大公约数 1.小学时候一般采用质因数分解法,一般使用短除得到结果,下面用一种最初级的方法求最大公约数 function gcd2(a,b){ var result = 1; for(var ...
- iOS 第三方框架-SDWebImage
iOS中著名的牛逼的网络图片处理框架.包含的功能:图片下载.图片缓存.下载进度监听.gif处理等等.用法极其简单,功能十分强大,大大提高了网络图片的处理效率.国内超过90%的iOS项目都有它的影子. ...
- shell编程:if语句
条件判断式的两边的空格不能生
- python入门之列表
1.列表基本格式# list 类 列表li = [1, 2, 3, "sb", ["时间",[9, 10], "huang"], 6, 7, ...