POJ 3370 Halloween treats(抽屉原理)

QT播放器插件内嵌浏览器配合流媒体实现国标摄像头网页端播放 基本原理在浏览器⽹页中的指定播放窗口的位置和⼤⼩,实现⼀个内嵌到⽹页中显⽰的播放窗⼝,前端还必须可对这个内嵌播放窗⼝进⾏控制,⽽且播放窗⼝必须跟随浏览器窗⼝的移动和缩放、⽹页滚动、标签页切换、关闭等操作进⾏⾃动联动。播放器可以通过QT实现。这个播放窗⼝同时提供Web Socket的服务端和JSON打包命令的解析执⾏模块,前端就可以通过Web Socket连接后发送JSON打包的控制命令实现控制播放窗⼝。 阅读详情

Halloween treats
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 6631 Accepted: 2448 Special Judge

Description

Every year there is the same problem at Halloween: Each neighbour is only willing to give a certain total number of sweets on that day, no matter how many children call on him, so it may happen that a child will get nothing if it is too late. To avoid conflicts, the children have decided they will put all sweets together and then divide them evenly among themselves. From last year's experience of Halloween they know how many sweets they get from each neighbour. Since they care more about justice than about the number of sweets they get, they want to select a subset of the neighbours to visit, so that in sharing every child receives the same number of sweets. They will not be satisfied if they have any sweets left which cannot be divided.

Your job is to help the children and present a solution.

Input

The input contains several test cases.
The first line of each test case contains two integers c and n (1 ≤ c ≤ n ≤ 100000), the number of children and the number of neighbours, respectively. The next line contains n space separated integers a1 , ... , an (1 ≤ ai ≤ 100000 ), where ai represents the number of sweets the children get if they visit neighbour i.

The last test case is followed by two zeros.

Output

For each test case output one line with the indices of the neighbours the children should select (here, index i corresponds to neighbour i who gives a total number of ai sweets). If there is no solution where each child gets at least one sweet print "no sweets" instead. Note that if there are several solutions where each child gets at least one sweet, you may print any of them.

Sample Input

4 5
1 2 3 7 5
3 6
7 11 2 5 13 17
0 0

Sample Output

3 5
2 3 4

Source




题意:给出c和n,接下来n个数,求任意的几个数的和为c的倍数,输出任意一组答案(注意是任意的)


抽屉原理: 放10个苹果到九个抽屉,最少有一个抽屉有大于1的苹果


这个题为什么说是抽屉原理呢?  你计算前n个数(一共有n个和)的和mod  c ,因为n大于c,所以你猜测会有多少个余数,

最多有 n个,即 0~n-1,而0是满足条件的,换而言之,这n个余数中要么有0,要么最少有两个相同的余数,

现在看两个余数相同的情况,例如   假设sum[1]%c==sum[n]%c  那么a[2]+a[3]+..+a[n]就是 c  的倍数,就说这么多了,

看代码吧:






#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 100005

int a[N];
int vis[N];
int c,n;

int main()
{
    int i;
    while(~scanf("%d%d",&c,&n))
    {
        memset(vis,-1,sizeof(vis));

        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }

        int temp=0,j;


        for(i=1;i<=n;i++)
        {
            temp+=a[i];
            temp%=c;

            if(temp==0)
            {
                for(j=1;j<=i;j++)
                    if(j==1)
                       printf("%d",j);
                    else
                       printf(" %d",j);

               printf("\n");
                break;
            }

            if(vis[temp]!=-1)
            {

                for(j=vis[temp]+1;j<=i;j++)
                  if(i==j)
                      printf("%d",j);
                   else
                      printf("%d ",j);

                      printf("\n");

              break;
            }

            vis[temp]=i;
        }

    }
    return 0;
}





基于FPGA的多通道音频信号采样系统设计 FPGA是随着数字集成电路的发展而逐步演变而来的。从早期的电子管、晶体管、小规模集成电路,到超大规模集成电路(VLSIC),数字集成电路的集成度和性能不断提升。FPGA的出现为系统设计师提供了灵活的设计平台,使其能够在不依赖半导体厂商的情况下快速设计专用集成电路(ASIC)。FPGA具有设计周期短、成本低、开发工具先进等优点,广泛应用于原型设计和产品生产中。VHDL是一种用于描述数字系统的硬件描述语言,其语言形式类似于计算机高级语言,但包含了许多硬件特征语句。 阅读详情

相关推荐

从零到一:如何用YOLOv8和PyQt5打造你的第一个花卉识别桌面应用

本文详细介绍了如何使用YOLOv8和PyQt5从零开始构建一个花卉识别桌面应用。涵盖环境搭建、数据准备、模型训练、界面设计、模型集成与性能优化等全流程,帮助开发者快速掌握深度学习目标识别技术的实际应用。

weixin_29048775的博客 452

poj 3370 Halloween treats(抽屉原理)

【题目大意】:给出n个数,叫你从中选出任意个数,使得这些数的和是c的倍数。 【解题思路】:下午这道题被拿去当了选拔赛的题目。做的时候总觉得貌似在哪里见过,然后再那里没事%c搞啊搞啊,越搞越觉得像抽屉原理。。。。。然后,没错,就是你了。。。抽屉原理。 【抽屉原理】:原理1 把多于n个的物体放到n个抽屉里,则至少有一个抽屉里的东西不少于两件;

Wu is so Water 1749

用R语言实现“中断时间序列分析” --- R code for ITS

ITS方法可用于评估一项干预措施的效果,从水平改变和斜率改变两个角度来描述干预引起的变化。

franksui的博客 4026

POJ 3370 Halloween treats【抽屉原理】

题目链接:http://poj.org/problem?id=3370 Description Every year there is the same problem at Halloween: Each neighbour is only willing to give a certain total number of sweets on that day, no matt...

dianxuanzhi1019的博客 206

浅谈车联网概述-1

车联网技术目前在车企中应用广泛,车联网通过车载传感器、无线通信等技术,能够将车辆上百的传感器数据上传至云端,当前智能网联车辆可以理解为一个“大号”手机。

Hello, World! 新能源汽车智能网联工程师,分享日常工作思考。 559

SAP PP CSAP_MAT_BOM_MAINTAIN ECN 增加组件

SAP PP CSAP_MAT_BOM_MAINTAIN ECN 增加组件。

GAVIN 408

poj3370Halloween treats【抽屉原理】

Language: Default Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7616   Accepted: 2783   Special Judge Description Every year there i

走一步再走一步 595

Altair HyperWorks 2022.3.0 Suite下载

Altair HyperWorks开发团队提供了新的一流技术,以设计和优化高性能、高效和创新的产品,并发布了HyperWorks 2021.2套件。与所有新版本一样,这个版本包含了新特性、增强功能,并修复了前一个版本中用户报告的各种问题,提供了总体上更稳定的体验。链接: https://pan.baidu.com/s/1rYietmQLQUboHiJzYoE9WQ?pwd=m9yh 提取码: m9yh 复制这段内容后打开百度网盘手机App,操作更方便哦。

weixin_48469365的博客 2126

poj 3370 Halloween treats 【抽屉原理】

Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7171   Accepted: 2649   Special Judge Description Every year there is the same problem at

世界很大 623

基于Simulink的间接功率控制的矩阵变换器

通过上述步骤,我们成功设计并实现了基于 Simulink 的间接功率控制的矩阵变换器仿真模型。该模型能够通过控制输入电流和输出电压,实现对功率的间接控制,适用于电机驱动、可再生能源系统、电力传输等领域。通过虚拟场景仿真、参数优化和性能评估,验证了系统的稳定性和高效性,并通过调整 PI 控制器参数和优化调制算法,进一步提升了系统的性能。

MHD0815的博客 295

2024年电气工程师最新面试题及答案

1. **基本电气工程原理**:包括电流、电压、电阻、功率等基本概念。2. **欧姆定律**:V = IR,描述电压、电流和电阻之间的关系。42. **风力发电系统组成**:包括风力涡轮机、发电机、控制系统等。44. **智能电网技术**:包括自动化控制、通信技术、数据分析等。10. **减少EMI**:使用屏蔽、滤波、合理布线等方法。40. **光伏系统组成**:包括光伏板、逆变器、控制器等。48. **能量存储技术**:包括电池、超级电容器、飞轮等。

guo162308的博客 6561

POJ 3370 Halloween treats(抽屉原理,前缀和)

抽屉原理 题目意思: n个数任取若干个, 这些数的和是c的倍数, 输出其中的任意一种取法,输出元素的下标即可 本题要点: 1、抽屉原理 有n+1件或n+1件以上的物品要放到n个抽屉中,那么至少有一个抽屉里有两个或两个以上物品。 2、一个结论 a1,a2,a3…am是正整数序列,至少存在整数k和r,1<=k<r<=m,使得ak+a(k+1)+…+a®是m的倍数。 3、具体步骤 用sum来记录数组a的前缀和, a) 如果某个 sum[i] % c == 0, 说明 sum[i] = a[1]

qq_38232157的博客 215

逆向分析-SeparationPreview.aip-分色预览-结构分析(一)-x64dbg条件日志打印-命令表达式-PS脚本

从功能上分析,仅显示使用的专色这个功能,并没有触发插件接口。使用X64dbg加载illustrator进程,切换到句柄窗口,在窗口过程中,右键刷新获取界面。在x64dbg中,在UI中可以输入一些条件表达式,能够计算出对应的值,并打印在日志中。常用的,如果非暂停,输出第一个参数。参数二是utf16的指针,utf16@字符串地址,这里的字符串地址为[[ebp-108]]参数一是utf8的,utf8@字符串地址,这里的字符串地址为[ebp-28]从界面上分析,一个颜色列表,及仅显示专色的多选框组成。

插件开发 643

POJ 3370 Halloween treats(抽屉原理)

题意  有c个小孩 n个大人万圣节搞活动  当小孩进入第i个大人家里时   这个大人就会给小孩a[i]个糖果  求小孩去哪几个大人家可以保证得到的糖果总数是小孩数c的整数倍  多种方案满足输出任意一种 用s[i]表示前i个打人给糖果数的总和  令s[0]=0  那么s[i]共有n+1种不同值  而s[i]%c最多有c种不同值  题目说了c 这就是抽屉原理了   n个抽屉放大于n个苹果

Good morning,good afternoon and good night 1174

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

POJ 3370 Halloween treats 抽屉原理

Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9361   Accepted: 3348   Special Judge Description Every year the...

pxlsdz的博客 439

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

Halloween treats (POJ-3370)(抽屉原理)

Every year there is the same problem at Halloween: Each neighbour is only willing to give a certain total number of sweets on that day, no matter how many children call on him, so it may happen that a...

菜鸡的博客 409

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

poj3370Halloween treats抽屉原理

链接 简单的说就是已知c,n和n个无序数字,要求这n个数中那些的和能被c整除== 联想到课件给的 例题: POJ 2356 题意: 给定n个数,求其中的任意一个非空子集满足集合中的每个元素值加和正好是n的倍数 。 分析: 把前缀和统计出来对n取模,任意两个相等的sum [i], sum [j] ,[i ,j ]内的数的和都满足这个条件。 n个数对n取模,范围为[0~n-1]

MissZhou要努力 534

Poj 3370 Halloween treats -抽屉原理

题目链接:This is the link   Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9370   Accepted: 3351   Special Judge Desc...

Source_Roc 198

【POJ】3370 - Halloween treats(抽屉原理 & STL)

点击打开题目 Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7919   Accepted: 2887   Special Judge Description Every year there is the

wyg1997 671

POJ-3370 Halloween treats (抽屉原理)

Every year there is the same problem at Halloween: Each neighbour is only willing to give a certain total number of sweets on that day, no matter how many children call on him, so it may happen that a

Eiffel的博客 465
上一篇: POJ 3187 Backward Digit Sums(dfs)
下一篇: POJ3083 Children of the Candy Corn dfs+bfs
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值