luogu P3131 [USACO16JAN]子共七Subsequences Summing to Sevens 题解

该博客介绍了Luogu P3131题目的解法,这是一道关于寻找一组连续的牛(编号为整数)其编号之和能被7整除的问题。博主提供了使用前缀和思想解决此问题的方法,并强调了在实现过程中需要注意数据类型的选择,以避免分数不全的情况。
摘要由CSDN通过智能技术生成

题目描述

Farmer John’s NN cows are standing in a row, as they have a tendency to do from time to time. Each cow is labeled with a distinct integer ID number so FJ can tell them apart. FJ would like to take a photo of a contiguous group of cows but, due to a traumatic childhood incident involving the numbers 1…6 , he only wants to take a picture of a group of cows if their IDs add up to a multiple of 7.

Please help FJ determine the size of the largest group he can photograph.

给你n个数,求一个最长的区间,使得区间和能被7整除

输入输出格式

输入格式:

The first line of input contains N (1≤N≤50,000 ). The next NN

lines each contain the NN integer IDs of the cows (all are in the range

0…. 1,000,0000 ).

输出格式:

Please output the number of cows in the largest consecutive group whose IDs sum

to a multiple of 7. If no such group exists, output 0.

解法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值