codeforce 448 B. XK Segments

解决一个算法问题,找出数组中满足特定条件的有序数对数量。条件涉及元素间的关系及可被特定整数整除的中间数值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

B. XK Segments
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j)such that ai ≤ aj and there are exactly k integers y such that ai ≤ y ≤ aj and y is divisible by x.

In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).

Input

The first line contains 3 integers n, x, k (1 ≤ n ≤ 105, 1 ≤ x ≤ 109, 0 ≤ k ≤ 109), where n is the size of the array a and x and k are numbers from the statement.

The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a.

Output

Print one integer — the answer to the problem.

Examples
input
4 2 1
1 3 5 7
output
3
input
4 2 0
5 3 1 7
output
4
input
5 3 1
3 3 3 3 3
output
25
 
   
排序不影响最后的结果,因为求得是多少个,并没有具体到哪个;
对于某个数a[i],如果他是x的倍数,设为t*x,如果在a[i]~a[j]之间恰好有k个y满足条件,那么a[j]的范围是[(t+k-1)*x,(t+k+1)*x-1],如果他不是x的倍数,设他为kx+b;则a[j]的范围为[(t+k)*x,(t+k+1)*x-1];
枚举a[i],在此范围内求满足的a[j]个数;
lower_bound(x,y,z),从地址x到地址y,寻找第一个大于等于z的数,并返回其位置;
std::ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
加上这两句可以使cin cout快的飞起,和scanf printf相差无几;
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h> 
using namespace std;
typedef long long ll;
ll a[100100];
int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll n,x,k;
	ll ans=0;
	memset(a,0,sizeof(a));
	cin>>n>>x>>k;
	for (int i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	for (int i=0;i<n;i++)
	{
	 ll r=x*(k+1+(a[i]-1)/x);
	 ll l=max(x*(k+(a[i]-1)/x),a[i]);
	 ans+=lower_bound(a,a+n,r)-lower_bound(a,a+n,l);
    }
	cout<<ans<<endl;
	return 0;
} 


 
  
汉字字库存储芯片扩展实验 # 汉字字库存储芯片扩展实验 ## 实验目的 1. 了解汉字字库的存储原理和结构 2. 掌握存储芯片扩展技术 3. 学习如何通过硬件扩展实现大容量汉字字库存储 ## 实验原理 ### 汉字字库存储基础 - 汉字通常采用点阵方式存储(如16×16、24×24、32×32点阵) - 每个汉字需要占用32字节(16×16)到128字节(32×32)不等的存储空间 - 国标GB2312-80包含6763个汉字,需要较大存储容量 ### 存储芯片扩展方法 1. **位扩展**:增加数据总线宽度 2. **字扩展**:增加存储单元数量 3. **混合扩展**:同时进行位扩展和字扩展 ## 实验设备 - 单片机开发板(如STC89C52) - 存储芯片(如27C256、29C040等) - 逻辑门电路芯片(如74HC138、74HC373等) - 示波器、万用表等测试设备 - 连接线若干 ## 实验步骤 ### 1. 单芯片汉字存储实验 1. 连接27C256 EPROM芯片到单片机系统 2. 将16×16点阵汉字字库写入芯片 3. 编写程序读取并显示汉字 ### 2. 存储芯片字扩展实验 1. 使用地址译码器(如74HC138)扩展多片27C256 2. 将完整GB2312字库分布到各芯片中 3. 编写程序实现跨芯片汉字读取 ### 3. 存储芯片位扩展实验 1. 连接两片27C256实现16位数据总线扩展 2. 优化字库存储结构,提高读取速度 3. 测试并比较扩展前后的性能差异 ## 实验代码示例(单片机部分) ```c #include <reg52.h> #include <intrins.h> // 定义存储芯片控制引脚 sbit CE = P2^7; // 片选 sbit OE = P2^6; // 输出使能 sbit
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值