Educational Codeforces Round 104 (Rated for Div. 2) A,B,C,D,E
Educational Codeforces Round 104 (Rated for Div. 2) A,B,C,D,E
A - Arena
题意
nnn 个英雄,他们的等级分别是 a1,a2,…,ana_1,a_2,…,a_na1,a2,…,an ,和同等级的英雄打会平局,和比自己等级低的打可以使自己等级上升 111 ,两个英雄可以打很多次。我们称可能可以达到 100500100^{500}100500 的英雄成为可能的冠军,问有多少个可能的冠军?
思路
只要有比自己等级低的英雄,就可能是冠军。
代码
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define PI acos(-1)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int N = 1e4 + 19;
const ll mod = 1e9 + 7;int a[N];int main()
{int T;cin >> T;while(T--){int n;cin >> n;int minn = INF;for(int i = 0; i < n; i++){cin >> a[i];if(a[i] < minn)minn = a[i];}int ans = n;for(int i = 0; i < n; i++){if(a[i] == minn)ans--;}cout << ans << endl;}return 0;
}
B - Cat Cycle
题意
两只猫A、B, nnn 个猫窝。每个小时猫猫们都会更换睡觉的猫窝:A从第 n−1n - 1n−1 个递减的往第 111 个猫窝睡,B从第 111 个递增的往第 n−1n - 1n−1 个猫窝睡。B和A从不躺在一个猫窝里睡觉,如果恰好他们接下来要去的猫窝是同一个,则B放弃该猫窝去再下一个点,并且不返回这个错过的猫窝睡觉。
问 kkk 小时后,猫猫B在哪个猫窝里?
思路
首先,如果是偶数个猫窝那么猫猫睡觉是不会冲突的,直接输出模数即可;
对于奇数部分,我们先对5个猫窝的情况进行模拟:
k | A | B |
---|---|---|
1 | 5 | 1 |
2 | 4 | 2 |
3 | 3 | 4 |
4 | 2 | 5 |
5 | 1 | 2 |
6 | 5 | 3 |
7 | 4 | 5 |
8 | 3 | 1 |
9 | 2 | 3 |
10 | 1 | 4 |
11 | 5 | 1 |
12 | 4 | 2 |
13 | 3 | 4 |
14 | 1 | 5 |
15 | 1 | 2 |
可以看出有以下规律:
- B的运动规律是有周期的,在第11小时又回到了和第一小时一样的运动轨迹;
- B的运动轨迹可以分成两部分看:1 2 4 5 2 3 5 1 3 4 ,可以看出他能以某种形式分出奇偶,轨迹在奇偶部分分别递增(偶:12,23,34;奇:45,51)。
经过推算,可以发现B的奇偶分区可以根据 m=(n−1)/2m = (n - 1) / 2m=(n−1)/2 来定。
- 在偶数区域1的运动规律为:{1,2,…,m}\{1, 2, …, m\}{1,2,…,m} → {2,3…,m,m+1}\{2, 3 …, m, m + 1\}{2,3…,m,m+1} → ……… → {m+1,m+2,…,n−1}\{m + 1, m + 2, …, n - 1\}{m+1,m+2,…,n−1}
- 在奇数区域2的运动规律为:{m+2,m+3,…,n}\{m + 2, m + 3, …, n\}{m+2,m+3,…,n} → {m+3,m+4,…,n,1}\{m + 3, m + 4, …, n, 1\}{m+3,m+4,…,n,1} → ……… → {n,1,2…,m−1}\{n, 1, 2 …, m - 1\}{n,1,2…,m−1}
因此我们只需要判断 kkk 所在的区域(k/mk / mk/m),以及 kkk 在该区域的具体位置(k%mk \% mk%m)即可。
个人感觉我这个办法其实蛮麻烦的,很容易出错,,不知道还有没有更好的办法。
代码
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define PI acos(-1)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int N = 1e4 + 19;
const ll mod = 1e9 + 7;int a[N];int main()
{int T;cin >> T;while(T--){int n, k;cin >> n >> k;if(n % 2 == 0){int ans = ((k % n) == 0) ? n : (k % n);cout << ans << endl;}else{int m = (n - 1) / 2;int pos = (k % m) == 0 ? m : (k % m);if(n == 3){pos = k % n;if(pos == 1){cout << 1 << endl;}else if(pos == 2){cout << 3 << endl;}else{cout << 2 << endl;}continue;}int time = (k - 1) / m;//cout << k << ' ' << m << endl;int ans = time / 2 + pos;//cout << time / 2 << ' ' << pos << endl;if(time % 2)ans += m + 1;ans = (ans % n) == 0 ? n : (ans % n);cout << ans << endl;}}return 0;
}
C - Minimum Ties
题意
nnn 支队伍,每两只队伍都要打一局比赛,胜出方加3分,输的一方不加分,若平局两个队伍各加1分。问怎样的比赛结果可以使所有队伍的分数一样,且平局的次数最少?
思路
画了个草图,大概描述了一下比赛胜负情况的分配:(长方形其实是矩阵,简化成了线条)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-FpIKb8LG-1613794495421)(C:\Users\29039\AppData\Roaming\Typora\typora-user-images\image-20210216174206791.png)]
代码
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define PI acos(-1)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int N = 1e4 + 19;
const ll mod = 1e9 + 7;int main()
{int T;cin >> T;while(T--){int n;int cnt = 0;cin >> n;if(n == 2){cout << 0 << endl;continue;}if(n % 2 == 0){cnt = n / 2 - 1;for(int i = n - 1; i >= 0; i--){for(int j = 0; j < min(cnt, i); j++)cout << "1 ";if(i > cnt)cout << "0 ";for(int j = cnt; j < i - 1; j++)cout << "-1 ";}cout << endl;}else{cnt = n / 2;for(int i = n - 1; i >= 0; i--){for(int j = 0; j < min(cnt, i); j++)cout << "1 ";for(int j = cnt; j < i; j++)cout << "-1 ";}cout << endl;}}
}
D - Pythagorean Triples
题意
有一类直角三角形,设其三边分别为 a,b,c(a≤b≤c)a, b, c \ \ (a \leq b \leq c)a,b,c (a≤b≤c) , 满足 A2−B=CA^2 - B = CA2−B=C 。现给定数字 nnn ,问在 1≤a≤b≤c≤n1 \leq a \leq b \leq c \leq n1≤a≤b≤c≤n 的条件下,有多少这类三角形?
思路
对式子进行化简,可以得到:
a2+12=ca≤c,c≤n\frac{a^2 + 1}{2} = c \ \ a \leq c \ , \ c \leq n 2a2+1=c a≤c , c≤n
由此可得 aaa 一定是奇数(因为 a2+1a^2 + 1a2+1 是偶数才能被 222 整除),且 a2≤2×c−1≤2×n−1a^2 \leq 2 \times c - 1 \leq 2 \times n - 1a2≤2×c−1≤2×n−1 。
由此,问题转化为求 [3,2×n−1][3,2 \times n - 1][3,2×n−1] 中有多少奇数。
其实可以 O(1)O(1)O(1) 算的,我还打了个表(不知道当时怎么想的),不过好像还有很多人暴力的,那我也还行( •̀ ω •́ )y
代码
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define PI acos(-1)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int N = 1e9 + 19;
const int M = 1e5 + 19;
const ll mod = 1e9 + 7;int a[M];void init()
{for(int i = 3; i * i < 2 * N; i++){if(i * i % 2){a[i] = a[i - 1] + 1;}else{a[i] = a[i - 1];}}
}int main()
{init();int T;cin >> T;while(T--){int n;cin >> n;cout << a[(int)sqrt(2 * n - 1)] << endl;}
}
E - Cheap Dinner
题意
一顿饭包含菜1,菜2,饮料和甜点。
菜 111 有 n1n_1n1 种,菜 222 有 n2n_2n2 种,饮料有 n3n_3n3 种,甜点有 n4n_4n4 种。其中有 m1m_1m1 对菜 111 和菜 222 不能一起吃, m2m_2m2 对菜 222 和饮料不能一起吃, m3m_3m3 对饮料和甜品不能一起吃。给定每个食物的价格,怎么搭配最便宜?
思路
codeforces Edu 104 DE 同学的思路,完全参考了这个题解写的qwq
网上全是线段树dp什么的,这个贪心方法简单清晰,强推
代码
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define PI acos(-1)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int N = 2e6 + 9;
const ll MOD = 1e9 + 7;struct node
{int id;int cost;
} a[N], b[N], c[N], d[N];set<int> s[N], sb[N], sc[N];bool cmp(node& a, node& b)
{return a.cost < b.cost;
}int main()
{int n1, n2, n3, n4;int m1, m2, m3;scanf("%d%d%d%d", &n1, &n2, &n3, &n4);for(int i = 0; i < n1; i++){scanf("%d", &a[i].cost);a[i].id = i + 1;}for(int i = 0; i < n2; i++){scanf("%d", &b[i].cost);b[i].id = i + 1;}for(int i = 0; i < n3; i++){scanf("%d", &c[i].cost);c[i].id = i + 1;}for(int i = 0; i < n4; i++){scanf("%d", &d[i].cost);d[i].id = i + 1;}scanf("%d", &m1);for(int i = 0, x, y; i < m1; i++){scanf("%d%d", &x, &y);sb[y].insert(x);}scanf("%d", &m2);for(int i = 0, x, y; i < m2; i++){scanf("%d%d", &x, &y);s[x].insert(y);}scanf("%d", &m3);for(int i = 0, x, y; i < m3; i++){scanf("%d%d", &x, &y);sc[x].insert(y);}sort(a, a + n1, cmp);for(int i = 0; i < n2; i++){bool flag = 0;for(int j = 0; j < n1; j++){if(sb[b[i].id].find(a[j].id) == sb[b[i].id].end()){b[i].cost += a[j].cost;flag = 1;break;}}if(!flag){b[i].cost = INF;}}sort(d, d + n4, cmp);for(int i = 0; i < n3; i++){bool flag = 0;for(int j = 0; j < n4; j++){if(sc[c[i].id].find(d[j].id) == sc[c[i].id].end()){c[i].cost += d[j].cost;flag = 1;break;}}if(!flag){c[i].cost = INF;}}sort(c, c + n3, cmp);for(int i = 0; i < n2; i++){bool flag = 0;for(int j = 0; j < n3; j++){if(s[b[i].id].find(c[j].id) == s[b[i].id].end()){b[i].cost += c[j].cost;flag = 1;break;}}if(!flag){b[i].cost = INF;}}sort(b, b + n2, cmp);if(b[0].cost >= INF){cout << -1 << endl;}else{cout << b[0].cost << endl;}return 0;
}
总结
B题卡了特别久,有这类题目不熟练的原因,应该也有方法选取的问题,卡的原因主要是公式计算错误(奇数列加m + 1还是加m搞错了)。好像大家都过的很快,但是我就算的特别痛苦TT
D题WA了一发其实很可惜,是因为范围没有计算好,应该预处理到 2×n−12 \times n - 12×n−1 只处理到 nnn 。好在都过了。
多多包涵,共同进步
(k−1)/m(k - 1) / m(k−1)/m 为偶数。为什么要减1?因为小时从1开始。 ↩︎
(k−1)/m(k - 1) / m(k−1)/m 为奇数。为什么要减1?因为小时从1开始。 ↩︎
Educational Codeforces Round 104 (Rated for Div. 2) A,B,C,D,E相关推荐
- Educational Codeforces Round 104 (Rated for Div. 2)A~E解题报告
Educational Codeforces Round 104 (Rated for Div. 2) A. Arena \quad原题链接 http://codeforces.com/contest ...
- Educational Codeforces Round 104 (Rated for Div. 2)A-E题解
Educational Codeforces Round 104 (Rated for Div. 2)A-E题解 比赛链接:https://codeforces.ml/contest/1487 A题 ...
- Educational Codeforces Round 104 (Rated for Div. 2)
A. Arena 题目传送门: A. Arena 题目大意: 有n个人,每个人都有战斗力,当两个人打起来时,战斗力高的人赢并且战斗力加1,当战斗力达到100500时,则成为英雄.问能有多少人能成为英雄 ...
- Educational Codeforces Round 108 (Rated for Div. 2)-B. The Cake Is a Lie-题解
目录 Educational Codeforces Round 108 (Rated for Div. 2)-B. The Cake Is a Lie Problem Description Inpu ...
- Educational Codeforces Round 112 (Rated for Div. 2)-A. PizzaForces-题解
目录 Educational Codeforces Round 112 (Rated for Div. 2)-A. PizzaForces Problem Description Input Outp ...
- Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...
- Educational Codeforces Round 106 (Rated for Div. 2)(A ~ E)题解(每日训练 Day.16 )
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 Educational Codeforces Round 106 (Rated for Div. ...
- Educational Codeforces Round 37 (Rated for Div. 2) 1
Educational Codeforces Round 37 (Rated for Div. 2) A.Water The Garden 题意:Max想给花园浇水.花园可被视为长度为n的花园床,花园 ...
- Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)
Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...
最新文章
- csr_matrix矩阵用法小结
- micropython 模块_MicroPython添加Module(一)
- vivo真实案例:中台到底解决了什么问题?
- 流量 起伏大_广西崇左的德天跨国大瀑布,一半是中国一半是越南,天下奇观!...
- linux7 vnc 黑屏,51CTO博客-专业IT技术博客创作平台-技术成就梦想
- 黑苹果自制声卡仿冒驱动(AppleHDA for ALC269)
- 小麦(Wheat)-玉米(Maize)-水稻(Rice) 数粒软件
- Bias和Variance
- 计算机专业需要物理力学,读经典物理学和量子力学所想到的计算机哲学
- php mysql可以跨站_Laravel5中防止XSS跨站攻击的方法
- @vaild校验参数
- npm --save和--save-dev区别
- 剪切板的使用: 复制 粘贴
- NUC的型号说明及其他的一些信息
- 3D电视与3D眼镜的工作原理
- STM32G4系列通过SPI配置DRV8353S驱动芯片
- python学习之recognition的多人人脸识别
- 计算机相关技术在医院应用,计算机管理相关技术在医院中的应用分析
- 计算机软件著作权一般要多久,软件著作权一般多长时间
- 数据可视化之高级图表
热门文章
- php的 include_once 什么意思,【后端开发】php关于include_once与include之间的区别详解...
- 一文让你读懂区块链能给游戏带来什么价值?
- 点击导航高亮 html,jQuery实现的导航条点击后高亮显示功能示例
- 微商八大途径吸粉、引流客源技巧详解!
- 华为watch fit new和华为手环7区别
- mysql的ibdata1_ibdata1是?
- Vegas基础入门——让素材在指尖变换
- 基于HTML与CSS的网页制作课程设计(果汁外卖)
- 网页自动刷新JavaScript脚本
- 为自动化测试装上精准测试的“翅膀