目录
4482. 分组
思路:
找到每个数的最大次数,该数据中的最大次数就是最大分组数
代码如下:
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(false),cin.tie(0), cout.tie(0)
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 2e5 + 10, mod = 1e9 + 7;
int n;
int st[N];
int main()
{
//fast;
//cin >> T;
scanf("%d", &n);
int x = 0, mx = 0;
for(int i = 0; i < n; i ++ )
scanf("%d", &x), st[x] ++, mx = max(mx, st[x]);
printf("%d\n", mx);
return 0;
}
4483. 格斗场
思路:设置原数组的元素数组和该元素的数量数组,降序排列元素组,离散化为原数组。
明确几点:
1)存在比本数大的数且符合题目规则,则本数的数量清零。
2)想要存最小的数量,即将所有可以删去的元素都删去。即、将每个数的可以删去的数都删去,即判断该数之后的 K 范围的数,可以简化为判断每相邻的两个数是否可以删去。
代码如下:
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(false),cin.tie(0), cout.tie(0)
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e6 + 10, mod = 1e9 + 7;
int n, k;
int st[N];
int b[N];
int main()
{
//fast;
//cin >> T;
scanf("%d %d", &n, &k);
vector<int> a(n);
int x = 0, res = 0;
for(int i = 0; i < n; i ++ )
scanf("%d", &a[i]), st[a[i]] ++;
sort(a.begin(), a.end(), greater<int>());
a.erase(unique(a.begin(), a.end()), a.end());
res += st[a[0]];
int t = a[0];
for(int i = 1; i < a.size(); i ++ )
{
if(a[i-1] - a[i] <= k) st[a[i]] = 0;
}
int cnt = 0;
for(int i = 0; i < a.size(); i ++ )
{
if(st[a[i]]) b[cnt++] = a[i];
}
for(int i = 1; i < cnt; i ++ )
{
if(t - b[i] > k)
{
t = b[i], res += st[b[i]];
}
}
printf("%d\n", res);
return 0;
}
4484. 有限小数
思路:判断有限小数,即判断小数部分的b次方是否可以被,即判断 p/q*b^n是否为整数,即判断b^n/q是否为整数,将q中的与b的公因数除净,然后判断q是否为1 , 为1 代表可以整除,反之无法整除
代码如下:
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(false),cin.tie(0), cout.tie(0)
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e6 + 10, mod = 1e9 + 7;
int n;
LL p, q, b;
LL gcd(LL a, LL b)
{
return b ? gcd(b, a % b) : a;
}
int main()
{
//fast;
//cin >> T;
scanf("%d", &n);
while(n -- )
{
scanf("%lld %lld %lld", &p, &q, &b);
LL d = gcd(p, q);
q /= d;
while(q > 1)
{
LL t = gcd(q, b);
if(t == 1) break;
while(q % t == 0) q /= t;
}
if(q == 1) puts("YES");
else puts("NO");
}
return 0;
}