这道题是道数论题,如果想对了的话会很快。

因为这道题实在是没有什么知识点,所以我直接上代码,代码上有很详细的注释:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[]={},t; //a为桶排序数组
int main(){
std::ios::sync_with_stdio();//读入输出加速
cin>>t;//测试数据的个数
while(t--){
long long k,n; //k为模,n为数列的长度
cin>>k>>n; //输入
memset(a,,sizeof(a)); //清空a数组
long long sum=; //sum表示前缀和的累加mod K的结果
long long x;//x表示当前输入的数
long long ans=; //ans表示结果
for(int i=;i<=n;i++){ //循环表示当前读到的数列元素的位置
cin>>x; //输入该元素x
sum=(sum+x)%k; //累计前缀和并覆盖sum
a[sum%k]++; //桶排序,表示有多少同余的数
}
for(int i=;i<k;i++){ //循环访问排序结果
ans+=a[i]*(a[i]-)/;// 如果这个余数i有很多个情况,因为里面保存的是1-?的和mod k。
//a[i]中任意两个相减都代表前缀和相减,代表的是一个1-n的子区间,例如:1,2,3,4,因为必须上一个区间比减去的区间大才可以
//进行相减操作所以只能从1开始减2,3,4.从2开始减3,4.类似地计算这类排列的情况为:n*(n-1)/2
//这样的话可以计算出来合法的子序列的方案和。
}
cout<<ans<<endl;//加上本来余数就是零的序列
}
}

2644. 数列 (Standard IO)的更多相关文章

  1. 1001. 温度转换 (Standard IO)

    1001. 温度转换 (Standard IO) 时间限制: 1000 ms  空间限制: 262144 KB  具体限制   题目描述 将输入的华氏温度转换为摄氏温度.由华氏温度F与摄氏温度C的转换 ...

  2. JZOJ 2137. 【GDKOI2004】城市统计 (Standard IO)

    2137. [GDKOI2004]城市统计 (Standard IO) Time Limits: 1000 ms  Memory Limits: 128000 KB  Detailed Limits  ...

  3. JZOJ 5326. LCA 的统计 (Standard IO)

    5326. LCA 的统计 (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Description Input Output S ...

  4. JZOJ 5307. 【NOIP2017提高A组模拟8.18】偷窃 (Standard IO)

    5307. [NOIP2017提高A组模拟8.18]偷窃 (Standard IO) Time Limits: 1000 ms Memory Limits: 262144 KB Description ...

  5. JZOJ 5286. 【NOIP2017提高A组模拟8.16】花花的森林 (Standard IO)

    5286. [NOIP2017提高A组模拟8.16]花花的森林 (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Descript ...

  6. JZOJ 5305. 【NOIP2017提高A组模拟8.18】C (Standard IO)

    5305. [NOIP2017提高A组模拟8.18]C (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Description ...

  7. JZOJ 5257. 小X的佛光 (Standard IO)

    5257. 小X的佛光 (Standard IO) Time Limits: 2000 ms Memory Limits: 524288 KB Description Input Output Sam ...

  8. JZOJ 5258. 友好数对 (Standard IO)

    5258. 友好数对 (Standard IO) Time Limits: 1000 ms Memory Limits: 524288 KB Detailed Limits Description I ...

  9. JZOJ 1349. 最大公约数 (Standard IO)

    1349. 最大公约数 (Standard IO) Time Limits: 1000 ms Memory Limits: 65536 KB Description 小菜的妹妹小诗就要读小学了!正所谓 ...

随机推荐

  1. HTML5基本标签<搬运>

    HTML语言基本标签: 创建一个HTML文档<html></html> 设置文档标题以及其他不在WEB网页上显示的信息<head></head> 设置文 ...

  2. CentOS 安装开发工具包

    这里使用组安装包,一次性安装所有开发者工具. 1.查看有那些组安装包可用. [root@bogon ~]# yum grouplist | more 2.搜索一下有哪些和 Development 有关 ...

  3. 【xinsir】githook之precommit分享

    钩子类型 使用node编写githook,以pre-commit为例: 1.在项目下配置自动生成pre-commit文件,一般可以在启动项目的脚本下添加: modifyPreCommit: funct ...

  4. 洛谷 P1168 中位数(优先队列)

    题目链接 https://www.luogu.org/problemnew/show/P1168 解题思路 这个题就是求中位数,但是暴力会tle,所以我们用一种O(nlogn)的算法来实现. 这里用到 ...

  5. 模板引擎( art-template)

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8& ...

  6. UIGestureRecognizer 手势

    - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.v ...

  7. C# 对象转JSON字符串

    对象转JSON字符串 /// <summary> /// 对象转Json字符串 /// </summary> /// <param name="obj" ...

  8. 一、AJAX

    一. (function ($) { //1.得到$.ajax的对象 var _ajax = $.ajax; $.ajax = function (options) { //2.每次调用发送ajax请 ...

  9. python数字图像处理(三)边缘检测常用算子

    在该文将介绍基本的几种应用于边缘检测的滤波器,首先我们读入saber用来做为示例的图像 #读入图像代码,在此之前应当引入必要的opencv matplotlib numpy saber = cv2.i ...

  10. .net core 操作oracle

    依赖项——右键——管理NuGet程序包——浏览——输入以下内容 oracle.ManagedDataAccess.core(记得勾选包括预发行版) 在页面中加入操作数据库的方法 public IAct ...