题意:问任意两对ai,aj相加的总进位数为多少。比如5,6,95分为(5,6)(5,95)(6,95),进位数 = 1 + 2 + 2 = 5

思路:显然暴力是会超时的。我们可以知道总进位数等于每一位进位数之和,所以我们可以把10个位数的进位分开算,每次%10^k,排序后用二分找到刚好的位置,然后算总数。

好像是唯一一次写二分一次A的题。

代码:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + ;
const ll seed = ;
ll a[maxn], b[maxn], k;
ll fac[];
int mid(int l, int r, ll num){
int m, ans = r + ;
while(l <= r){
m = (l + r) >> ;
if(num + b[m] >= fac[k]) ans = m;
if(num + b[m] < fac[k]) l = m + ;
else r = m - ;
}
return ans;
}
int main(){
int n;
fac[] = ;
for(int i = ; i <= ; i++)
fac[i] = fac[i - ] * ;
while(~scanf("%d", &n)){
k = ;
ll ans = ;
for(int i = ; i <= n; i++)
scanf("%lld", &a[i]);
for(int i = ; i <= ; i++){
k = i;
for(int i = ; i <= n; i++)
b[i] = a[i] % fac[k];
sort(b + , b + n + );
for(int i = ; i <= n; i++){
int pos = mid(i + , n, b[i]);
ans += (n - pos + );
}
}
printf("%lld\n", ans);
}
return ;
}

SCU 4437 Carries(二分乱搞)题解的更多相关文章

  1. ACM:SCU 4437 Carries - 水题

    SCU 4437  Carries Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu  Practice  ...

  2. [NOIP模拟赛][并没有用二分][乱搞AC]

    圆圈舞蹈 [问题描述] 熊大妈的奶牛在时针的带领下,围成了一个圆圈跳舞.由于没有严格的教育,奶牛们之间的间隔不一致. 奶牛想知道两只最远的奶牛到底隔了多远.奶牛A到B的距离为A顺时针走和逆时针走,到达 ...

  3. Codeforces 1077E (二分乱搞或者dp)

    题意:给你一个数组,可以从中选区若干种元素,但每种元素选区的个数前一种必须是后一种的2倍,选区的任意2种元素不能相同,问可以选取最多的元素个数是多少? 思路1(乱搞):记录一下每种元素的个数,然后暴力 ...

  4. bzoj1992鬼谷子的钱袋(二分乱搞 二进制)

    1192: [HNOI2006]鬼谷子的钱袋 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3223  Solved: 2333 Descriptio ...

  5. [luoguP2862] [USACO06JAN]把牛Corral the Cows(二分 + 乱搞)

    传送门 可以二分边长 然后另开两个数组,把x从小到大排序,把y从小到大排序 枚举x,可以得到正方形的长 枚举y,看看从这个y开始,往上能够到达多少个点,可以用类似队列来搞 其实发现算法的本质之后,x可 ...

  6. 【bzoj5085】最大(二分+乱搞)

    题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=5085 这道题我们可以先二分答案,然后转化为判定是否有四角权值>=mid的矩形. ...

  7. 【BZOJ-4692】Beautiful Spacing 二分答案 + 乱搞(DP?)

    4692: Beautiful Spacing Time Limit: 15 Sec  Memory Limit: 128 MBSubmit: 46  Solved: 21[Submit][Statu ...

  8. “盛大游戏杯”第15届上海大学程序设计联赛夏季赛暨上海高校金马五校赛题解&&源码【A,水,B,水,C,水,D,快速幂,E,优先队列,F,暴力,G,贪心+排序,H,STL乱搞,I,尼姆博弈,J,差分dp,K,二分+排序,L,矩阵快速幂,M,线段树区间更新+Lazy思想,N,超级快速幂+扩展欧里几德,O,BFS】

    黑白图像直方图 发布时间: 2017年7月9日 18:30   最后更新: 2017年7月10日 21:08   时间限制: 1000ms   内存限制: 128M 描述 在一个矩形的灰度图像上,每个 ...

  9. Atcoder Grand Contest 032 E - Modulo Pairing(乱搞+二分)

    Atcoder 题面传送门 & 洛谷题面传送门 神仙调整+乱搞题. 首先某些人(including me)一看到最大值最小就二分答案,事实上二分答案对这题正解没有任何启发. 首先将 \(a_i ...

随机推荐

  1. <4>Lua表

    lua表 1: lua没有数组,但是表可以代替数组的功能(数组部分与非数组部分); 开始的, 1, 2, 3 ...称连续的索引; b.Lua表的连续索引的长度(数组部分);  #表的名字; --数组 ...

  2. cmd下 mysql操作命令大全详解

    启动:net start mySql; 进入:mysql -u root -p/mysql -h localhost -u root -p databaseName; 列出数据库:show datab ...

  3. 【转】robotFramework 与testlink集成

    场景: robotframework 执行完用例之后,将执行结果报至testlink. 方案1: 通过TestLink-API-Python-client中的RF关键字 每条用例执行完成之后根据状态进 ...

  4. Spark学习之路 (十四)SparkCore的调优之资源调优JVM的GC垃圾收集器

    一.概述 垃圾收集 Garbage Collection 通常被称为“GC”,它诞生于1960年 MIT 的 Lisp 语言,经过半个多世纪,目前已经十分成熟了. jvm 中,程序计数器.虚拟机栈.本 ...

  5. GridFS Example

    http://api.mongodb.com/python/current/examples/gridfs.html This example shows how to use gridfs to s ...

  6. Presto 学习参考资料

    Presto 文档资料: 0.1版:Presto 0.100 Documentation 0.213版:Presto 0.213 Documentation 阿里云 presto 学习资料:https ...

  7. Codeforces 268B - Buttons

    Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you ...

  8. UVALive 3295 Counting Triangles

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  9. CentOS7安装MySQL冲突和问题解决小结

    摘自:https://blog.csdn.net/typa01_kk/article/details/49059729 问题1: [root@localhost install-files]# rpm ...

  10. OSI七层协议与TCP/IP模型

    OSI为Open System Interconnection的缩写,意为开放式系统互联,国际标准化组织(ISO,International Organization for Standardizat ...