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. 浙江工商大学15年校赛E题 无邪的飞行棋 【经典背包】

    无邪的飞行棋 Time Limit 1s Memory Limit 64KB Judge Program Standard Ratio(Solve/Submit) 15.38%(4/26) Descr ...

  2. UVALive 6467 Strahler Order 拓扑排序

    这题是今天下午BNU SUMMER TRAINING的C题 是队友给的解题思路,用拓扑排序然后就可以了 最后是3A 其中两次RE竟然是因为: scanf("%d",mm); ORZ ...

  3. Week7(10月21日)

    Part I:提问  =========================== 1.请为下图编写视图代码,视图中表单提交后,交给当前控制器和动作处理. 2.如何实现点击列标题排序功能? 3.分页时采用了 ...

  4. Week10(11月11日):一个激动的日子

    Part I:提问  =========================== 请回答视图和控制器传递数据的方法. Part II:案例学习 =========================== Mu ...

  5. 基于visual Studio2013解决算法导论之012计数排序

     题目 计数排序 解决代码及点评 #include <stdio.h> #include <stdlib.h> #include <malloc.h> #in ...

  6. 使用webservice实现App与服务器端数据交互

    What? webservice曾经认为是解决异构系统间整合的最佳解决方案,不依赖于第三方任何系统的支持(不需要部署RDBMS服务器),大家只需要按照官方的规范,即可完成相互之间的数据交互. Why? ...

  7. C++中的智能指针(auto_ptr)

    实际上auto_ptr 仅仅是C++标准库提供的一个类模板,它与传统的new/delete控制内存相比有一定优势.使用它不必每次都手动调用delete去释放内存.当然有利也有弊,也不是全然完美的. 本 ...

  8. 2014Esri全球用户大会之标准和互操作

    1.   ArcGIS是一个开放协作的平台吗?Esri是怎样看待"开放"的? 是的,ArcGIS是一个开放协作的平台.Esri公司致力于支持我们的用户更加easy的在异构环境下工作 ...

  9. linux BC命令行计算器

    1. 基本使用: $ bc <<< 5*4 20 $ bc <<< 5+4 9 $ bc <<< 5-4 1 或者 $ echo "5* ...

  10. Android创建与读取Excel

    主流的操作Excel的有两种方法,一种是通过poi包,另一种是通过jxl包.这里我主要讲解通过jxl包来读写Excel. 首先需要导入一个jxl.jar包. 下载地址:http://www.andyk ...