AtCoder Beginner Contest 083 (AB)
A - Libra
题目链接:https://abc083.contest.atcoder.jp/tasks/abc083_a
Time limit : 2sec / Memory limit : 256MB
Score : 100 points
Problem Statement
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan.
Print Left if the balance scale tips to the left; print Balanced if it balances; print Right if it tips to the right.
Constraints
- 1≤A,B,C,D≤10
- All input values are integers.
Input
Input is given from Standard Input in the following format:
A B C D
Output
Print Left if the balance scale tips to the left; print Balanced if it balances; print Right if it tips to the right.
Sample Input 1
3 8 7 1
Sample Output 1
Left
The total weight of the masses on the left pan is 11, and the total weight of the masses on the right pan is 8. Since 11>8, we should print Left.
Sample Input 2
3 4 5 2
Sample Output 2
Balanced
The total weight of the masses on the left pan is 7, and the total weight of the masses on the right pan is 7. Since 7=7, we should print Balanced.
Sample Input 3
1 7 6 4
Sample Output 3
Right
The total weight of the masses on the left pan is 8, and the total weight of the masses on the right pan is 10. Since 8<10, we should print Right.
#include <iostream>
using namespace std;
int N,A,B;
int test(int x)
{
int sum=;
while(x){
sum+=x%;
x/=;
}
if(sum<=B&&sum>=A) return ;
else return ;
}
int main()
{ while(cin>>N>>A>>B){
int s=;
for(int i=;i<=N;i++){
if(test(i)) s+=i;
}
cout<<s<<endl;
}
return ;
}
B - Some Sums
题目链接:https://abc083.contest.atcoder.jp/tasks/abc083_b
Time limit : 2sec / Memory limit : 256MB
Score : 200 points
Problem Statement
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
Constraints
- 1≤N≤104
- 1≤A≤B≤36
- All input values are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
Sample Input 1
20 2 5
Sample Output 1
84
Among the integers not greater than 20, the ones whose sums of digits are between 2 and 5, are: 2,3,4,5,11,12,13,14 and 20. We should print the sum of these, 84.
Sample Input 2
10 1 2
Sample Output 2
13
Sample Input 3
100 4 16
Sample Output 3
4554
#include <iostream>
using namespace std;
int N,A,B;
int test(int x)
{
int sum=;
while(x){
sum+=x%;
x/=;
}
if(sum<=B&&sum>=A) return ;
else return ;
}
int main()
{ while(cin>>N>>A>>B){
int s=;
for(int i=;i<=N;i++){
if(test(i)) s+=i;
}
cout<<s<<endl;
}
return ;
}
AtCoder Beginner Contest 083 (AB)的更多相关文章
- AtCoder Beginner Contest 084(AB)
A - New Year 题目链接:https://abc084.contest.atcoder.jp/tasks/abc084_a Time limit : 2sec / Memory limit ...
- AtCoder Beginner Contest 254(D-E)
Tasks - AtCoder Beginner Contest 254 D - Together Square 题意: 给定一个N,找出所有不超过N的 ( i , j ),使得( i * j )是一 ...
- AtCoder Beginner Contest 086 (ABCD)
A - Product 题目链接:https://abc086.contest.atcoder.jp/tasks/abc086_a Time limit : 2sec / Memory limit : ...
- AtCoder Beginner Contest 085(ABCD)
A - Already 2018 题目链接:https://abc085.contest.atcoder.jp/tasks/abc085_a Time limit : 2sec / Memory li ...
- AtCoder Beginner Contest 264(D-E)
D - "redocta".swap(i,i+1) 题意: 给一个字符串,每次交换相邻两个字符,问最少多少次变成"atcoder" 题解: 从左到右依次模拟 # ...
- Atcoder Beginner Contest 155E(DP)
#definde HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; int main(){ ios: ...
- Atcoder Beginner Contest 156E(隔板法,组合数学)
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ; ; long long fac[N] ...
- Atcoder Beginner Contest 121D(异或公式)
#include<bits/stdc++.h>using namespace std;int main(){ long long a,b; cin>>a>&g ...
- Atcoder Beginner Contest 155D(二分,尺取法,细节模拟)
二分,尺取法,细节模拟,尤其是要注意a[i]被计算到和a[i]成对的a[j]里时 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> ...
随机推荐
- 前端 HTML body标签相关内容 常用标签 分割线 <hr>
分割线 <hr> <hr>标签用来在HTML页面中创建水平分隔线,通常用来分隔内容 <!DOCTYPE html> <html lang="en&q ...
- Github上Laravel开源排行榜Star数61-90名
Github上Laravel开源排行榜Star数61-90名,罗列所有 Laravel 开源扩展包,含 Github Star 数量,下载数量和项目简介.默认排序是按Star数量从多到少来排 61.c ...
- SSAS下玩转PowerShell
操作SSAS数据库的方法有非常多,是否有一种能够方法能够通过脚本自己主动去做这些事呢,比方处理分区,创建备份以及监视SSAS的执行状况. 原文地址: http://www.mssqltips ...
- 20170811 使用Bootstrap框架写个页面
采用Bootstrap-table 做的页面. 1. 增加Query 查询功能,涉及Ajax 来加载页面数据吧! <meta charset="UTF-8"> < ...
- 运维自动化ansible基础
云计算三种服务架构 IAAS: 不提供OS 只购买硬件(网络,存储,计算) PAAS: 提供硬件和OS和开发和运行环境 只需要开发应用软件 SAAS: 提供 硬件 os 软件 相当于直接购买软 ...
- Node.js之npm使用
1.使用国内镜像 本人window8系统安装node.js之后,使用npm的命令安装Express一直失败: npm install express -g (以上命令会将 Express 框架安装在当 ...
- 利用SparkLauncher 类以JAVA API 编程的方式提交Spark job
一.环境说明和使用软件的版本说明: hadoop-version:hadoop-2.9.0.tar.gz spark-version:spark-2.2.0-bin-hadoop2.7.tgz jav ...
- ipfs私链服务
cd /lib/systemd/system vi ipfs.service [Unit]Description=IPFS[Service]ExecStart=/usr/bin/ipfs daemon ...
- 22-Python3 输入和输出
''' 输出格式美化 ''' s = 'Hello,Runoob' #repr():将输出读值转化成字符串,产生一个解释器易读读字符 print('repr():',repr(s)) #str():将 ...
- [LeetCode] 824. Goat Latin_Easy
A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and up ...