https://blog.csdn.net/catglory/article/details/46539283

https://blog.csdn.net/u012127882/article/details/46517099

学到了很开心

当我们求,有多少个数相加起来会大于某一个常数的时候,只需将原数组排序,然后枚举每一个数就行了,枚举的时候,一个左指针向右移,就是我们正在枚举的数字,而另外一个右指针向左移,而不需要回溯,因为左指针指向的数字变大了,所以右指针右边的不用判断就知道一定会大于这个常数了。这样的话就可以将n方的复杂度变成2*n,所谓的二分解法,与这个也是类似的。二分求解的是,每一个左指针指向的值,与之相加不能超过这个常数的值的位置,实际上就是每次左指针右移时,右指针停住的位置。

 #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-); int num[maxn];
int a[maxn];
int main()
{
// ios::sync_with_stdio(false);
// freopen("in.txt","r",stdin); int n;
while(scanf("%d",&n)!=EOF){
for(int i=;i<=n;i++){
scanf("%d",&num[i]);
}
int t= ;
ll ans = ;
for(int k=;k<=;k++){
t*=;
for(int i=;i<=n;i++){
a[i]=num[i]%t;
}
sort(a+,a++n); int r = n;
for(int i=;i<=n;i++){
while(r&&a[i]+a[r]>=t){
r--;
}
// fuck(r)
if(i>r){ans+=(n-r-);}
else{ans+=n-r;}
// fuck(ans)
} }printf("%lld\n",ans/); } return ;
}

代码几乎是抄的上面两位博主的,毕竟看了别人的代码,思路就固化了。开始不知道输出是答案的两倍,除了一个2就过了。

后来想了一下,应该是重复枚举了,毕竟l最后会超过r,所以要除以2

SCU-4437 Carries的更多相关文章

  1. ACM:SCU 4437 Carries - 水题

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

  2. SCU 4437 Carries(二分乱搞)题解

    题意:问任意两对ai,aj相加的总进位数为多少.比如5,6,95分为(5,6)(5,95)(6,95),进位数 = 1 + 2 + 2 = 5 思路:显然暴力是会超时的.我们可以知道总进位数等于每一位 ...

  3. Carries SCU - 4437

    Carries frog has nn integers a1,a2,-,ana1,a2,-,an, and she wants to add them pairwise. Unfortunately ...

  4. ACM: SCU 4438 Censor - KMP

     SCU 4438 Censor Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu  Practice D ...

  5. ACM: SCU 4440 Rectangle - 暴力

     SCU 4440 Rectangle Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu  Practic ...

  6. 2015弱校联盟(1) - B. Carries

    B. Carries Time Limit: 1000ms Memory Limit: 65536KB frog has n integers a1,a2,-,an, and she wants to ...

  7. SCU 4424(求子集排列数)

    A - A Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice ...

  8. SCU 2941 I NEED A OFFER!(01背包变形)

    I NEED A OFFER!     64bit IO Format: %lld & %llu Submit Status Description Description Speakless ...

  9. SCU 4440 分类: ACM 2015-06-20 23:58 16人阅读 评论(0) 收藏

    SCU - 4440 Rectangle Time Limit: Unknown   Memory Limit: Unknown   64bit IO Format: %lld & %llu ...

  10. scu 4436: Easy Math 水题

    4436: Easy Math Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.scu.edu.cn/soj/problem.actio ...

随机推荐

  1. 三、ASP.NET Core 部署Linux

    预备工作 1.删除dotnet core sdk sudo yum erase libunwind libicu 2.删除链接 sudo rm -rf /usr/local/bin 3.sudo yu ...

  2. 使用javaWeb的二大(Listener、Filter)组件实现分IP统计访问次数

    分析: 统计工作需要在所有资源之前都执行,那么就可以放到Filter中. 我们这个过滤器不打算做拦截操作!因为我们只是用来做统计 用什么东西来装载统计的数据.Map<String,Integer ...

  3. react 入坑笔记(二) - State

    React State 一. state 大致思想:在 react 中,每个组件都是一个状态机,通过与用户的交互,实现不同状态,然后渲染 UI,让用户界面和数据保持一致.React 里,只需更新组件的 ...

  4. codeforces263B

    Squares CodeForces - 263B Vasya has found a piece of paper with a coordinate system written on it. T ...

  5. DRF 版本和认证

    Django Rest Framework 版本控制组件 DRF的版本 版本控制是做什么用的, 我们为什么要用 首先我们要知道我们的版本是干嘛用的呢~~大家都知道我们开发项目是有多个版本的~~ 当我们 ...

  6. 洛谷p1586四方定理题解

    题目 这个题的本质是动态规划中的背包问题. 为什么会想到背包呢. 因为往往方案数不是排列组合就是递推或者是dp,当然还有其他的可能.我们可以把一个数的代价当成这个数的平方,价值就是一个方案数.由于这个 ...

  7. 白兔的刁难 IDFT

    题目描述 给你\(n,k\),求 \[ \forall 0\leq t< k,s_t=\sum_{i=-t}^{n-t}[k|i]\binom{n}{i+t} \] 对\(998244353\) ...

  8. Ionic的NavController 和ModalController 的区别

    网上也没有找到直接介绍两者区别的文章,以下都是个人感觉 区别 NavController 和 ModalController 都是打开新页面,但是NavController 是直接将页面放入到原有的页 ...

  9. tp5 日志管理

    日志驱动 日志可以通过驱动支持不同的方式写入,默认日志会记录到文件中,系统已经内置的写入驱动包括 File.Socket,如果要临时关闭日志写入,可以设置日志类型为Test即可,例如: 'log' = ...

  10. 微信小程序原生开发简介

    简介: 总结: 1. 逻辑层使用js引擎,视图层使用webview渲染 2. 微信小程序已经支持了绝大部分的 ES6 API 3. 可以自动补全css的兼容语法 文档:https://develope ...