首页 > 其他分享 >cf 题解

cf 题解

时间:2023-07-23 14:55:05浏览次数:29  
标签:10 Slavic frogs 题解 cf trap test Mihai

Mihai and Slavic were looking at a group of $n$ frogs, numbered from $1$ to $n$, all initially located at point $0$. Frog $i$ has a hop length of $a_i$.

Each second, frog $i$ hops $a_i$ units forward. Before any frogs start hopping, Slavic and Mihai can place exactly one trap in a coordinate in order to catch all frogs that will ever pass through the corresponding coordinate.

However, the children can't go far away from their home so they can only place a trap in the first $n$ points (that is, in a point with a coordinate between $1$ and $n$) and the children can't place a trap in point $0$ since they are scared of frogs.

Can you help Slavic and Mihai find out what is the maximum number of frogs they can catch using a trap?

Input

Input

The first line of the input contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer $n$ ($1 \leq n \leq 2 \cdot 10^5$) — the number of frogs, which equals the distance Slavic and Mihai can travel to place a trap.

The second line of each test case contains $n$ integers $a_1, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the lengths of the hops of the corresponding frogs.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

Output

Output

For each test case output a single integer — the maximum number of frogs Slavic and Mihai can catch using a trap.

Example

input

7
5
1 2 3 4 5
3
2 2 2
6
3 1 3 4 9 10
9
1 3 2 4 2 3 7 8 5
1
10
8
7 11 6 8 12 4 4 8
10
9 11 9 12 1 7 2 5 8 10

output

3
3
3
5
0
4
4

Note

Note

In the first test case, the frogs will hop as follows:

  • Frog 1: $0 \to 1 \to 2 \to 3 \to \mathbf{\color{red}{4}} \to \cdots$
  • Frog 2: $0 \to 2 \to \mathbf{\color{red}{4}} \to 6 \to 8 \to \cdots$
  • Frog 3: $0 \to 3 \to 6 \to 9 \to 12 \to \cdots$
  • Frog 4: $0 \to \mathbf{\color{red}{4}} \to 8 \to 12 \to 16 \to \cdots$
  • Frog 5: $0 \to 5 \to 10 \to 15 \to 20 \to \cdots$

Therefore, if Slavic and Mihai put a trap at coordinate $4$, they can catch three frogs: frogs 1, 2, and 4. It can be proven that they can't catch any more frogs.

In the second test case, Slavic and Mihai can put a trap at coordinate $2$ and catch all three frogs instantly.

AC

#include <bits/stdc++.h>
using namespace std;
 
typedef  long long ll;
 
const int N = 200010;
 
int n, m, c, k, a, b;
int s[N], f[N];
 
void solve()
{ 
    cin>>n;
    for(int i=0; i<=n; i++) f[i]=0;
    for(int i=1; i<100; i++) s[i]=0;
    for(int i=0; i<n; i++) 
    {
        int x; cin>>x;
        if(x<100) s[x]++;
        else 
            for(int j=1; j*x<=n; j++)
                f[j*x]++;
    }
    
    int ans=0;
    for(int i=1; i<=n; i++)
    {
        int res=f[i];
        for(int k=1; k<100; k++)
        {
            if(i%k==0) res+=s[k];
        }
        ans=max(ans, res);
    }
        
    cout<<ans<<endl;
}
 
int main()
{
    int t; cin>>t;
    while(t--) solve();
    return 0;
}

标签:10,Slavic,frogs,题解,cf,trap,test,Mihai
From: https://www.cnblogs.com/qing9611/p/17575005.html

相关文章

  • P7074 [CSP-J2020] 方格取数 题解
    题目:题目描述设有n*m 的方格图,每个方格中都有一个整数。现有一只小熊,想从图的左上角走到右下角,每一步只能向上、向下或向右走一格,并且不能重复经过已经走过的方格,也不能走出边界。小熊会取走所有经过的方格中的整数,求它能取到的整数之和的最大值。输入格式第一行有两个整......
  • AtCoder Beginner Contest 311 A-E题解
    A-FirstABC题意给一个长度为N的仅由ABC三个字符组成的字符串S,问S中ABC三个字符第一次出现的位置的最大值。题解使用map<char,bool>判重,记录当前不同的字符串的个数cnt,当cnt等于3时,输出此时的下标+1作为答案。Code#include<bits/stdc++.h>usingnamespacestd;usingll......
  • 第二次比赛部分题解
    P7060[NWRRC2014]AlarmClock  #include<bits/stdc++.h>usingnamespacestd;intmain(){intn;cin>>n;intarr[10]={6,2,5,5,4,5,6,3,7,6};boolcheck=false;//对于时间ab:cdfor(inta=0;a<=2;a++){//a最多可以到2(因为最大为23......
  • 2023“钉耙编程”中国大学生算法设计超级联赛(2)部分题解
    2023“钉耙编程”中国大学生算法设计超级联赛(2)部分题解7.201002 BinaryNumber可以发现,每个位置最多修改两次,再多了没有意义。当k为0时,无法修改直接输出。当n为1时,看k的奇偶性,若为奇数则将其翻转输出,否则直接输出。当n不为1时:如果给定的次数k小于序列中连续0串的个数,那一定......
  • P1833 樱花 题解
    二进制拆分做法:把每一个物品根据2的多少次方拆分,因为任何数都可以转化为二进制数核心思想:把每一个物品拆成很多个,分别计算价值和所需时间,再转化为01背包求解最后一点:完全背包可以把他的空间记为999999,不要太大,一般百万就足够了还有一点:cin和scanf不可以混用代码#include<bit......
  • [解题报告][CF1007E]Mini Metro
    Statement传送门有\(n\)个车站,从\(1\)到\(n\)编号,车站\(i\)初始有\(a_i\)个人。在每个小时结束的前几分钟,车站\(i\)会新增\(b_i\)个人。玩家有无限辆容量为\(k\)的火车。玩家在每个小时的中间(也就是\(\mathrm{30min,1h30min,2h30min...}\))可以让任意......
  • P1679 神奇的四次方数 题解
    思路先枚举出\(n\)以内的4次方数然后dp.代码#include<bits/stdc++.h>#definelllonglong#defineldlongdouble#definemin(x,y)(x<y?x:y)usingnamespacestd;inlinevoidread(int&x){ x=0; shortflag=1; charc=getchar(); while(c<'0'......
  • P1757 通天之分组背包 题解
    思路分组背包模版题,不多说。代码#include<bits/stdc++.h>#definelllonglong#defineldlongdoubleusingnamespacestd;inlinevoidread(int&x){ x=0; shortflag=1; charc=getchar(); while(c<'0'||c>'9'){ if(c=='-......
  • 第二次比赛出题题解
    第二次比赛题解P1138第k小整数-洛谷|计算机科学教育新生态(luogu.com.cn)主要了解set的用法,set会自动去重和排序#include<bits/stdc++.h>usingnamespacestd;signedmain(){ios::sync_with_stdio(false);cin.tie(nullptr);intn,k;cin>>......
  • P1060 [NOIP2006 普及组] 开心的金明 题解
    思路01背包模版题,唯一不同的是加了一个条件就是价格与重要度的乘积。转移方程为:dp[j]=max(dp[j],dp[j-w[i]]+w[i]*v[i]);这里加了滚动数组优化。代码#include<bits/stdc++.h>#definelllonglong#defineldlongdoubleusingnamespacestd;inlinevoidread(int&x){......