首页 > 其他分享 >[AtCoder] E - Putting Candies

[AtCoder] E - Putting Candies

时间:2024-08-16 08:58:16浏览次数:7  
标签:operations AtCoder adding Candies pick 2nd Putting time before

Problem Link

If we pick A[i] the 2nd time, it means we have a cycle.

Proof:

1st time we pick A[i], the sum before adding A[i] is x; 2nd time we pick A[i], the sum before adding A[i] is y;  For this to happen x % N == y % N must hold. Otherwise we would not arrive at index i again. 

x -> x + A[i]

y -> y + A[i]

(x + A[i]) % N == (y + A[i]) % N. This means we'll repeat the same set of picks in order indefinitely until we run out of operations. 

 

By pigeon hole principle, we'll have a cycle after at most N operations. 

 

The final answer can be constructed accordingly using the above information. 

 

标签:operations,AtCoder,adding,Candies,pick,2nd,Putting,time,before
From: https://www.cnblogs.com/lz87/p/18362165

相关文章

  • 题解:AT_abc365_d [ABC365D] AtCoder Janken 3
    D-AtCoderJanken3题解题意:高桥和青木要玩石头剪刀布,给你一个长度为\(n\)的字符串\(s\),\(s\)表示青木在第\(i\)局游戏中的动作(R表示石头,P表示布,S表示剪刀。)。高桥不可以在任何一局中输给青木(即:高桥和青木只可以平局或高桥赢青木),且高桥第\(i\)局出的和第\(i-1\)局......
  • 题解:AtCoder Janken 3
    D-AtCoderJanken3题解题意高桥和青木要玩石头剪刀布,给你一个长度为\(n\)的字符串\(s\),\(s\)表示青木在第\(i\)局游戏中的动作(R表示石头,P表示布,S表示剪刀)。高桥不可以在任何一局中输给青木(即:高桥和青木只可以平局或高桥赢青木),且高桥第\(i\)局出的和第\(i-1\)局......
  • AtCoder Beginner Contest 044
    A-TakandHotels(ABCEdit)#include<bits/stdc++.h>usingnamespacestd;usingi64=longlong;intmain(){ ios::sync_with_stdio(false),cin.tie(nullptr); intn,k,x,y; cin>>n>>k>>x>>y; intans=0; if......
  • Solution - Atcoder ARC171D Rolling Hash
    对于这个\(\operatorname{hash}(A_L,\cdots,A_R)\),一个比较经典的想法是做差分,即令\(s_i=\sum\limits_{j=1}^iA_jB^{i-j}\)。于是\(\operatorname{hash}(A_L,\cdots,A_R)=s_R-s_{L-1}\timesB^{R-L+1}\not=0\)。那么也就是\(s_R\not=s_{L-1}\ti......
  • Solution - Atcoder ABC155F Perils in Parallel
    首先可以按\(a_i\)排序,对于区间\([l_i,r_i]\)可以通过二分确定实际影响到的\(b_i\)的区间。考虑到区间\(i\in[l,r]\)的\(b_i\)都取反影响到的元素过多,考虑去减少影响到的元素。于是可以想到令\(c_i=b_i\oplusb_{i-1}\),那么对于区间\([l,r]\)操作实际影响......
  • Atcoder nomura2020F Sorting Game
    首先考虑如果固定了\(a\),如何判定这个\(a\)是否能被排序。如果存在\(a_i>a_j(i<j)\),那么\(a_i\)肯定要交换到\(a_j\)后面,那么就肯定会交换\(a_i,a_j\)。于是合法条件就是如果存在\(a_i>a_j(i<j)\),那么\(a_i,a_j\)只相差一个二进制位。那就还能知道此时一......
  • AtCoder Regular Contest 041 D 辺彩色
    洛谷传送门AtCoder传送门比较有意思的小清新题。第一步是时光倒流,看成是每次经过一条未被访问过的边才染色。奇偶相关容易想到二分图。发现若有一个黑白交替的奇环(即从一个点开始遍历完整个环得到的颜色序列是黑白交替地),那我们可以先染完这个环。又因为它是奇环,所以我们遍历......
  • AtCoder ABC 366题解
    前言本文部分思路来自于网络,仅供参考。A-Election2题目大意给定两个市长候选人的票数,求结果是否已经确定。解题思路如果剩下的人全部投票给票少的人票少的人也不能赢,则结果就已经确定了。code#include<bits/stdc++.h>usingnamespacestd;intmain(){intn,t,......
  • AtCoder Beginner Contest 366
    A-Election2(abc366A)题目大意\(n\)张票,目前投了\(t\)给高桥,\(a\)给青木。问剩余票随便分配,是否都是一个结局。解题思路考虑最好情况,即剩下票全部投给当前票少的,看看能不能超过对方,会则结局会变,否则不会变。神奇的代码#include<bits/stdc++.h>usingnamespaces......
  • AtCoder Beginner Contest 366 C,D题解
    C-BallsandBagQuery题解题意没什么好说的,给出q次查询,进行求解思路很简单的一道题,但这篇题解的作用是引出unordered_set,这个东西的作用类似set,但没有排序,相当于哈希。unordered_set有几种操作,接下来介绍三种insert,没什么可说的,普通的插入erase,进行弹出size,返回大......