2015 四川省赛 B Carries (脑洞题)
2015-10-02 17:13
399 查看
题意:
N<=105序列中,两两个数的进位总和
分析:
某一位要进位一定满足 a[i]%10k+a[j]%10k>=10k
情况不多一共101∼109 9种情况
对于每一种只要排序余数 然后二分查找计算就可以了
代码:
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; }
相关文章推荐
- Java HTTP协议问题集锦
- O(V*n)的多重背包问题
- Effective c++读书笔记三
- [面试时]我是如何讲清楚GCD的
- 使用dbms_file_transfer传输ASM file出现ORA-15001
- silverlight画图 虚线 反射效果 射线渐变效果Radial Gradient
- STC12C5A60S2外部中断P3^2,P3^3 的应用 【中断函数略讲interrupt using】
- Unity3d 3d角色换装实现原理及步骤
- 组织的信息能力与竞争优势
- java15:面向对象
- 【因子算法】——求一个数的因子、质因子、求两个数的公因子
- java中的io机制
- GCC内嵌汇编
- scu 4444 travel
- Java堆和栈的区别 经典总结(转载)
- Xcode 和 Mac 的一些快捷键
- swift的类和对象
- android studio 用WiFi 真机 调试 测试
- UVA - 1584 Circular Sequence
- LinkedHashMap与LRUCache实现