Shattered Cake

题目来源

F: Shattered Cake
A rectangular cake is transported via a truck to a restaurant. On the way to the destination, the truck hits a pothole, which shatters the cake in N perfectly rectangular pieces of width wi and length li, for 1 < i < N. At the destination, the damage is assessed, and the customer decides to order a replacement cake of the same dimensions. Unfortunately, the original order form was incompletely filled and only the widthW of the cake is known. The restaurant asks for your help to find out the length L of the cake. Fortunately, all pieces of the shattered cake have been kept.
Input The input consists of the following integers: • on the first line, the widthW of the cake; • on the second line, the number N of shattered pieces; • on each of the next N lines, the width wi and length li of each piece. Limits • 1 6 N 6 5000000; • 1 6W,L 6 10000; • for each 1 6 i 6 N, 1 6 wi,li 6 10000. Output The output should be the integer L.
12
Sample Input
4

7

2 3

1 4

1 2

1 2

2 2

2 2

2 1
Sample Output
6

分析:ACM最水题之一看完,对提高信心很有帮助,题如果看懂还是非常easy的,大致就是知道一个矩形宽,然后矩形变成了N个不一样的小矩形,而且每个矩形的长和宽都知道,求原来矩形的长,怎么样是不是很激动,操动起来吧!!

AC程序

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main() 
{
	int i,w,n,a,b,sum;
	sum = 0;
	scanf("%d",&w);
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d%d",&a,&b);
		sum += (a*b);
    }
    printf("%d\n",(sum)/w);
	return 0;
}



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值