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. (三)Spring框架之事务管理

    一.编程式事务管理 Spring事务管理器的接口是org.springframework.transaction.PlatformTransactionManager,事务管理器接口PlatformT ...

  2. pmtk3

    summary A list of every PMTK3 demo auto-generated by publishDemos on 27-Mar-2012 Book Demos (1) Intr ...

  3. HTTP参数污染(参数处理图)

  4. JavaScript--常用对象的属性及方法(1)

    1.Number对象(基本数据类型) Number对象的方法大多是一些强制转换方法,如果转换失败返回NaN,以下举例中用number来代替具体数字: *console.log在控制台输出(键盘F12可 ...

  5. C++ STL 之 函数对象适配器

    谓词是指普通函数或重载的 operator()返回值是 bool 类型的函数对象(仿函数).如果operator 接受一个参数,那么叫做一元谓词,如果接受两个参数,那么叫做二元谓词,谓词可作为一个判断 ...

  6. 常用git指令记录

    Generating an SSH key Checking for existing SSH keys Generating a new SSH key and adding it to the s ...

  7. LVS介绍及相关配置

    一. LVS概述 LVS是一种工作在四层协议上的负载均衡解决方案,在1998年5月由章文嵩博士创建.目前广泛使用的负载均衡模型主要有: 1)工作在四层协议(LVS):主要用于四层协议上的负载均衡,性能 ...

  8. MySQL的MHA实现高可用性

    MySQL高可用 (1)MMM: Multi-Master Replication Manager for MySQL,Mysql主主复制管理器是一套灵活的脚本程序,基于perl实现,用来对mysql ...

  9. 【转】ufw 端口

    1.扫描端口 用ubuntu自带的网络工具中的端口扫描不够强大,扫描结果可能不全,推荐用nmap,黑客常用的端口扫描利器!安装方法:sudo apt-get install nmap ,想扫描端口nm ...

  10. 使用fastjson统一序列化响应格式

    摘要:其实很简单的处理方式,只不够优雅,或者说没有找到fastjson为其提供便捷的处理方式.因此记录下处理该问题的过程. 目标:将所有api请求,即响应为APPLICATION_JSON的内容做统一 ...