写在前边

状态及其不佳,很累很困,还好\(unrated\)了

链接:Codeforces Round #697 (Div. 3)

A. Odd Divisor

链接:A题链接

题目大意:

判断一个数是否有奇数因子。

思路

一开始挺懵的,然后自己推了一下,发现只有\(2\)的幂才不会有奇数因子,因此本题只需要判断是否是二的幂即可,利用位运算,\(x \& (x - 1)\)。

代码:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath> using namespace std; #define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define PLL pair<long, long> typedef long long ll;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI; void solve() {
ll n;
cin >> n;
if (n & (n - 1)) {
puts("YES");
} else {
puts("NO");
}
} int main()
{
ios::sync_with_stdio(false), cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}

B. New Year's Number

链接:B题链接

题目大意:

判断一个数\(n\)是否可以由\(a\)个\(2021\)和\(b\)个\(2020\)组成。

思路

既然由\(2020\)与\(2021\)组成,那么只需要判断\(n\)对\(2020\)取模后得到的数是否可以由\(n / 2020\)个\(1\)组成即可,即\((n \% 2020) <= (n / 2020)\)。

代码:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector> using namespace std; #define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define PLL pair<long, long> typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI; void solve() {
int n;
cin >> n;
if ((n % 2020) <= (n / 2020)) {
puts("YES");
} else {
puts("NO");
}
} int main()
{
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}

C. Ball in Berland

链接:C题链接

题目大意:

有\(a\)个男生,\(b\)个女生,一个男生一个女生组合起来跳舞,并且要求选出两对,给出\(k\)对男女组合,求有多少种组合方式。

思路

可以两重直接循环枚举,枚举到\([a, b]\)的时候,二重循环中判断不包含\(a,b\)顶点的都可以加到答案中,但是直接枚举肯定超时,因此优化一下我们就可以预处理出\(a\)的出度\(degreeA[a]\),\(b\)的出度\(degreeB[b]\),那么一重循环枚举到\([a, b]\)我们可以直接找到不符合条件的有几个,即\(degreeA[a] + degreeB[b] - 1\),一共有\(k\)对那么符合条件的就有\(k - (degreeA[a] + degreeB[b] - 1)\),因此就从\(O(n^2)\)优化到了\(O(n)\),最后再将答案除以\(2\)即可,因为每个顶点都算了两遍。

代码:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector> using namespace std; #define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define PLL pair<long, long> typedef long long ll;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI; const int N = 2e5 + 10;
int edga[N], edgb[N];
ll out_degreeA[N], out_degreeB[N]; void solve() {
int a, b, k;
cin >> a >> b >> k;
for (int i = 1; i <= k; i++) {
cin >> edga[i];
out_degreeA[edga[i]]++;
}
for (int i = 1; i <= k; i++) {
cin >> edgb[i];
out_degreeB[edgb[i]]++;
}
ll res = 0;
for (int i = 1; i <= k; i++) {
res += k - (out_degreeA[edga[i]] + out_degreeB[edgb[i]] - 1);
}
cout << res / 2 << endl;
memset(out_degreeA, 0, sizeof out_degreeA);
memset(out_degreeB, 0, sizeof out_degreeB);
} int main()
{
int t;
cin >> t;
while (t--) {
solve();
} return 0;
}

D. Cleaning the Phone

链接:D题链接

题目大意:

清理手机问题,每个\(app\)占用内存\(a_i\),它相应的实用度有\(b_i\) \((b_i只能为1或2)\),那么总的实用度就是\(b_i\)的和,现在要清理内存,要求清理出至少\(m\)的内存,损失最少实用度,求出损失的最少实用度,若没有则输出\(-1\)。

思路

