Codeforces 691F. Couple Cover (暴力)
来源:互联网 发布:js数组赋值 编辑:程序博客网 时间:2024/05/22 03:36
题目链接
简单题意
给出一个序列,和一些询问,每个询问包含一个整数q,问序列中乘积不小于q的数对有多少对
思路
(代码更容易看懂)
因为q最多是3e6,所以只要统计一下序列中哪些数出现过,出现过多少次,然后用一个二重循环
然后对输入查表,用总数减去乘积小于q的数量就得到答案。
PS:也可以先读入数据,
代码
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int maxn = 3e6+10;ll num[maxn];ll sum[maxn];int main(){ ll n,m; scanf("%I64d", &n); ll ma = 0; for(int i = 0 ; i < n ; i++){ scanf("%I64d",&m); num[m]++; ma = max(ma,m); } for(int i = 0 ; i <= ma ; i ++){ for(int j = 0 ; j <= ma; j ++){ if(1LL*i*j > 3e6) break; sum[i*j] += num[i] * num[j]; if(i == j) sum[i*j] -= num[i]; } } for(int i = 1 ; i < maxn ; i ++) sum[i] += sum[i-1]; scanf("%I64d",&m); for(int i = 0 ; i < m ; i ++){ ll tmp; scanf("%I64d", &tmp); printf("%I64d\n", n*(n-1) - sum[tmp-1]); }}
0 0
- Codeforces 691F. Couple Cover (暴力)
- Codeforces 691F. Couple Cover (暴力)
- codeforces 691F Couple Cover 暴力预处理
- codeforces 731F (暴力)
- hdu 5386 Cover (暴力)
- hdu 5386 Cover(暴力)
- Codeforces Gym 101061 F(暴力搜索做法)
- (奇怪的暴力)codeforces 731F 354C
- hdu 5386 Cover (逆向暴力模拟)
- Codeforces 490F. Treeland Tour 暴力+LIS
- codeforces 731F 暴力(前缀和)
- HDU 5386 Cover(暴力)
- hdu5386 Cover(暴力,观察)
- hdu 5386 Cover(暴力求解+想法题)
- hdu 5386 Cover 暴力模拟
- HDU5386 Cover 果然还是暴力
- couple
- Codeforces 779B(暴力)
- chgrp/chmod/chown/ln 命令详解
- 最流行强大的页面标签框架 display:table 使用
- common.constant 常量枚举类型
- 【Android】解决Genymotion无法打开
- 对Debug和Release的一些理解
- Codeforces 691F. Couple Cover (暴力)
- 30分钟git命令入门到放弃
- 博弈论(sg函数)
- delete 和 delete [] 区别
- [Android] 在Jni中对SurfaceView渲染一张图片
- JSTL函数标签库 fn标签
- NYOJ245编号统计
- linux 数据盘分区挂载
- 典型的非对称加密算法 RSA