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 form表单标签 input标签 type属性 radio 单选框
<input type="radio"> 单选框 适用于 选择性别按钮网页等 <!DOCTYPE html> <html lang="en& ...
- “我的小程序”来了 新版微信v6.7.1下拉就能找到
今天iOS版微信迎来v6.7.1正式版发布,本次升级主要是可以把常用的小程序添加到“我的小程序”.近期版本微信可以直接浏览订阅号的消息,扫一扫可拍照翻译整页中英文,浏览的文章支持缩小为浮窗.两大更新如 ...
- shell日志分析进阶篇
前面我们说了shell分析日志常用指令,现在我们随ytkah一起看看shell日志分析进阶篇,假设日志文件为ytkah.log //统计不重复抓取数量 cat ytkah.log | awk '{pr ...
- CentOS安装python3.5.0+uwsgi+nginx
1安装编译工具 yum install zlib-devel bzip2-devel openssl-devel python-devel kernel-devel libffi-devel ncur ...
- Caffe上用SSD训练和测试自己的数据
学习caffe第一天,用SSD上上手. 我的根目录$caffe_root为/home/gpu/ljy/caffe 一.运行SSD示例代码 1.到https://github.com ...
- wxPython:消息对话框MessageDialog
wxMessageDialog(wxWindow* parent, const wxString& message, const wxString& caption = "M ...
- HTML5(Canvas Vedio Audio 拖动)
1.Canvas (在画布上(Canvas)画一个红色矩形,渐变矩形,彩色矩形,和一些彩色的文字) HTML5 元素用于图形的绘制,通过脚本 (通常是JavaScript)来完成. 标签只是图形 ...
- c 字符数组与字符串
char a[]="abc"; printf( char str[]="abc"; int size = sizeof(str)/sizeof(char); p ...
- 虚拟主机是设置在httpd-vhosts.conf还是vhosts.conf还是httpd.conf
https://blog.csdn.net/weisubao/article/details/43536723 解决方案:虚拟主机是设置在httpd-vhosts.conf还是vhosts.conf还 ...
- MySQL高效的前提
好硬件是数据库高效的前提,没有好硬件其他优化都是白费 高性能的CPU 主频高SQL处理的更快 3级cache大CPU计算速率更快 多线程,同时并发处理SQL 关闭NUMA并设置为最大性能模式,充分利用 ...