Trap HDU - 6569 二分
题意:
给你n个边长ai,你需要挑出来4个边使得它们可以构成等腰梯形。问你能构成多少种不同的等腰梯形
题解:
我们首先处理一下边长为x的且这个边长出现大于等于2次的边,因为等腰梯形需要两条相等的边
然后枚举上底a,和下底b,这个时候取得gcd(a,b),然后找和gcd(a,b)互质的边,且这个边要出现大于等于两次
因为等腰梯形有(上底+2*腰长)>下底,所以腰长>(下底-上底)/2
具体见代码
代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#define mem(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
vector<int> a,b,g[maxn];
int num[maxn];
int main()
{
int n;
cin>>n;
for(int i=0; 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()); //去重
int len=a.size();
// for(int i=0;i<len;++i)
// {
// printf("%d ",a[i]);
// }
// printf("*******\n");
for(int i=0; i<=10000; i++)
{
if(num[i]>=2)
b.push_back(i);
}
for(int i=1; i<=10000; i++)
{
for(int j=0; j<(int)b.size(); j++)
{
if(__gcd(i,b[j])==1)
g[i].push_back(b[j]);
}
}
ll ans=0;
for(int i=0; i<a.size(); i++)
{
for(int j=i+1; j<a.size(); j++)
{
int limit = (a[j]-a[i])%2==0?(a[j]-a[i])/2+1:(a[j]-a[i]+1)/2; //等腰梯形限制条件
int d = __gcd(a[i],a[j]);
int index = lower_bound(g[d].begin(),g[d].end(),limit)-g[d].begin();
ans=ans+g[d].size()-index;
if(d==1) //特判一下等腰梯形三条边都相等的情况
{
if(num[a[i]]==2&&a[i]>=limit)ans--;
if(num[a[j]]==2&&a[j]>=limit)ans--;
}
}
}
printf("%d\n",ans);
return 0;
}
Trap HDU - 6569 二分的更多相关文章
- hdu 4024 二分
转自:http://www.cnblogs.com/kuangbin/archive/2012/08/23/2653003.html 一种是直接根据公式计算的,另外一种是二分算出来的.两种方法速度 ...
- hdu 1669(二分+多重匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1669 思路:由于要求minimize the size of the largest group,由此 ...
- HDU 3586 二分答案+树形DP判定
HDU 3586 『Link』HDU 3586 『Type』二分答案+树形DP判定 ✡Problem: 给定n个敌方据点,1为司令部,其他点各有一条边相连构成一棵树,每条边都有一个权值cost表示破坏 ...
- hdu 4004 (二分加贪心) 青蛙过河
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4004 题目意思是青蛙要过河,现在给你河的宽度,河中石头的个数(青蛙要从石头上跳过河,这些石头都是在垂 ...
- hdu 5046 二分+DLX模板
http://acm.hdu.edu.cn/showproblem.php?pid=5046 n城市建k机场使得,是每个城市最近机场的距离的最大值最小化 二分+DLX 模板题 #include < ...
- HDU 5699 二分+线性约束
http://acm.hdu.edu.cn/showproblem.php?pid=5699 此题满足二分性质,关键在于如何判断当前的时间值可以满足所有的运送方案中的最长的时间. 对于每一次枚举出的k ...
- hdu 3277(二分+最大流+拆点+离线处理+模板问题...)
Marriage Match III Time Limit: 10000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu 3081(二分+并查集+最大流||二分图匹配)
Marriage Match II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- hdu 1816(二分+2-sat)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1816 思路:首先将每把钥匙i拆成两个点i和i+2n,分别表示选与不选,对于被分成n对的钥匙,由于只能选 ...
随机推荐
- 为linux添加一块新硬盘并分区
一---如何增加一块硬盘1:虚拟机添加硬盘2:分区3:格式化4:挂载5:设置可以自动挂载 1---设置里面 2---分区命令 fdisk /dev/sdb开始分区m显示命令列表p显示磁盘分区 同fdi ...
- Can't locate CPAN.pm in @INC
[root@test]# perl -MCPAN -e 'install DBD::mysql'Can't locate CPAN.pm in @INC (@INC contains: /usr/lo ...
- Ubuntu16.04安装MySQL8.0
1.Ubuntu换源(阿里云) sudo cp /etc/apt/sources.list /etc/apt/sources.list.baksudo vi /etc/apt/sources.list ...
- BAPI_GOODSMVT_CREATE的参数GOODSMVT_CODE的说明
BAPI_GOODSMVT_CREATE 的功能就是用于货物移动,其主要可以实现MB*事物的一些功能,其中该BAPI的参数 GOODSMVT_CODE就控制了对应哪个事物码的功能,下面给出该参数的值和 ...
- 【Windows】Win10家庭版启用组策略gpedit.msc
[前言] 大家都认为,Windows 10家庭版中并不包含组策略,其实不然,它是有相关文件的,只是不让你使用而已.那么我们让系统允许你使用就好了. [操作步骤] 1.首先你需要在桌面上新建一个txt文 ...
- 逃逸分析与栈、堆分配分析 escape_analysis
小结: 1.当形参为 interface 类型时,在编译阶段编译器无法确定其具体的类型.因此会产生逃逸,最终分配到堆上. 2.The construction of a value doesn't d ...
- detect data races The cost of race detection varies by program, but for a typical program, memory usage may increase by 5-10x and execution time by 2-20x.
小结: 1. conflicting access 2.性能危害 优化 The cost of race detection varies by program, but for a typical ...
- power network 电网——POJ1459
Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 27282 Accepted: 14179 D ...
- BootstrapValidator验证规则、BootStrap表格:列参数
BootstrapValidator验证规则 需引用组件 <script src="~/Scripts/jquery-1.10.2.js"></script> ...
- fastHttp服务端处理请求的过程
Github 地址 https://github.com/valyala/fasthttp fastHttp 服务端的处理请求的过程 工作过程 主要代码 设置监听地址 server.go func ( ...