hdu 5178

求|a[i] - a[j]| <= k (i < j) <i,j>的对数,一开始认为数据不大就直接ans++了,后来结果出来才知道,啊啊啊,too young too simple。总之一个教训

思路:先排序,然后用二分查找寻找a[i] + k 在数组中的位置,然后 ans相加

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <stack>
#include <cctype>
#include <string>
#include <malloc.h>
#include <queue>
#include <map> using namespace std; const int INF = 0xffffff;
const double esp = 10e-;
const double Pi = * atan(1.0);
const int maxn = +;
const long long mod = ;
const int dr[] = {,,-,,-,,-,};
const int dc[] = {,,,-,,-,-,};
typedef long long LL; LL gac(LL a,LL b){
return b?gac(b,a%b):a;
} long long a[maxn]; int main()
{
#ifndef ONLINE_JUDGE
freopen("inpt.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
int t;
int n,k;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&k);
memset(a,,sizeof(a));
for(int i = ;i < n;i++){
scanf("%I64d",&a[i]);
}
sort(a,a+n);
long long ans = ;
for(int i = ;i < n-;i++){
long long tmp = a[i] + k;
int m = upper_bound(a,a+n,tmp)- a;
ans += (m-i-);
}
printf("%I64d\n",ans);
}
return ;
}

hdu 5179

题意是:一个数如果其低位小于等于高位,并且高位是相邻地位的整数倍则称为魅力的数,要求求出[L,R]范围内美丽数的个数

思路,dfs暴力。

做到了第二题啦~~

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <stack>
#include <cctype>
#include <string>
#include <malloc.h>
#include <queue>
#include <map> using namespace std; const int INF = 0xffffff;
const double esp = 10e-;
const double Pi = * atan(1.0);
const int maxn = +;
const long long mod = ;
const int dr[] = {,,-,,-,,-,};
const int dc[] = {,,,-,,-,-,};
typedef long long LL; LL gac(LL a,LL b){
return b?gac(b,a%b):a;
} int L,R;
int a[],b[];
int arr[];
int cnt; long long get_num(int x){
long long tmp = ;
for(int i = x-;i > ;i--){
tmp = tmp * + arr[i];
}
// cout << tmp << endl;
return tmp;
} void dfs(int x){
long long tt = get_num(x);
if(tt > R)
return;
if(tt >= L)
cnt++;
for(int i = ;i < ;i++){
int tmp = arr[x-] * i;
if(tmp < ){
arr[x] = tmp;
dfs(x+);
}
arr[x] = ;
}
} int main()
{
#ifndef ONLINE_JUDGE
freopen("inpt.txt","r",stdin);
#endif
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d",&L,&R);
memset(arr,,sizeof(arr));
cnt = ;
arr[] = ;
dfs();
printf("%d\n",cnt);
}
return ;
}

第三题什么的就没做出来……

