整理的-----ACM题目及答案(3)

2018-12-04 22:05

sum+=5; }

printf(\,sum); }

return 0;

}

1009 FatMouse' Trade

Problem Description

FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.

The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and requires F[i] pounds of cat food. FatMouse does not have to trade for all the JavaBeans in the room, instead, he may get J[i]* a% pounds of JavaBeans if he pays F[i]* a% pounds of cat food. Here a is a real number. Now he is assigning this homework to you: tell him the maximum amount of JavaBeans he can obtain.

Input

The input consists of multiple test cases. Each test case begins with a line containing two non-negative integers M and N. Then N lines follow, each contains two non-negative integers J[i] and F[i] respectively. The last test case is followed by two -1's. All integers are not greater than 1000.

Output

For each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of JavaBeans that FatMouse can obtain.

Sample Input

5 3 7 2 4 3 5 2 20 3 25 18 24 15 15 10 -1 -1

Sample Output

13.333 31.500

Author

CHEN, Yue

Source

ZJCPC2004

Recommend

JGShining

11

代码:

#include #include #define MAX 1000 int main() {

int i,j,m,n,temp;

int J[MAX],F[MAX]; double P[MAX]; double sum,temp1;

scanf(\ while(m!=-1&&n!=-1) {

sum=0;

memset(J,0,MAX*sizeof(int));

memset(F,0,MAX*sizeof(int)); memset(P,0,MAX*sizeof(double));

for(i=0;i

for(j=i+1;j

if(P[i]

temp1=P[i]; P[i]=P[j]; P[j]=temp1; temp=J[i]; J[i]=J[j]; J[j]=temp; temp=F[i]; F[i]=F[j]; F[j]=temp; } }

}

for(i=0;i

{

if(m

printf(\ scanf(\ }

return 0; }

12

1021 Fibonacci Again

Problem Description

There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).

Input

Input consists of a sequence of lines, each containing an integer n. (n < 1,000,000).

Output

Print the word \Print the word \

Sample Input

0 1 2 3 4 5

Sample Output

no no yes no no no

Author

Leojay

Recommend

JGShining

#include int main() {

long n;

while(scanf(\,&n) != EOF) if (n%8==2 || n%8==6) printf(\); else

printf(\);

13

return 0; }

1089 A+B for Input-Output Practice

(I)

Problem Description

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 Input

1 5 10 20

Sample Output

6 30

Author

lcy

Recommend

JGShining

解答:

#include main() {

14

int a,b;

while(scanf(\,&a,&b)!=EOF) printf(\,a+b); }

1090 A+B for Input-Output Practice

(II)

Problem Description

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 Input

2 1 5 10 20

Sample Output

6 30

Author

lcy

Recommend

JGShining

解答:

#include #define M 1000 void main()

15


整理的-----ACM题目及答案(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2016级南京农业大学研究生培养方案(全)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: