题目来源: Ural 1302
基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题
 收藏
 关注
一个长度为N的数组A,从A中选出若干个数,使得这些数的和是N的倍数。
例如:N = 8,数组A包括:2 5 6 3 18 7 11 19,可以选2 6,因为2 + 6 = 8,是8的倍数。
 
Input
第1行:1个数N,N为数组的长度,同时也是要求的倍数。(2 <= N <= 50000)
第2 - N + 1行:数组A的元素。(0 < A[i] <= 10^9)
Output
如果没有符合条件的组合,输出No Solution。
第1行:1个数S表示你所选择的数的数量。
第2 - S + 1行:每行1个数,对应你所选择的数。
Input示例
8
2
5
6
3
18
7
11
19
Output示例
2
2
6
 #include <algorithm>
#include <cstdio> using namespace std; int n;
int num[];
int sum_mod[];
long long sum[]; int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&num[i]);
sum[i]=sum[i-]+num[i];
sum_mod[i]=sum[i]%n;
if(!sum_mod[i])
{
printf("%d\n",i);
for(int j=;j<=i;j++)
printf("%d\n",num[j]);
return ;
}
}
for(int i=;i<n;i++)
for(int j=i+;j<=n;j++)
if(sum_mod[i]==sum_mod[j])
{
printf("%d\n",j-i);
for(int k=i+;k<=j;k++)
printf("%d\n",num[k]);
return ;
}
printf("No Solution");
return ;
}

51nod——T1103 N的倍数的更多相关文章

  1. 51nod 1103 N的倍数(抽屉原理)

    1103 N的倍数 题目来源: Ural 1302 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 一个长度为N的数组A,从A中选出若干个数,使得这些数的和是N的倍 ...

  2. 51nod 1103 N的倍数 思路:抽屉原理+前缀和

    题目: 这是一道很神奇的题目,做法非常巧妙.巧妙在题目要求n个数字,而且正好要求和为n的倍数. 思路:用sum[i]表示前i个数字的和%n.得到sum[ 1-N ]共N个数字. N个数字对N取模,每个 ...

  3. 51nod 1103 N的倍数

    1103 N的倍数   一个长度为N的数组A,从A中选出若干个数,使得这些数的和是N的倍数. 例如:N = 8,数组A包括:2 5 6 3 18 7 11 19,可以选2 6,因为2 + 6 = 8, ...

  4. 51nod 1103 N的倍数 (鸽巢原理)

    1103 N的倍数 题目来源: Ural 1302 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题  收藏  关注 一个长度为N的数组A,从A中选出若干个数,使得这 ...

  5. 51Nod 1433 0和5(9的倍数理论)

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1433 思路: 数论中关于9的倍数的理论:若是一个数能被9整除,则各位数之 ...

  6. 51Nod——T 1109 01组成的N的倍数

    https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1109 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 ...

  7. 51Nod——N1284 2 3 5 7的倍数

    https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1284 基准时间限制:1 秒 空间限制:131072 KB 分值: 5  ...

  8. 51nod 1109 01组成的N的倍数

    用01 组成 N的最小倍数 这个BFS搜索就好. 类似这道:  ZOJ Problem Set - 1530 每次 要么是0 要么是1, 记入余数,和前驱. #include<bits/stdc ...

  9. 51Nod 1284 2 3 5 7的倍数 容斥原理

    1284 2 3 5 7的倍数基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 收藏 关注给出一个数N,求1至N中,有多少个数不是2 3 5 7的倍数. 例如N = 1 ...

随机推荐

  1. Spring:验证用户登录

    利用 Spring IOC 技术实现用户登录的验证机制,对用户进行登录验证. 首先利用 Spring 的自动装配模式将 User 对象注入到控制器中,然后将用户输入的用户名和密码与系统中限定的合法用户 ...

  2. Spark之Structured Streaming

    目录 Part V. Streaming Stream Processing Fundamentals Structured Streaming Basics Event-Time and State ...

  3. 机器人走迷宫(dfs)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1590 #include <stdio.h ...

  4. Windows<小白>详细笔记

    Windows 7 部署 =========================================== ========================================== ...

  5. UILabel垂直方向显示(上下的顺序显示)。

    NSString* text = @"一"; NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFont ...

  6. ubuntu 软件桌面图标创建

    sublime text 的安装目录是:/usr/local/sublimetext $cd 桌面 $vim Sublime\ Text.desktop 添加如下内容: [Desktop Entry] ...

  7. A - Infinite Sequence

    Problem description Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2,  ...

  8. Entity Framework -- 添加,删除,修改,关系依附,关系摘除,验证操作

    数据库模型 这个基本上是浓缩 Jerry Tom博客的内容,作为参考http://www.cnblogs.com/mbailing/archive/2012/07/31/2616779.html 说明 ...

  9. Java创建Excel-DEMO

    import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.Out ...

  10. Java 8 新特性终极指南

    1.前言 毫无疑问,Java 8的发布是自从Java5以来Java世界中最重大的事件,它在编译器.工具类和Java虚拟机等方面为Java语言带来的很多新特性.在本文中我们將一起关注下这些新变化,使用实 ...