BestR #31
求|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 ;
}
题意是:一个数如果其低位小于等于高位,并且高位是相邻地位的整数倍则称为魅力的数,要求求出[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的更多相关文章
- 城市代码表mysql
只有代码: # ************************************************************ # Sequel Pro SQL dump # Version ...
- CSharpGL(31)[译]OpenGL渲染管道那些事
CSharpGL(31)[译]OpenGL渲染管道那些事 +BIT祝威+悄悄在此留下版了个权的信息说: 开始 自认为对OpenGL的掌握到了一个小瓶颈,现在回头细细地捋一遍OpenGL渲染管道应当是一 ...
- 计算机程序的思维逻辑 (31) - 剖析Arrays
数组是存储多个同类型元素的基本数据结构,数组中的元素在内存连续存放,可以通过数组下标直接定位任意元素,相比我们在后续章节介绍的其他容器,效率非常高. 数组操作是计算机程序中的常见基本操作,Java中有 ...
- SQL Server查询第31到40条数据
大致分为两种情况:ID连续和ID不连续. 1.ID连续的情况: 2.ID不连续的情况: (1).两次对表查询,效率较低. ID from A) (2).外层查询没有对表A进行查询,效率提高. ID f ...
- 把《c++ primer》读薄(3-1 标准库string类型初探)
督促读书,总结精华,提炼笔记,抛砖引玉,有不合适的地方,欢迎留言指正. 问题1:养成一个好习惯,在头文件中只定义确实需要的东西 using namespace std; //建议需要什么再using声 ...
- 背水一战 Windows 10 (31) - 控件(按钮类): ButtonBase, Button, HyperlinkButton, RepeatButton, ToggleButton, AppBarButton, AppBarToggleButton
[源码下载] 背水一战 Windows 10 (31) - 控件(按钮类): ButtonBase, Button, HyperlinkButton, RepeatButton, ToggleButt ...
- Lind.DDD.Manager里的3,7,15,31,63,127,255,511,1023,2047
回到目录 进制 我是一个程序猿,我喜欢简单的数字,十进制如何,数字太多,有10种数字组成,但由于它广为人知,所有使用最为广泛,人们的惯性思维培养了十进制,并说它是最容易被计算的数字,事实上,在计算机里 ...
- 2017年1月5日 星期四 --出埃及记 Exodus 21:31
2017年1月5日 星期四 --出埃及记 Exodus 21:31 This law also applies if the bull gores a son or daughter.牛无论触了人的儿 ...
- 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 ...
随机推荐
- ZOJ 3211 Dream City DP 01背包 经典问题
题目大意:JAVAMAN 到梦幻城市旅游见到了黄金树,黄金树上每天回结出金子.已经有n棵树,JAVAMAN要停留m天,每天只能砍掉一棵树,砍掉树后就能得到树上的黄金.给定n棵树上原有的黄金a[i]和每 ...
- MFC全局函数开局——AfxGetApp解剖
MFC中有不少的全局函数,方便在不同对象中获取不同的内容或创建不同的对象.主要全局函数有: AfxWinInit() AfxBeginThread() AfxEndThread() AfxFormat ...
- android 发送短信 怎样做到一条一条的发送,仅仅有在上一条发送成功之后才发送下一条短信
android发送短信截获上一条发送是否成功,然后再来发送下一条短信 1.问题:在项目中遇到例如以下要求:待发短信有N条,实现一条一条的发送并在上一条短信发送成功之后再来发送下一条. for(int ...
- Android的BUG(二) - SurfaceTexture中的野指针
当初遇到这个bug,是不定期的低概率出现,最后找到一个比较容易重现的步骤: 启动系统 然后进google + 新建一个帐号(注意是新建一个帐号) 没几步就重启了 这个BUG,一开始追踪也是无头绪的 ...
- Linux命令: chown
touch auth.log root@ubuntu:/work# ls -l auth.log -rw-r--r-- 1 root root 0 Feb 18 19:27 auth.log chow ...
- File类常见方法
package file; import java.io.File; public class FileTest2 { public static void main(String[] args) { ...
- PowerManager.WakeLock
PowerManager.WakeLock PowerManager.WakerLock是我分析Standup Timer源代码时发现的一个小知识点,Standup Timer 用WakeLock保证 ...
- c++ 静态成员遇到的坑总结
新标签页http://74.55.154.136/ c++ 静态成员遇到的坑总结 - linuxfloat - 博客园 c++ 静态成员遇到的坑总结 1.对于类静态变量的初始化,用下面方法. // ...
- 用overflow-y 解决web页面抖动问题
页面抖动(左右抖动)让人视觉上很不爽.. /** original : php攻城师 http://blog.csdn.net/phpgcs **/ 最开始我也以为是 layout 不一致的原因..后 ...
- or1200构建sopc系统之软件环境搭建
使用预先编译好的工具链 下载: ftp://ocuser:oc@195.67.9.12/toolchain/or32-elf-linux-x86.tar.bz2 解压 tar xjf or32-elf ...