[POJ2356] Find a multiple 鸽巢原理
| Time Limit: 1000MS | Memory Limit: 65536K | |||
| Total Submissions: 8776 | Accepted: 3791 | Special Judge | ||
Description
Input
Output
If there are more than one set of numbers with required properties
you should print to the output only one (preferably your favorite) of
them.
Sample Input
5
1
2
3
4
1
Sample Output
2
2
3
Source
#include <iostream>
#include <cstdio>
#include <map>
using namespace std; int n;
int a[];
int qzh[];
map <int, int> mp; int main()
{
scanf("%d", &n);
for (register int i = ; i <= n ; i ++) scanf("%d", a + i);
for (register int i = ; i <= n ; i ++)
{
qzh[i] = qzh[i-] + a[i];
if (qzh[i] % n == )
{
cout << i << endl;
for (register int j = ; j <= i ; j ++) printf("%d\n", a[j]);
return ;
}
if (mp[qzh[i]%n]!= )
{
cout << i - mp[qzh[i]%n] << endl;
for (register int j = mp[qzh[i]%n] + ; j <= i ; j ++)
printf("%d\n", a[j]);
break;
}
mp[qzh[i]%n] = i;
}
return ;
}
[POJ2356] Find a multiple 鸽巢原理的更多相关文章
- [poj2356]--Find a multiple ——鸽巢原理
题意: 给定n个数,从中选取m个数,使得\(\sum | n\).本题使用Special Judge. 题解: 既然使用special judge,我们可以直接构造答案. 首先构造在mod N剩余系下 ...
- [POJ2356]Find a multiple 题解(鸽巢原理)
[POJ2356]Find a multiple Description -The input contains N natural (i.e. positive integer) numbers ( ...
- poj2356 Find a multiple(抽屉原理|鸽巢原理)
/* 引用过来的 题意: 给出N个数,问其中是否存在M个数使其满足M个数的和是N的倍数,如果有多组解, 随意输出一组即可.若不存在,输出 0. 题解: 首先必须声明的一点是本题是一定是有解的.原理根据 ...
- POJ2356 Find a multiple 抽屉原理(鸽巢原理)
题意:给你N个数,从中取出任意个数的数 使得他们的和 是 N的倍数: 在鸽巢原理的介绍里面,有例题介绍:设a1,a2,a3,……am是正整数的序列,试证明至少存在正数k和l,1<=k<=l ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- poj 2356 Find a multiple(鸽巢原理)
Description The input contains N natural (i.e. positive integer) numbers ( N <= ). Each of that n ...
- poj Find a multiple【鸽巢原理】
参考:https://www.cnblogs.com/ACShiryu/archive/2011/08/09/poj2356.html 鸽巢原理??? 其实不用map但是习惯了就打的map 以下C-c ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- HDU 1005 Number Sequence【多解,暴力打表,鸽巢原理】
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
随机推荐
- Mysql优化总结(一)
一,前言 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库. MySQL 是一个关系型数据库管理系统,由瑞典 MySQL AB 公司开发,目前属于 Oracle 公司.My ...
- MyBatis 3.5.2 新特性介绍
1.MyBatis 最新版本 3.5.2 发布 MyBatis最新版本是:3.5.2,发布时间是:2019年7月15日 2.MyBatis 3.5.2 新特征介绍 我们知道,MyBatis 是支持定制 ...
- (转)在阿里云 CentOS 服务器(ECS)上搭建 nginx + mysql + php-fpm 环境
阿里云的云服务器(ECS)可以选择多种操作系统,打算用它运行 Drupal或者 WordPress ,你最好选择 Linux 系统,这篇文章的演示是基于阿里云的 CentOS 操作系统的服务器.我们在 ...
- Android Adapter的一些记录
一.摘要 An Adapter object acts as a bridge between an AdapterView and the underlying data for that view ...
- JIRA集成GitHub
原因: 作为管理员, 为用户提高效率的角度,配置测试此服务.让用户从JIRA内看到代码分支,提交信息,pull requests等等, 让Github的代码提交记录和JIRA的任务管理系统集成在一起, ...
- CDH集群的时间同步--简要配置要求
每个节点执行ntpstat 和 timedatectl 都显示同步并且时间相同,那么CDH才能正常使用.每次ntp服务同步到外部授时中心都要一段时间(5~10分钟),只有当NTP server(nod ...
- Mycat 配置文件rule.xml
rule.xml配置文件定义了我们对表进行拆分所涉及到的规则定义.我们可以灵活的对表使用不同的分片算法,或者对表使用相同的算法但具体的参数不同. 该文件里面主要有tableRule和function这 ...
- 阿里云服务器CentOS6.9安装SVN
1.安装SVN yum -y install subversion 出现Complete表明安装成功 2.创建SVN仓库目录 mkdir -p /data/svn/repositories/yyksv ...
- HTML5 相关扩展
一.与类相关的扩展 class属性的应用极其广泛,与class的相关的操作也越来越简化,HTML5增加了 getElementsByClassName来查找元素,通过也增加了classList属性,方 ...
- Python3 Linux安装(Redhat)
Python3 Linux安装(Redhat): 下载Python-3.6.4.tgz: https://www.python.org/downloads/release/python-364/ Y ...