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;
}

最新文章

  1. LINQ to XML
  2. vbox 网络配置文件
  3. 方法重载的小demo
  4. LoadRunner 多场景批处理
  5. iOS 中NSOperationQueue,Grand Central Dispatch , Thread的上下关系和区别
  6. jeecg团队招新人(5人)
  7. Ajax—初识
  8. 使用minidom来处理XML的示例(Python 学习)(转载)
  9. 华哥倒酒&lt;区间标记,二分&gt;
  10. Ant Design UI组件
  11. Python 获取当前脚本文件路径目录
  12. 关于模拟登陆微博(PC)
  13. Spring AOP AspectJ
  14. json 模块 与 pickle 模块
  15. Spring MVC4 + Spring Security4 + Hibernate实例
  16. 使用C#把发表的时间改为几个月,几天前,几小时前,几分钟前,或几秒前
  17. PAT乙级1009
  18. elasticsearch备份与恢复
  19. pwa学习笔记--简介
  20. js查看对象内容

热门文章

  1. 游记-pkupc&amp;cts2019
  2. 将迁移学习用于文本分类 《 Universal Language Model Fine-tuning for Text Classification》
  3. 数据仓库之抽取数据:openrowset函数带bulk操作符的用法
  4. JFinal(2)JFinal 学习资料
  5. MVC的12种ActionResult介绍以及应用示例【转】
  6. @PostConstruct注解原理解析
  7. Shell学习笔记:awk实现group by分组统计功能
  8. 7.Redis的发布订阅
  9. Echarts如何添加鼠标点击事件?防止重复触发点击事件
  10. pycharm2017.3版本永久激活