NPOJ 1067 Flappy48

题目大意:中文

注释代码:

/*                                                    
 * Problem ID : NPOJ 1067 Flappy48
 * Author     : Lirx.t.Una                                                    
 * Language   : C++                                 
 * Run Time   : 1                                                    
 * Run Memory : 1692                                                  
*/ 

#include <iostream>
#include <cstdio>
#include <map>

//最大的方块可能为2^40
#define	MAXN		41

using namespace std;

typedef	long long	llg;

map<llg, llg>		score;//score[x]表示方块为x的分数

int
main() {
	
	int		t;//测例数
	int		iscn;
	int		i;//计数变量
	int		n;//每个测例中有几个方块
	llg		x;//方块上的数字
	
	llg		ans;
	
	//先对方块2 ~ 2^40的分数进行打表
	//score[x] = 2score[x/2] + x
	score[2LL] = 0;
	for ( x = 4LL, i = 2; i < MAXN; i++, x <<= 1LL )
		score[x] = ( score[x >> 1LL] << 1LL ) + x;
	
	scanf("%d", &t);
	iscn = 0;
	
	while ( t-- ) {
		
		ans = 0;
		
		scanf("%d", &n);
		while ( n-- ) {
			
			scanf("%lld", &x);
			ans += score[x];
		}
		
		printf("Case %d: %lld\n", ++iscn, ans);
	}
	
	return 0;
}

无注释代码:

#include <iostream>
#include <cstdio>
#include <map>

#define	MAXN		41

using namespace std;

typedef	long long	llg;

map<llg, llg>		score;

int
main() {

	int		t;
	int		iscn;
	int		i;
	int		n;
	llg		x;

	llg		ans;

	score[2LL] = 0;
	for ( x = 4LL, i = 2; i < MAXN; i++, x <<= 1LL )
		score[x] = ( score[x >> 1LL] << 1LL ) + x;

	scanf("%d", &t);
	iscn = 0;

	while ( t-- ) {
	
		ans = 0;

		scanf("%d", &n);
		while ( n-- ) {
		
			scanf("%lld", &x);
			ans += score[x];
		}

		printf("Case %d: %lld\n", ++iscn, ans);
	}
	
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值