很明显的贪心策略就是优先删除实用度为\(1\)并且占内存比较大的,再者就是删除实用度为\(2\)占内存比较大的,而但是毕竟选择的不是一两个\(app\),因此为了解决这个问题可以将实用度为1或者2的分成两个数组,然后求其前缀和,最好的方案就是再能达到需求的情况下尽可能少的卸载实用度为\(2\)的\(app\),因此从大到小枚举实用度为\(2\)的\(app\),然后剩下就是\(m - preSum2\),那么另一边就用二分来选择\(preSum1\),维护一个\(res\)始终为最小方案。

代码:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <climits> using namespace std; #define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define PLL pair<long, long> typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI; void solve() {
int n, m;
cin >> n >> m;
vector<LL> v(n + 1), preSum1, preSum2;
preSum1.push_back(0), preSum2.push_back(0);
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
for (int i = 1; i <= n; i++) {
int c;
cin >> c;
if (c == 1) {
preSum1.push_back(v[i]);
}
else if (c == 2) {
preSum2.push_back(v[i]);
}
} sort(preSum2.rbegin(), preSum2.rend() - 1), sort(preSum1.rbegin(), preSum1.rend() - 1); for (int i = 1; i < preSum1.size(); i++) {
preSum1[i] += preSum1[i - 1];
}
for (int i = 1; i < preSum2.size(); i++) {
preSum2[i] += preSum2[i - 1];
} LL res = INT_MAX;
for (int i = preSum2.size() - 1; i >= 0; i--) { //从大到小枚举
LL aim = m - preSum2[i];
LL l = 0, r = preSum1.size();
while (l < r) {
LL mid = l + r >> 1;
if (preSum1[mid] >= aim) {
res = min(res, i * 2 + mid);
r = mid;
}
else {
l = mid + 1;
}
}
}
cout << (res == INT_MAX ? -1 : res) << endl;
} int main()
{
int t;
cin >> t;
while (t--) {
solve();
} return 0;
}

E. Advertising Agency

链接:E题链接

题目大意:

一个人从\(n\)个博主里选\(k\)个来带货,那么她当然是优先选择粉丝多的博主了,问有多少种选择方案。

思路

设\(cnt[x]\)为拥有\(x\)个粉丝的博主,那么我们肯定优先从粉丝多的博主选了,例如要求选\(k\)个,已经选了\(m\)个,还剩下\(k - m\)个需要选,那么现在\(cnt[x] >= k - m\),因此只需要从cnt[x]里选k-m个即可,即求组合数,因为数据范围很小,可以直接用递推式即可:\(C_a^b = C_{a-1}^{b} + C_{a-1}^{b-1}\)

代码:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector> using namespace std; #define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define PLL pair<long, long> typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI; const int mod = 1e9 + 7;
const int N = 1010;
int c[N][N]; void init() {
for (int i = 0; i < N; i++) {
for (int j = 0; j <= i; j++) {
if (!j) {
c[i][j] = 1;
} else {
c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
}
}
}
} void solve() {
int k, n;
cin >> n >> k;
vector<int> cnt(n + 1);
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
cnt[x]++;
}
init();
for (int i = n; i >= 1; i--) {
if (cnt[i] >= k) {
cout << c[cnt[i]][k] << endl;
return;
} else {
k -= cnt[i];
}
}
} int main()
{
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}

