Find a multiple POJ - 2356 (抽屉原理)
抽屉原理:
#include<cstdio>
#include<cstring> const int maxn = 1e5 + ;
int num[maxn], hash[maxn], sum[maxn];
int n; int main()
{
while (scanf("%d", &n) != EOF){
memset(hash, , sizeof(hash));
for (int i = ; i <= n; ++i)
scanf("%d", &num[i]); int t = , s = ;
for (int i = ; i <= n; ++i)
{
sum[i] = (sum[i - ] + num[i]) % n;
if (sum[i] == ){
t = i;
break;
}
if (hash[sum[i]] > ){
s = hash[sum[i]] + ;
t = i;
break;
}
hash[sum[i]] = i;
}
printf("%d\n", t - s + );
for (int i = s; i <= t; ++i)
printf("%d\n", num[i]);
}
}
Find a multiple POJ - 2356 (抽屉原理)的更多相关文章
- poj 2356 抽屉原理
基本原理: n+1个鸽子放到n个笼子里,至少有一个笼子里有两只及其以上的鸽子.若有n个笼子,kn+1个鸽子,至少有一个笼子里面有k+1个鸽子: 题意:给定N个数,挑出一些数,他们和和是n的整数倍: 分 ...
- Find a multiple POJ - 2356 【鸽巢原理应用】
Problem DescriptionThe input contains N natural (i.e. positive integer) numbers ( N <= 10000 ). E ...
- Find a multiple POJ - 2356 容斥原理(鸠巢原理)
1 /* 2 这道题用到了鸠巢原理又名容斥原理,我的参考链接:https://blog.csdn.net/guoyangfan_/article/details/102559097 3 4 题意: 5 ...
- Find a multiple POJ - 2356
The input contains N natural (i.e. positive integer) numbers ( N <= 10000 ). Each of that numbers ...
- Mathematics:Find a multiple(POJ 2356)
找组合 题目大意:给你N个自然数,请你求出若干个数的组合的和为N的整数倍的数 经典鸽巢原理题目,鸽巢原理的意思是,有N个物品,放在N-1个集合中,则一定存在一个集合有2个元素或以上. 这一题是说有找出 ...
- poj 2356鸽笼原理水题
关于鸽笼原理的知识看我写的另一篇博客 http://blog.csdn.net/u011026968/article/details/11564841 (需要说明的是,我写的代码在有答案时就输出结果了 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2356 Find a multiple 抽屉原理
从POJ 2356来体会抽屉原理的妙用= =! 题意: 给你一个n,然后给你n个数,让你输出一个数或者多个数,让这些数的和能够组成n: 先输出一个数,代表有多少个数的和,然后再输出这些数: 题解: 首 ...
- poj 2356 (抽屉原理)
题目链接:http://poj.org/problem?id=2356 题目大意:给你n个数,要你从n个数选出若干个数,要求这若干个数的和是n的倍数,输出选择数的个数,以及相应的数. 解题思路: 以下 ...
随机推荐
- JS 上传图片 + 预览功能(一)
JS 上传图片 + 预览功能 <body> <input type="file" id="fileimg1" style="disp ...
- 菜鸟入门【ASP.NET Core】9:RoutingMiddleware介绍以及MVC引入
前言 前面介绍了使用app.Map来配置路由,但是对于一般不是特别大的项目来说,不使用Map来进行路由配置. 配置路由 我们首先需要在Startup.cs文件中的ConfigureServices方法 ...
- 【Mybatis】一对一实例
①创建数据库和表,数据库为mytest,表为father和child DROP TABLE IF EXISTS child; DROP TABLE IF EXISTS father; CREATE T ...
- mysql远程连接 Host * is not allowed to connect to this MySQL server(第一次配置好lnmp环境)
1.第一次在linux上搭建好mysql,本机windows远程链接报错Host * is not allowed to connect to this MySQL server 2.原因:mysql ...
- Linux 磁盘使用查看 查看使用磁盘程序 Monitoring disk activity in linux
5 TOOLS FOR MONITORING DISK ACTIVITY IN LINUX Here is a quick overview of 5 command-line tools that ...
- Android视屏播放兼容性问题分享
最近产品提了一个紧急需求:webview加载的URL,需要支持视频播放. 为了快速完成需求,功能实现上直接使用系统自带播放器播放视频.由于是自带播放器,需要进行兼容性测试,过程发现了不少问题,这里分享 ...
- Java —— 对象
创建对象 int[] b = new int[30]; 等号右侧:创建了一个数组对象 // 等号左侧:变量 b 称为该对应的引用 // 称作 变量 b 指向了一个对象 // 有时也简称为: b ...
- C#语言————两值交换
//两值交换 public static void Show(ref int num1,ref int num2) { int num=num1; num1=num2; num2=num; } sta ...
- .net core HttpContext(Http上下文)
在.NET Core中,只有Controller才能直接使用 HttpContext ,其他地方需要通过HttpContextAccessor来访问
- inode 耗尽
背景: 之前为了提升大硬盘mkfs文件系统的速度,使用了大文件选项 mkfs.ext4 -T largefile /dev/xvde1 没有仔细算能存多少文件,结果今天发现磁盘没用完,但inode用完 ...