A - A+B for Input-Output Practice (I)
Your task is to Calculate a + b.
Too easy?! Of course! I specially designed the problem for acm beginners.
You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim.
Input
The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.
Output
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.
Sample
Inputcopy | Outputcopy |
---|---|
1 5 10 20 | 6 30 |
分析:对输入的两个数求和输出
#include <stdio.h>
int main()
{
int a,b;
while(~scanf("%d%d",&a,&b)){
printf("%d",a+b);
}
return 0;
}
B - A+B for Input-Output Practice (II)
Your task is to Calculate a + b.
Input
Input contains an integer N in the first line, and then N lines follow. Each line consists of a pair of integers a and b, separated by a space, one pair of integers per line.
Output
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.
Sample
Inputcopy | Outputcopy |
---|---|
2 1 5 10 20 | 6 30 |
分析:读入n组数据,输出求和结果
#include <stdio.h>
int main()
{
int a,b,i,n;
scanf("%d",&n);
for(i=0 ; i<n ; i++){
scanf("%d%d",&a,&b);
printf("%d",a+b);
}
return 0;
}
C - A+B for Input-Output Practice (III)
Your task is to Calculate a + b.
Input
Input contains multiple test cases. Each test case contains a pair of integers a and b, one pair of integers per line. A test case containing 0 0 terminates the input and this test case is not to be processed.
Output
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.
Sample
Inputcopy | Outputcopy |
---|---|
1 5 10 20 0 0 | 6 30 |
分析:持续读入数据,输出和,读到0 0 为止
#include <stdio.h>
int main()
{
int a,b;
while(~scanf("%d%d",&a,&b)){
if(a==0&&b==0){
break;
}
else
printf("%d",a+b);
}
return 0;
}
Jiajia downloads a lot, a lot more than you can even imagine. Some say that he starts downloading up to 20,000 files together. If 20,000 files try to share a limited bandwidth then it will be a big hazard and no files will be downloaded properly. That is why, he uses a download manager.
If there are T files to download, the download manger uses the following policy while downloading files:
1. The download manager gives the smaller files higher priority, so it starts downloading the smallest n files at startup. If there is a tie, download manager chooses the one with less bytes remaining (for download). We assume that with at least 50 Mega Bytes/sec of bandwidth, n files can be downloaded simultaneously without any problem.
2. The available bandwidth is equally shared by the all the files that are being downloaded. When a file is completely downloaded its bandwidth is instantaneously given to the next file. If there are no more files left except the files that are being downloaded, this bandwidth is immediately shared equally by all remaining files that are being downloaded.
Given the size and completed percentage of each file, your task is to intelligently simulate the behavior of the download manager to find the total time required to download all the files.
Input
The will be at most 10 test cases. Each case begins with three integers T (1 <= T <= 20000), n (1 <= n <= 2000 and 1 <= n <= T) and B (50 <= B <= 1000). Here B denotes the total bandwidth available to Jiajia (In Megabytes/sec). Please note that the download manager always downloads n files in parallel unless there are less than n files available for download. Each of next T lines contains one non-negative floating-point number S (less than 20,000, containing at most 2 digits after the decimal places) and one integer P (0 <= P <= 100). These two numbers denote a file whose size is S megabyte and which has been downloaded exactly P% already. Also note that although theoretically it is not possible that the size of a file or size of its remaining part is a fraction when expressed in bytes, for simplicity please assume that such thing is possible in this problem. The last test case is followed by T=n=B=0, which should not be processed.
Output
For each case, print the case number and the total time required to download all the files, expressed in hours and rounded to 2 digits after the decimal point. Print a blank line after the output of each test case.
Sample
Inputcopy | Outputcopy |
---|---|
6 3 90 100.00 90 40.40 70 60.30 70 40.40 80 40.40 85 40.40 88 1 1 56 12.34 100 0 0 0 | Case 1: 0.66 Case 2: 0.00 |
Hint
Explanation
In the first sample, there are 6 files and the download manager can download 3 files simultaneously. The size of the smallest file is 40.40 Megabyte but there are
four such files (2nd, 4th, 5th and 6th files). So the download manager chooses the 6th, 5th and 4th files for download as they have less bytes remaining. All these
files get equal bandwidth (30.00 Megabyte/Sec). Of these three files the 8th file is finished first. So instantaneously the 2nd file starts downloading. Then, 5th file
is finished. So the next larger file (3rd file) starts downloading. This process goes on until all files are downloaded.
分析:持续读入T(总数),N,B,给出T个文件大小和完成度,求完成剩余所有未完成的文件时间,按照数据组好+结果的格式输出
#include <stdio.h>
int main()
{
int a,b;
while(~scanf("%d%d",&a,&b)){
if(a==0&&b==0){
break;
}
else
printf("%d",a+b);
}
return 0;
}
给你n个整数,请按从大到小的顺序输出其中前m大的数。
Input
每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不相同,且都处于区间[-500000,500000]的整数。
Output
对每组测试数据按从大到小的顺序输出前m大的数。
Sample
Inputcopy | Outputcopy |
---|---|
5 3 3 -35 92 213 -644 | 213 92 3 |
Hint
请用VC/VC++提交
分析:通过下标映射的方法
#include <stdio.h>
int main()
{
int T,n,c=0,i;
double a,b,B;
while(~scanf("%d%d%lf",&T,&n,&B)){
double sum=0;
if(T==0&&n==0&&B==0){
break;
}
for(i=0 ; i<T ; i++){
scanf("%lf %lf",&a,&b);
sum=a*(100-b)/100+sum;
}
c++;
printf("Case %d: %.2lf\n",c,sum/B);
}
return 0;
}
HDOJ上面已经有10来道A+B的题目了,相信这些题目曾经是大家的最爱,希望今天的这个A+B能给大家带来好运,也希望这个题目能唤起大家对ACM曾经的热爱。
这个题目的A和B不是简单的整数,而是两个时间,A和B 都是由3个整数组成,分别表示时分秒,比如,假设A为34 45 56,就表示A所表示的时间是34小时 45分钟 56秒。
Input
输入数据有多行组成,首先是一个整数N,表示测试实例的个数,然后是N行数据,每行有6个整数AH,AM,AS,BH,BM,BS,分别表示时间A和B所对应的时分秒。题目保证所有的数据合法。
Output
对于每个测试实例,输出A+B,每个输出结果也是由时分秒3部分组成,同时也要满足时间的规则(即:分和秒的取值范围在0~59),每个输出占一行,并且所有的部分都可以用32位整数表示。
Sample
Inputcopy | Outputcopy |
---|---|
2 1 2 3 4 5 6 34 45 56 12 23 34 | 5 7 9 47 9 30 |
分析:时间单位的相加,注意进位关系
#include <stdio.h>
int main()
{
int n,a[100],i,j;
scanf("%d",&n);
for(i=0 ; i<n ; i++){
for(j=0 ; j<6 ; j++){
scanf("%d",&a[j]);
}
printf("%d %d %d",a[0]+a[3]+(a[1]+a[4]+(a[2]+a[5])/60)/60,(a[1]+a[4]+(a[2]+a[5])/60)%60,(a[2]+a[5])%60);
}
return 0;
}
参加过上个月月赛的同学一定还记得其中的一个最简单的题目,就是{A}+{B},那个题目求的是两个集合的并集,今天我们这个A-B求的是两个集合的差,就是做集合的减法运算。(当然,大家都知道集合的定义,就是同一个集合中不会有两个相同的元素,这里还是提醒大家一下)
呵呵,很简单吧?
Input
每组输入数据占1行,每行数据的开始是2个整数n(0<=n<=100)和m(0<=m<=100),分别表示集合A和集合B的元素个数,然后紧跟着n+m个元素,前面n个元素属于集合A,其余的属于集合B. 每个元素为不超出int范围的整数,元素之间有一个空格隔开.
如果n=0并且m=0表示输入的结束,不做处理。
Output
针对每组数据输出一行数据,表示A-B的结果,如果结果为空集合,则输出“NULL”,否则从小到大输出结果,为了简化问题,每个元素后面跟一个空格.
Sample
Inputcopy | Outputcopy |
---|---|
3 3 1 2 3 1 4 7 3 7 2 5 8 2 3 4 5 6 7 8 0 0 | 2 3 NULL |
分析:手写快排
#include <stdio.h>
int main()
{
int n,m,a[105],b[105],i,j,t;
while(~scanf("%d%d",&n,&m)){
if(n==0&&m==0){
break;
}
for(i=0 ; i<n ; i++){
scanf("%d",&a[i]);
}
for(j=0 ; j<m ; j++){
scanf("%d",&b[j]);
}
for(j=0 ; j<m ; j++){
for(i=0 ; i<n ; i++){
if(a[i]==b[j]){
n--;
for(i=i ; i<n ; i++){
a[i]=a[i+1];
}
break;
}
}
}
if(n==0){
printf("NULL");
}
else{
for(i=0 ; i<n-1 ; i++){
for(j=0 ; j<n-1-i ; j++){
if(a[j]>a[j+1]){
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
for(i=0 ; i<n ; i++){
printf("%d ",a[i]);
}
}
}
return 0;
}
求A^B的最后三位数表示的整数。
说明:A^B的含义是“A的B次方”
Input
输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<=A,B<=10000),如果A=0, B=0,则表示输入数据的结束,不做处理。
Output
对于每个测试实例,请输出A^B的最后三位表示的整数,每个输出占一行。
Sample
Inputcopy | Outputcopy |
---|---|
2 3 12 6 6789 10000 0 0 | 8 984 1 |
分析:a的b次方就是b个a相乘
#include <stdio.h>
int main()
{
int n,m,i;
while(~scanf("%d%d",&n,&m)){
int x=1;
if(n==0&&m==0){
break;
}
for(i=0 ; i<m ; i++){
x=x*n%1000;
}
printf("%d\n",x);
}
return 0;
}