Codeforces Round #697 (Div. 3) A~E题解的更多相关文章

  1. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  2. Codeforces Round #198 (Div. 2)A,B题解

    Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...

  3. Codeforces Round #672 (Div. 2) A - C1题解

    [Codeforces Round #672 (Div. 2) A - C1 ] 题目链接# A. Cubes Sorting 思路: " If Wheatley needs more th ...

  4. Codeforces Round #614 (Div. 2) A-E简要题解

    链接:https://codeforces.com/contest/1293 A. ConneR and the A.R.C. Markland-N 题意:略 思路:上下枚举1000次扫一遍,比较一下 ...

  5. Codeforces Round #610 (Div. 2) A-E简要题解

    contest链接: https://codeforces.com/contest/1282 A. Temporarily unavailable 题意: 给一个区间L,R通有网络,有个点x,在x+r ...

  6. Codeforces Round #611 (Div. 3) A-F简要题解

    contest链接:https://codeforces.com/contest/1283 A. Minutes Before the New Year 题意:给一个当前时间,输出离第二天差多少分钟 ...

  7. Codeforces Round #499 (Div. 2) D. Rocket题解

    题目: http://codeforces.com/contest/1011/problem/D This is an interactive problem. Natasha is going to ...

  8. Codeforces Round #499 (Div. 2) C Fly题解

    题目 http://codeforces.com/contest/1011/problem/C Natasha is going to fly on a rocket to Mars and retu ...

  9. Codeforces Round #198 (Div. 2)C,D题解

    接着是C,D的题解 C. Tourist Problem Iahub is a big fan of tourists. He wants to become a tourist himself, s ...

  10. Codeforces Round #579 (Div. 3) 套题 题解

    A. Circle of Students      题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...

随机推荐

  1. 浅谈php伪协议的运用

    浅谈php伪协议的运用 (133条消息) PHP Filter伪协议Trick总结_php伪协议rot13的用法_swtre33的博客-CSDN博客 php死亡exit()绕过 - xiaolong' ...

  2. 王道oj/problem13(用递归数楼梯)

    网址:http://oj.lgwenda.com/problem/13 思路:用递归写step(int n):return step(n-1)+step(n-2); 停止条件是:n=1为1:n=2为2 ...

  3. 使用 python 快速搭建http服务

    python -m SimpleHTTPServer 8888 使用上面的命令可以把当前目录发布到8888端口. 直接浏览器访问 但是这条命令是当前运行的,不是后台运行的,也就是说如果Ctrl + C ...

  4. 【pandas小技巧】--拆分列

    拆分列是pandas中常用的一种数据操作,它可以将一个包含多个值的列按照指定的规则拆分成多个新列,方便进行后续的分析和处理.拆分列的使用场景比较广泛,以下是一些常见的应用场景: 处理日期数据:在日期数 ...

  5. 如何选择最适合您的Excel处理库?

    摘要:本文由葡萄城技术团队于博客园原创并首发.转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 引言 GcExcel和POI是两个应用于处理Excel文件的技 ...

  6. 关于三维模型OSGB格式轻量化在数据存储的重要性浅析

    关于三维模型OSGB格式轻量化在数据存储的重要性浅析 三维模型的OSGB格式是一种常见的数据格式,用于存储和传输地理信息系统(GIS)中的三维地图数据.随着技术的不断发展,三维模型的应用越来越广泛,包 ...

  7. LeetCode 周赛上分之旅 #43 计算机科学本质上是数学吗?

    ️ 本文已收录到 AndroidFamily,技术和职场问题,请关注公众号 [彭旭锐] 和 BaguTree Pro 知识星球提问. 学习数据结构与算法的关键在于掌握问题背后的算法思维框架,你的思考越 ...

  8. [译]这几个CSS小技巧,你知道吗?

    前言 在网页设计和前端开发中,CSS属性是非常重要的一部分.掌握常用的CSS属性不仅可以使你的网页看起来更美观,还能提升用户体验,今天小编为大家介绍8个常见的CSS小技巧: 1.修改滚动条样式 下图是 ...

  9. 关闭k8s的pod时减小对服务的影响

    在应用程序的整个生命周期中,正在运行的 pod 会由于多种原因而终止.在某些情况下,Kubernetes 会因用户输入(例如更新或删除 Deployment 时)而终止 pod.在其他情况下,Kube ...

  10. 全景VR KRPano项目打包成安卓APP快速简易教程

    有时候,我们可能不想把我们制作的全景VR项目发布到网站上,而是想把它作为一个手机应用来使用或者分享.这样,我们就可以更好地保护我们的作品,也可以更方便地展示给客户或者朋友.本文将介绍一种简单的方法,让 ...