boj 1328 简单问题 不过要考虑输入大小 long long可以 不过VC++不能编译
2011-03-16 12:48
627 查看
agicpig and Acm like to compete with each other recently. 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.
Input
The input consists of one or more lines. Each line contains a positive integer n.A line which contains a single 0 will end the input.
Output
A positive integer on each line denoting the required answer.
Sample Input
2
5
10
13
0
Sample Output
1
3
5
7
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
long long a[10000],b,j; //vc下不行 不过acm可以;
int i=0,k=0;
while(cin>>b)
{
j=b;
if(b==0)
break;
else
{
if(j%2==0)
a[i]=j/2;
if(j%2==1)
a[i]=j/2+1;
}
i++;
}
for(j=0;j<i;j++)
cout<<a[j]<<endl;
return 0;
}
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.
Input
The input consists of one or more lines. Each line contains a positive integer n.A line which contains a single 0 will end the input.
Output
A positive integer on each line denoting the required answer.
Sample Input
2
5
10
13
0
Sample Output
1
3
5
7
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
long long a[10000],b,j; //vc下不行 不过acm可以;
int i=0,k=0;
while(cin>>b)
{
j=b;
if(b==0)
break;
else
{
if(j%2==0)
a[i]=j/2;
if(j%2==1)
a[i]=j/2+1;
}
i++;
}
for(j=0;j<i;j++)
cout<<a[j]<<endl;
return 0;
}
相关文章推荐
- 解决typedef unsigned long long DDWORD; 在VC下编译不过问题。
- 解决typedef unsigned long long DDWORD; 在VC下编译不过问题
- 解决typedef unsigned long long DDWORD; 在VC下编译不过问题。
- 解决typedef unsigned long long DDWORD; 在VC下编译不过问题。
- boj 1336 简单的问题 不过自己没想到 别人解释的~~学习~~
- C语言用数组1. 简单约瑟夫环问题: N个人,编号从1~N围成一圈,输入一个数T,从1号开始报数,报到T的人出圈;下一人又从1开始报数,下一个报到T的人出圈,输出出圈顺序。 考虑问实现约瑟夫环问题
- boj 1336 简单的问题 不过自己没想到 别人解释的~~学习~~
- boj problem 1331 思路:快排分块 按块查找 问题:全局数组时可以定义到500W的 main函数下的数组不行~ 另外c语言比c++快 TLE可以考虑C~~具体原因待解决
- boj 1336 简单的问题 不过自己没想到 别人解释的~~学习~~
- boj problem 1340 简单题 费时很久 long long型 输入输出时 "%lld“ 是LL而不是11. 先快排 然后计算就可以
- 简单的Android音乐播放,解决incall类型不能通过音量按键控制声音大小的问题
- VC(MFC)中debug下的exe不能直接运行,编译可以
- 我把一个VC6的工程转换为VS2008的工程后,编译总是出现找不到而且不能升级vc90.pdb文件的问题,error C2471--解决办法 2010-9-16 15:01
- 你就是一个画家!你现在想绘制一幅画,但是你现在没有足够颜色的颜料。为了让问题简单,我们用正整数表示不同颜色的颜料。你知道这幅画需要的n种颜色的颜料,你现在可以去商店购买一些颜料,但是商店不能保证能供应所有颜色的颜料,所以你需要自己混合一些颜料。混合两种不一样的颜色A和颜色B颜料可以产生(A XOR B)这种颜色的颜料(新产生的颜料也可以用作继续混合产生新的颜色,XOR表示异或操作)。本着勤俭节约的
- fcitx 关于多语言,不同编码的一点说明;同时也可以用于解决fcitx不能输入问题
- 求斐波那契数列第100位(通过C++数组模拟大数,注意VC6语法支持的不好,编译不过,在VS下面可以)
- VC对话框运行后不能改变大小的问题
- 一个VC6的工程转换为VS2008的工程后,编译找不到而且不能升级vc90.pdb文件的问题解决方法 2010-9-28 14:00
- 我把一个VC6的工程转换为VS2008的工程后,编译总是出现找不到而且不能升级vc90.pdb文件的问题,error C2471--解决办法
- boj 1336 简单的问题 不过自己没想到 别人解释的~~学习~~这个是 第二类Stirling数 需要再好好看看