您的位置:首页 > 其它

2015 四川省赛 B Carries (脑洞题)

2015-10-02 17:13 399 查看
题意:

N<=105序列中,两两个数的进位总和

分析:

某一位要进位一定满足 a[i]%10k+a[j]%10k>=10k

情况不多一共101∼109 9种情况

对于每一种只要排序余数 然后二分查找计算就可以了

代码:

//
//  Created by TaoSama on 2015-10-01
//  Copyright (c) 2015 TaoSama. All rights reserved.
//
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int n, a
, b
;

int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
//  freopen("out.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);

while(scanf("%d", &n) == 1) {
for(int i = 0; i < n; ++i) scanf("%d", a + i);
long long ans = 0;
for(int k = 10; k <= 1e9; k *= 10) {
for(int i = 0; i < n; ++i) b[i] = a[i] % k;
sort(b, b + n);
for(int i = 0; i < n; ++i) {
int t = k - b[i];
int p = lower_bound(b + i + 1, b + n, t) - b;
ans += n - p;
}
}
printf("%lld\n", ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: