WHU-ACM BG
时间限制: 1000 ms
内存限制: 524288 KiB
输入 / 输出: stdio
难度: 1 / 5
题目描述
Magicpig and Acm like to compete with each other recently, and the loser has to “BG” the winner, that means, if Magicpig wins, Acm will treat him to a meal. But Acm is so powerful that Magicpig has to “BG” him almost every time. Everybody is very interested in this. So more and more ACMers are attracted to participate in this game. One day, Peipei said: “It is unfair that one person should ‘BG’ all the others. I suggest that 50% of the participants should pay the bill. That means, if there are n participants, then Ceil(n/2) person should ‘BG’ the other n-Ceil(n/2) person.” This is a good idea! So all of us agree to do so. This is the story of “BG”. Now you task is: given a number n – the total number of participants, you have to calculate how many people should pay the bill.
输入格式
The input consists of one or more lines.
Each line contains a positive integer n (2 <= n <= 100).
A line which contains a single 0 will end the input, and should not be processed.
输出格式
A positive integer on each line denoting the required answer.
样例输入
2
5
10
13
0
样例输出
1
3
5
7
提示
注意:
0. ceil是math.h中的函数,用于对浮点数向上取整,返回值也是浮点类型(不是整型),其原型为:
double ceil (double x);
1. 题目要求能够处理多组数据,应当使用一个循环来完成多组数据的处理;
2. 题目要求每组输入数据输出一行,因此每次输出后面都要跟一个回车;
3. 系统能够区分输入和输出,处理一组输出一组即可,不需要收集所有数据一次性输出
代码框架示例如下:
int n;
while (1)
{ scanf("%d", &n);
if (n == 0) //输入结束标志,n=0时不需要被处理
break;
int ans = ........; //这里计算得到结果
printf("%d\n", ans); //需要加上 \n ,每组处理完直接输出即可。
}
代码
#include <stdio.h>
int ceil(int x){
return x%2 == 0 ? x/2:(x+1)/2;
}
int main(){
int n;
while (1)
{ scanf("%d", &n);
if (n == 0) //输入结束标志,n=0时不需要被处理
break;
int ans = ceil(n); //这里计算得到结果
printf("%d\n", ans); //需要加上 \n ,每组处理完直接输出即可。
}
return 0;
}
备注
蜜汁原因,我使用<math.h>中的ceil函数调用,但是编译运行没效果,不知道为什么,先留个坑,日后想到解决办法再回来。所以因为不能用ceil函数,我就自己写了个这个题的ceil函数,仅供此处使用