题目大意:中文
注释代码:
/*
* 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;
}