[POJ 2356] Find a multiple
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 6535 | Accepted: 2849 | 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<cstdlib>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define N 10010 struct Node
{
int x,y,s; //下标,余数,前缀和
bool operator <(const Node &t)const
{
if(y!=t.y) return y<t.y;
return x<t.x;
}
}p[N]; int main()
{
int n;
int flag;
int a[N];
while(scanf("%d",&n)!=EOF)
{
flag=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
p[i].s=p[i-].s+a[i];
p[i].x=i;
p[i].y=p[i].s%n;
if(!flag && p[i].y==)
{
flag=;
printf("%d\n",i);
for(int j=;j<=i;j++) printf("%d\n",a[j]);
}
}
if(flag) continue;
sort(p+,p+n+);
for(int i=;i<=n;i++)
{
if(p[i].y==p[i-].y)
{
int &l=p[i-].x;
int &r=p[i].x;
printf("%d\n",r-l);
for(int j=l+;j<=r;j++) printf("%d\n",a[j]);
break;
}
}
}
return ;
}
[POJ 2356] Find a multiple的更多相关文章
- 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 Find a multiple(鸽巢原理)
Description The input contains N natural (i.e. positive integer) numbers ( N <= ). Each of that n ...
- poj 2356 Find a multiple【鸽巢原理 模板应用】
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6651 Accepted: 2910 ...
- POJ 2356 Find a multiple( 鸽巢定理简单题 )
链接:传送门 题意:题意与3370类似 注意:注意输出就ok,输出的是集合的值不是集合下标 /***************************************************** ...
- 广搜+打表 POJ 1426 Find The Multiple
POJ 1426 Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25734 Ac ...
- POJ 1426 Find The Multiple --- BFS || DFS
POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至 ...
- POJ 1426 Find The Multiple(寻找倍数)
POJ 1426 Find The Multiple(寻找倍数) Time Limit: 1000MS Memory Limit: 65536K Description - 题目描述 Given ...
- POJ.1426 Find The Multiple (BFS)
POJ.1426 Find The Multiple (BFS) 题意分析 给出一个数字n,求出一个由01组成的十进制数,并且是n的倍数. 思路就是从1开始,枚举下一位,因为下一位只能是0或1,故这个 ...
随机推荐
- TDBAdvGrid 只读状态下复制功能
DataSource1.AutoEdit := false;
- spark 1.3.0下的问题
1.在spark SQL的一个test中 无论是registerAsTable还是registerTempTable 都会有问题,经过查找各种资料,采用如下的方式: val sqlCon=new or ...
- Linux分类笔记(一)-权限管理
Linux分类笔记(一) 权限管理 普通权限 文件的普通权限 对一个普通的文件使用ls -ll命令后,看到下面的输出内容 而对于文件权限中的每一位,又分别代表了以下的意思 文件类型又有以下几类: ...
- DB2 SQL 递归实现多行合并
最终效果 原始数据: 转换脚本: WITH post_a AS ( SELECT DISTINCT T.EMP_NO,S.CODE_ FROM inscndb.DTFMA000_EMP_POST T ...
- android include中的控件调用
项目中经常会有一些布局是重用的,但是如何来更好的利用这些布局中的控件 转: http://zhidao.baidu.com/link?url=GU93U8Wu31dfp7mKEx52hMJkxjFLC ...
- 配置node与express初试
http://www.nodejs.org/下载对应系统的node版本并安装 用npm包管理器安装需要的包 sudo npm install -g express sudo npm install - ...
- jQuery ajax 实现分页 kkpager插件
代码片段一: <!--分页组件 JS CSS 开始--> <!--分页组件 CSS--> <link type="text/css" href=&qu ...
- 区间型动规--石子归并(Pascal)
题目描述 Description 有n堆石子排成一列,每堆石子有一个重量w[i], 每次合并可以合并相邻的两堆石子,一次合并的代价为两堆石子的重量和w[i]+w[i+1].问安排怎样的合并顺序,能够使 ...
- To change the sharepoint CA port
Set-SPCentralAdministration -Port <port number> to fix the error: Got this error: Failed to re ...
- 获取不变的UDID-b
iOS唯一标识的历史历程 iOS 6.0 在iOS6.0以前,是使用uniqueIdentifier来获取手机的唯一标识,后来苹果感觉这样会泄露用户隐藏,就封掉了这个方法: iOS 6.0系统新增了两 ...