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. hdu 1325

    .,. 还是待整理 #include <stdio.h> const; typedef struct { int num,root,conn;//数据.根.入度 }Node; Node n ...

  2. (十五)SpringBoot之使用Redis做缓存数据

    一.添加Redis依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns=" ...

  3. 树节点递归删除--service层

    @Service public class ContentCategoryServiceImpl extends BaseServiceImpl<ContentCategory> impl ...

  4. koa-router学习笔记

    koa-router 是koa框架的一个路由处理级别的中间件. 目录结构 ├── app.js ├── middleware │ ├── m1.js │ └── m2.js ├── package-l ...

  5. VBA连接操作符

    VBA支持以下连接运算符. 假设变量A=5,变量B=10,则 - 运算符 描述 示例 + 将两个值添加为变量,其值是数字 A + B = 15 & 连接两个值 A & B = 510 ...

  6. 异常信息:javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed

    上周五遇到一个问题,工程本地编译运行正常,打包本地tomcat运行也正常.部署到测试环境报错: 2017-05-05 09:38:11.645 ERROR [HttpPoolClientsUtil.j ...

  7. Servlet实现图片读取显示

    1.导入jar包:commons-io-1.4.jar 2.index.jsp: <%@ page language="java" import="java.uti ...

  8. vue之生命周期与导航守卫

    组件钩子函数: beforeCreate.created.beforeMount.mounted.beforeUpdate.updated.beforeDestroy.destoryed 还有两个特殊 ...

  9. 伪元素before和after本质

    之所以被称为伪元素,是因为他们不是真正的页面元素,html没有对应的元素,但所有的用法和表现行为和真正的页面元素是一样的,可以对其使用诸如页面元素一样的css样式,表面上看上去貌似页面的谋些元素,实际 ...

  10. git的使用(win7 64位)

    下载安装 1.官方下载网址:https://git-scm.com/downloads: 2.安装十分简单,按照默认配置,一直点击next,最后点击install,即安装成功: 3.安装成功之后,则自 ...