AtCoder Beginner Contest 082 A - Round Up the Mean

题目链接:https://abc082.contest.atcoder.jp/tasks/abc082_a

Time limit : 2sec / Memory limit : 256MB

Score : 100 points

Problem Statement

You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.

Constraints

  • a and b are integers.
  • 1≤a,b≤100

Input

Input is given from Standard Input in the following format:

a b

Output

Print x rounded up to the nearest integer.


Sample Input 1

Copy
1 3

Sample Output 1

Copy
2

The average of 1 and 3 is 2.0, and it will be rounded up to the nearest integer, 2.


Sample Input 2

Copy
7 4

Sample Output 2

Copy
6

The average of 7 and 4 is 5.5, and it will be rounded up to the nearest integer, 6.


Sample Input 3

Copy
5 5

Sample Output 3

Copy
5

 

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <stack>
 5 #include <string>
 6 #include <cstring>
 7 #include <cmath>
 8 #include <cstdio>
 9 using namespace std;
10 int main()
11 {
12     int a,b;
13     while(cin>>a>>b){
14         if((a+b)%2==0) cout<<(a+b)/2<<endl;
15         else{
16             int c=(a+b)/2;
17             if(a+b-2*c<=1) cout<<c+1<<endl;
18             else cout<<c<<endl;
19         }
20     }
21     return 0;
22 }

 

posted @ 2017-12-20 21:15  wydxry  阅读(303)  评论(0编辑  收藏  举报
Live2D