Time Limit: 3000MS   Memory Limit: 524288KB   64bit IO Format: %I64d & %I64u

Description

方宝宝有n个篮球,每个篮球上写有一个值ai。他第一次从n个篮球中取出1个,不放回。第二次再在剩余的篮球中取出一个。
(每个球被取概率相同)。如果这两个球上的值的乘积大于等于p,他会变得高兴,然后请大家吃饭。否则方宝宝会不高兴,
然后暴食暴饮变得更胖。
当然为了方宝宝的健康(被请吃饭),我想取一个合适的p值,使方宝宝高兴。
那么问题来了,现在有m个数:p1,p2……pm.对于每个p值有多少种选法使方宝宝高兴。
于是善(毒)良(瘤)的出题人把这个问题交给了你们。

Input

第一个行的数是n,第二行是个篮球上面的值ai,第三行是m,第四行p1, p2, p3……pm.
1<=n<=10^6,1<=m<=10^6,1<=pi<=3*10^6,1<=ai<=10^6

Output

第i行输出对于当前pi值,方宝宝能赢的方案数。

Sample Input

输入:
5
4 2 6 1 3
4
1 3 5 8
输出:
20
18
14
10
 
输入:
2
5 6
2
30 31
输出:
2
0

Source

 
好不容易看到一道CF的中文题(原题是英文的) 果断就做了……
 
题意:
有n个篮球 不放回取出两个球a b
对于m组提问 问对每个pi a*b>=pi的取法有多少种
 
思路:
根据样例可以分析出来(a=5,b=6)和(a=6,b=5)是两种方法
所以算出来的正常值应该乘2
而且时间限制3000ms 内存限制也很大 就想到暴力了
开两个3e6的数组 计算之前先预处理一下
最后输出n*(n-1)-sum[n-1]  这个式子就已经是乘2的了
 
 #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
#define M(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=3e6+;
ll cnt[maxn];
ll sum[maxn];
ll n,m,a,max_=-;
int main(){
scanf("%I64d",&n);
for(int i=;i<n;i++){
scanf("%d",&m);
cnt[m]++;
if(m>max_) max_=m;
}
for(int i=;i<=max_;i++){
for(int j=;j<=max_;j++){
if(i*j>maxn) break;
sum[i*j]+=cnt[i]*cnt[j];
if(i==j) sum[i*j]-=cnt[j];
}
}
for(int i=;i<=maxn;i++)
sum[i]+=sum[i-];
scanf("%I64d",&m);
for(int i=;i<m;i++){
scanf("%d",&a);
printf("%I64d\n",n*(n-)-sum[a-]);
}
return ;
}
/* 5
4 2 6 1 3
4
1 3 5 8 2
5 6
2 */

[ An Ac a Day ^_^ ] CodeForces 691F Couple Cover 花式暴力的更多相关文章

  1. codeforces 691F Couple Cover 暴力

    分析:开一个300w的数组,统计,然后nlogn统计每个值在在序对第一个出现有多少种情况 时间复杂度:O(nlogn) n在3e6数量级 #include<cstdio> #include ...

  2. Codeforces 691F Couple Cover

    可以暴力预处理出每一种小于3000000的乘积有几种.询问的时候可以用总的方案减去比p小的有几种o(1)输出. #pragma comment(linker, "/STACK:1024000 ...

  3. codeforces 691F F. Couple Cover(组合计数)

    题目链接: F. Couple Cover time limit per test 3 seconds memory limit per test 512 megabytes input standa ...

  4. codeforces 691F 暴力

    传送门:https://codeforces.com/contest/691/problem/F 题意:给你n个数和q次询问,每次询问问你有多少对ai,aj满足ai*aj>=q[i],注意 a* ...

  5. codeforces 691F(组合数计算)

    Couple Cover, a wildly popular luck-based game, is about to begin! Two players must work together to ...

  6. codeforces 675B B. Restoring Painting(暴力枚举)

    题目链接: B. Restoring Painting time limit per test 1 second memory limit per test 256 megabytes input s ...

  7. Codeforces 626D Jerry's Protest(暴力枚举+概率)

    D. Jerry's Protest time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  8. CodeForces - 1013B And 与运算暴力

    题目链接: https://vjudge.net/problem/1735275/origin 基本思路: 本题思路比较简单,首先,我们知道 a & x = b, b & x = b; ...

  9. codeforces 650D D. Image Preview (暴力+二分+dp)

    题目链接: http://codeforces.com/contest/651/problem/D D. Image Preview time limit per test 1 second memo ...

随机推荐

  1. line-height 行高

    line-height 行高指一行文字的高度,具体来说是指两行文子间基线间的距离      line-height 与 font-size 的计算值之差(行距)分为两半,分别加到一个文本行内容的顶部和 ...

  2. Arch安装KDE5

    plasma desktop Install the plasma-meta meta-package or the plasma group. Alternatively, for a more m ...

  3. Java中IO流

    * IO流用来处理设备之间的数据传输 * Java对数据的操作是通过流的方式 * Java用于操作流的类都在IO包中 * 流按流向分为两种:输入流,输出流. * 流按操作类型分为两种: * 字节流 : ...

  4. 获取XMLHttpRequest对象

    //创建一个XMLHttpRequest对象 ,利用此对象与服务器进行通信 是AJAX技术的核心 /////////////////////////////////////////////////// ...

  5. Ajax中参数带有html格式的 传入后台保存【二】

    KindEditor.ready(function (K) { //编辑器插件 window.editor1 = K.create('#ctjs', { uploadJson: '/Hotelgl/U ...

  6. 项目版本管理 github简介

    git config user.email "c.wuliying@samsung.com"git config user.name "swportal" ** ...

  7. JAVA的if用法,比如if(...){} 和if()没有大括号直接写下面的区别是什么

    有大括号的时候 大括号里面所有的 都归if管.只有条件为真的时候 才会执行.没有大括号的时候 只有下面的一句归if管,也就是说 当只有一句的时候 大括号可以省略 其它的 没区别.

  8. HDU 4291 A Short problem(2012 ACM/ICPC Asia Regional Chengdu Online)

    HDU 4291 A Short problem(2012 ACM/ICPC Asia Regional Chengdu Online) 题目链接http://acm.hdu.edu.cn/showp ...

  9. NIO和IO(转)

    java NIO由以下几个核心部分组成: Channels(通道) Buffers(缓冲区) Selectors(选择器) 其他 Channel和Buffer: 所有的IO再NIO中都从一个Chann ...

  10. bit、byte、k

    bit(位/比特位):一个二进制数据0/1 byte(字节):简称B:1byte=8bit:一个英文字符占用1byte,一个汉字占用2byte k:1K=1024B M:1M=1024K