BestR #31的更多相关文章

  1. 城市代码表mysql

    只有代码: # ************************************************************ # Sequel Pro SQL dump # Version ...

  2. CSharpGL(31)[译]OpenGL渲染管道那些事

    CSharpGL(31)[译]OpenGL渲染管道那些事 +BIT祝威+悄悄在此留下版了个权的信息说: 开始 自认为对OpenGL的掌握到了一个小瓶颈,现在回头细细地捋一遍OpenGL渲染管道应当是一 ...

  3. 计算机程序的思维逻辑 (31) - 剖析Arrays

    数组是存储多个同类型元素的基本数据结构,数组中的元素在内存连续存放,可以通过数组下标直接定位任意元素,相比我们在后续章节介绍的其他容器,效率非常高. 数组操作是计算机程序中的常见基本操作,Java中有 ...

  4. SQL Server查询第31到40条数据

    大致分为两种情况:ID连续和ID不连续. 1.ID连续的情况: 2.ID不连续的情况: (1).两次对表查询,效率较低. ID from A) (2).外层查询没有对表A进行查询,效率提高. ID f ...

  5. 把《c++ primer》读薄(3-1 标准库string类型初探)

    督促读书,总结精华,提炼笔记,抛砖引玉,有不合适的地方,欢迎留言指正. 问题1:养成一个好习惯,在头文件中只定义确实需要的东西 using namespace std; //建议需要什么再using声 ...

  6. 背水一战 Windows 10 (31) - 控件(按钮类): ButtonBase, Button, HyperlinkButton, RepeatButton, ToggleButton, AppBarButton, AppBarToggleButton

    [源码下载] 背水一战 Windows 10 (31) - 控件(按钮类): ButtonBase, Button, HyperlinkButton, RepeatButton, ToggleButt ...

  7. Lind.DDD.Manager里的3,7,15,31,63,127,255,511,1023,2047

    回到目录 进制 我是一个程序猿,我喜欢简单的数字,十进制如何,数字太多,有10种数字组成,但由于它广为人知,所有使用最为广泛,人们的惯性思维培养了十进制,并说它是最容易被计算的数字,事实上,在计算机里 ...

  8. 2017年1月5日 星期四 --出埃及记 Exodus 21:31

    2017年1月5日 星期四 --出埃及记 Exodus 21:31 This law also applies if the bull gores a son or daughter.牛无论触了人的儿 ...

  9. 2016年12月31日 星期六 --出埃及记 Exodus 21:26

    2016年12月31日 星期六 --出埃及记 Exodus 21:26 "If a man hits a manservant or maidservant in the eye and d ...

随机推荐

  1. 432B - Football Kit

    解题思路: 暴力绝对TLE 一个队伍穿主场球衣的次数 = 这个队伍的客场球衣颜色与其他队主场球衣颜色起冲突的次数 + (n - 1) #include <stdio.h> #include ...

  2. svn笔记4属性Properties

    我们已经详细讲述了Subversion存储和检索版本库中不同版本的文件和目录的细节,并且用了好几个章节来论述这个工具的基本功能.如果对于版本化的支持到此为止,从版本控制的角度来看Subversion已 ...

  3. C#动态增加边框

    if (this.Width >= 600) { timer1.Enabled = false; } else { this.Width += 30; }

  4. 原生app与web app的比较

    http://www.2ee9.com/news/news_show_36_237.html http://zhidao.baidu.com/link?url=7lWq2tgqiMiDmsRd54hO ...

  5. DeDeCMS中如何实现下拉菜单

    在5.7版本,已经有比较简单的方法实现下拉菜单,我们可以用它已有方法,也可以用我写的第二种方法来实现 1. 在需要下拉菜单的地方加入以下代码 <div id="navMenu" ...

  6. 让你的 Qt 桌面程序看上去更加 native(一共六篇)

    <让你的 Qt 桌面程序看上去更加 native>是一个系列文章.在这个系列中,你将会了解到如何让你的 Qt 桌面应用程序看上去更加 native.这里,我假设你已经清楚如何使用 Qt 编 ...

  7. android页面切换效果

    两种方式: 在activity的自定义主题中定义切换方式: overridePendingTransition()方法 自定义主题: 在项目的res/values/styles.xml中添加样式 &l ...

  8. 分享非常有用的Java程序 (关键代码)(五)---把 Array 转换成 Map

    原文:分享非常有用的Java程序 (关键代码)(五)---把 Array 转换成 Map import java.util.Map; import org.apache.commons.lang.Ar ...

  9. wireshark 抓包分析 TCPIP协议的握手

    wireshark 抓包分析 TCPIP协议的握手 原网址:http://www.cnblogs.com/TankXiao/archive/2012/10/10/2711777.html 之前写过一篇 ...

  10. 基于visual Studio2013解决C语言竞赛题之1024求和

          题目 解决代码及点评 /* 已知有N个无规律的正整数,请编程序求出其中的素数并打印出能被5整除的数之积. */ #include <stdio.h> # ...