Trap

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 100    Accepted Submission(s): 39

Problem Description
Avin is studying isosceles trapezoids. An isosceles trapezoid is a convex quadrilateral with two opposite parallel bases, two equal-length legs and positive area. In this problem, we further require that the two legs are not parallel. Given n segments, you are asked to find the number of isosceles trapezoids whose 4 edges are from these segments and the greatest common divisor of their lengths is 1. Two congruent isosceles trapezoids are counted only once.
 
Input
The first line contains a number n (4 ≤ n ≤ 2, 000). The second line contains n numbers, each of which represents the length of a segment (the length is within [2, 10000]).
 
Output
Print the number of non-congruent isosceles trapezoids.
 
Sample Input
5
4 4 2 8 9
6
4 4 4 2 8 9
 
Sample Output
2
3
 
题意 n条线段,每条线段的长度为ai,问能够组成等腰梯形的方案数,要求四条边的gcd为1,且不是矩形,即上底下底不能相等。(4<=n<=2000,2<=ai<=10000)
解析 n只有1000 我们可以先排序去重,然后$n^2$枚举 上底 i ,下底 j,我们要找有多少个数x 满足 x的数量>=2 且 长度能与上底下底组成四边形 且 x与上底下底的gcd的gcd等于1,
所以我们预处理出来一些东西 二分去查找, 上底下底的gcd=1的时候要处理一下。
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+;
vector<int> a,b,g[maxn];
int num[maxn];
int main()
{
int n;
cin>>n;
for(int i=;i<n;i++){
int x;
cin>>x;
num[x]++;
a.push_back(x);
}
sort(a.begin(),a.end());
a.erase(unique(a.begin(),a.end()),a.end());
for(int i=;i<=;i++){
if(num[i]>=)
b.push_back(i);
}
for(int i=;i<=;i++){
for(int j=;j<(int)b.size();j++){
if(__gcd(i,b[j])==)
g[i].push_back(b[j]);
}
}
ll ans=;
for(int i=;i<(int)a.size();i++){
for(int j=i+;j<(int)a.size();j++){
int limit = (a[j]-a[i])%==?(a[j]-a[i])/+:(a[j]-a[i]+)/;
int d = __gcd(a[i],a[j]);
int index = lower_bound(g[d].begin(),g[d].end(),limit)-g[d].begin();
ans=ans+(int)g[d].size()-index;
if(d==){
if(num[a[i]]==&&a[i]>=limit)ans--;
if(num[a[j]]==&&a[j]>=limit)ans--;
}
}
}
cout<<ans<<endl;
}

2019CCPC-江西省赛C题 HDU6569 GCD预处理+二分的更多相关文章

  1. sdut 2610:Boring Counting(第四届山东省省赛原题,划分树 + 二分)

    Boring Counting Time Limit: 3000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述     In this problem you a ...

  2. 2013年省赛H题

    2013年省赛H题你不能每次都快速幂算A^x,优化就是预处理,把10^9预处理成10^5和10^4.想法真的是非常巧妙啊N=100000构造两个数组,f1[N],间隔为Af2[1e4]间隔为A^N,中 ...

  3. ACM-ICPC 2019南昌网络赛F题 Megumi With String

    ACM-ICPC 南昌网络赛F题 Megumi With String 题目描述 给一个长度为\(l\)的字符串\(S\),和关于\(x\)的\(k\)次多项式\(G[x]\).当一个字符串\(str ...

  4. 2019ICPC南京网络赛A题 The beautiful values of the palace(三维偏序)

    2019ICPC南京网络赛A题 The beautiful values of the palace https://nanti.jisuanke.com/t/41298 Here is a squa ...

  5. Python解答蓝桥杯省赛真题之从入门到真题(二刷题目一直更新)

    蓝桥刷题 原文链接: https://github.com/libo-sober/LanQiaoCup Python解答蓝桥杯省赛真题之从入门到真题 不同字串 """ 一 ...

  6. 2021江西省赛线下赛赛后总结(Crypto)

    2021江西省赛线下赛 crypto1 题目: from random import randint from gmpy2 import * from Crypto.Util.number impor ...

  7. 2013杭州现场赛B题-Rabbit Kingdom

    杭州现场赛的题.BFS+DFS #include <iostream> #include<cstdio> #include<cstring> #define inf ...

  8. 2017年第六届数学中国数学建模国际赛(小美赛)C题解题思路

    这篇文章主要是介绍下C题的解题思路,首先我们对这道C题进行一个整体的概括,结构如下: C题:经济类 第一问:发现危险人群. 发现:欺诈的方式开始.雇佣或浪漫的承诺. 数据→确定特定的经济萧条地区→确定 ...

  9. 2013年山东省赛F题 Mountain Subsequences

    2013年山东省赛F题 Mountain Subsequences先说n^2做法,从第1个,(假设当前是第i个)到第i-1个位置上哪些比第i位的小,那也就意味着a[i]可以接在它后面,f1[i]表示从 ...

随机推荐

  1. java实现带过期时间的缓存

    private static ScheduledExecutorService swapExpiredPool = new ScheduledThreadPoolExecutor(10); priva ...

  2. Linux文件删除,但是df -hT之后磁盘空间没有释放

    Linux 磁盘空间总是报警,查到到大文件,删除之后,df看到磁盘空间并没有释放. 查找了下发现系统对rm进行了alias   ,因为Linux对删除操作没有回收站机制,对rm操作进行了自定义,对删除 ...

  3. D盘Program Files 文件夹里文件不显示,没隐藏。怎么才能显示出来?

    D盘里有两个一模一样的Program Files 文件夹,文件夹里文件不显示,没隐藏.怎么才能显示出来?新买不久的电脑,win8.1系统 点击开始---运行---输入“cmd”(没有引号)---在弹出 ...

  4. python爬视频实例

    例:抓取PhotoShop视频教程 网址http://www.mxiaobei.com/?id=424 import requests import re from bs4 import Beauti ...

  5. Linux命令(1)grep

    开发过程中,与测试运维中 逐渐学习 运维常用的Linux 命令: 转自https://www.cnblogs.com/peida/archive/2012/12/17/2821195.html Lin ...

  6. export default和export的使用方式

    在node中使用 var 名称=require('模块标识符') 来导入 module.exports 和exports 来暴露成员 在ES6中,也通过规范的形式,规定了ES6中如何导入和导出模块 E ...

  7. js原生方法的重写

    讲干货,不啰嗦,通过prototype可以获取到JavaScript的原型对象,进而可以在对象原型上添加新的属性和方法,当该方法与原方法名称一样时会覆盖原方法既:重写,当不一样时既:添加 如:实现数组 ...

  8. oracle exists和 not exists 的用法

    比如 a,b 关联列为 a.id = b.id,现在要取 a 中的数据,其中id在b中也存在: select * from a where exists(select 1 from b where b ...

  9. Input system (输入子系统)

    Input system (输入子系统) 以前写一些输入设备(键盘,鼠标等)的驱动都是字符设备,混杂设备处理的,linux开源社区的大神门看到了这大量的输入设备如此分散不堪,就想有木有一种机制,可以对 ...

  10. 对WAF的一些认知

    WAF分为非嵌入型与嵌入型, 非嵌入型指的是硬WAF.云WAF.虚拟机WAF之类的:嵌入型指的是web容器模块类型WAF.代码层WAF.非嵌入型对WEB流量的解析完全是靠自身的,而嵌入型的WAF拿到的 ...