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. 信息设计工具IDT创建从SAP Business Object到SAP HANA的连接

    1. 打开Information Design Tool, 并添加BO Server的连接 2. 在Connection上右击, 选择Insert Relational Connection 3. 输 ...

  2. 加班计时App

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. python项目练习地址

    作者:Wayne Shi链接:http://www.zhihu.com/question/29372574/answer/88744491来源:知乎著作权归作者所有,转载请联系作者获得授权. 目前是3 ...

  4. ios监听ScrollView/TableView滚动的正确姿势

    主要介绍 监测tableView垂直滚动的舒畅姿势 监测scrollView/collectionView横向滚动的正确姿势 1.监测tableView垂直滚动的舒畅姿势 通常我们用KVO或者在scr ...

  5. IOS Android支持中文与本地文件的读取写入

    转自http://www.xuanyusong.com/archives/1069 和http://www.benmutou.com/archives/2094 前几天有个朋友问我为什么在IOS平台中 ...

  6. java中equals方法和contentEquals方法区别

    java中,String类里提供了两种字符串的比较方式(算上“==”应该是三种) String line1 = new String("0123456789"); String l ...

  7. JQuery笔记(二)jq常用方法animate()

    在jq中,比较方便的是相对于js,jq封装了很多方法,很方便使用,下面我举几个常用的方法 animate()方法 <!DOCTYPE html> <html lang="e ...

  8. matlab,xls转换为mat文件

    b=xlsread('iris_data.xls');save iris_data.mat b

  9. Base algorithm

    今天介绍几种常见的算法,在面试中或许能派上用场 1.字符串倒转 //Reverse a string public static string Reverse(string ori) { string ...

  10. fbset视频参数说明

    在机器上输入:fbset mode "1280x720-55"  # D: 67.504 MHz, H: 40.961 kHz, V: 54.907 Hz geometry 128 ...