[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 ...
随机推荐
- composer 依赖的require安装与remove删除命令
安装:require composer require phpmailer/phpmailer 删除:remove composer remove phpmailer/phpmailer
- 36 (OC)* MVC和MVVM
1:MVC (Modal View Controller)(模型 视图 控制器) 一.MVC 从字面意思来理解,MVC 即 Modal View Controller(模型 视图 控制器),是 Xe ...
- [LeetCode]Unique Binary Search TreesII
题目:Unique Binary Search TreesII 如果要列出所有可能的二叉搜索树,可以在上面的思路上进一步. f(n) = f(0)*f(n-1) + f(1)*f(n-2) + ... ...
- 第六届蓝桥杯java b组第二题
立方变自身 观察下面的现象,某个数字的立方,按位累加仍然等于自身. 1^3 = 1 8^3 = 512 5+1+2=8 17^3 = 4913 4+9+1+3=17 … 请你计算包括1,8,17在内, ...
- wpf 使用矢量字体 fontawesome
第一步:首先下载矢量字体 :http://www.fontawesome.com.cn/ 第二步:在将fontawesome-webfont.ttf 文件引用到项目 设置fontawesome-web ...
- logcat粗略了解(一)
Logcat Logcat介绍:logcat是android的一个命令行工具,用于的到程序的log信息 Logcat命令格式: [adb] logcat [<option>]…[<f ...
- Vsftp服务-实战案例
Vsftp 实验案例一:(本地用户) 试验版本:Linux7.X版本 公司内部现在有一台FTP 和WEB 服务器,FTP 的功能主要用于维护公司的网站内容,包括上传文 件.创建目录.更新网页等等.公司 ...
- Java之字符流读写文件、文件的拷贝
字符流读数据 – 按单个字符读取 创建字符流读文件对象: Reader reader = new FileReader("readme.txt"); 调用方法读取数据: int d ...
- 2017春季_京东_Java后端研发岗面经
纸上得来终觉浅,绝知此事要躬行 ——2017春季Java后端研发工程师面试心得 收获offer:上海汉得+北京中科软+成都百词斩+成都诺基亚研发中心+清华大学计算机研究所等offer.阿里一面猝.京 ...
- 【HIVE】各种时间格式处理
yyyy-MM-dd与yyyyMMdd000000转换的三种方法 方法一:date_format(只支持yyyy-MM-dd -> yyyyMMdd000000) select date_for ...