Educational Codeforces Round 79 (Rated for Div. 2)
A. New Year Garland (CF 1279 A)
题目大意
给定红绿蓝三种颜色灯的数量,问能否摆成一排,使得相邻颜色不相同。
解题思路
植树问题。考虑数量最多为的颜色的灯俩俩不相邻,那么其他颜色的灯的数量和要大于即可,大过的灯直接插到里面就好了。
神奇的代码
#include <bits/stdc++.h> #define MIN(a,b) ((((a)<(b)?(a):(b)))) #define MAX(a,b) ((((a)>(b)?(a):(b)))) #define ABS(a) ((((a)>0?(a):-(a)))) #define MP(a,b) make_pair((a),(b)) #define PB push_back using namespace std; typedef long long LL; typedef vector<int> VI; typedef pair<int,int> PII; typedef vector<PII> VPII; typedef vector<LL> VL; typedef pair<LL,LL> PLL; typedef vector<PLL> VPLL; template <typename T> void read(T &x) { int s = 0, c = getchar(); x = 0; while (isspace(c)) c = getchar(); if (c == 45) s = 1, c = getchar(); while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); if (s) x = -x; } template <typename T> void write(T x, char c = ' ') { int b[40], l = 0; if (x < 0) putchar(45), x = -x; while (x > 0) b[l++] = x % 10, x /= 10; if (!l) putchar(48); while (l) putchar(b[--l] | 48); putchar(c); } int main(void) { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); int a,b,c; int kase; read(kase); for (int i = 1; i <= kase; i++) { read(a); read(b); read(c); int maxx=MAX(a,MAX(b,c)); int sum=a+b+c; int ans=sum-maxx; if (ans>=maxx-1) printf("Yes\n"); else printf("No\n"); } return 0; }
B. Verse For Santa (CF 1279 B)
题目大意
给定以及个数的数组,问数组从第一个数开始加,其中可以跳过一个数,和不超过,问加的个数最多时应该跳过第几个数(不跳过输出)。
解题思路
很显然如果我们跳过的话自然是跳过前面最大的那个,是否跳过就看跳过的话增加的时间能不能再增加一个数甚至更多。
神奇的代码
#include <bits/stdc++.h> #define MIN(a,b) ((((a)<(b)?(a):(b)))) #define MAX(a,b) ((((a)>(b)?(a):(b)))) #define ABS(a) ((((a)>0?(a):-(a)))) #define MP(a,b) make_pair((a),(b)) #define PB push_back using namespace std; typedef long long LL; typedef vector<int> VI; typedef pair<int,int> PII; typedef vector<PII> VPII; typedef vector<LL> VL; typedef pair<LL,LL> PLL; typedef vector<PLL> VPLL; template <typename T> void read(T &x) { int s = 0, c = getchar(); x = 0; while (isspace(c)) c = getchar(); if (c == 45) s = 1, c = getchar(); while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); if (s) x = -x; } template <typename T> void write(T x, char c = ' ') { int b[40], l = 0; if (x < 0) putchar(45), x = -x; while (x > 0) b[l++] = x % 10, x /= 10; if (!l) putchar(48); while (l) putchar(b[--l] | 48); putchar(c); } const int N=1e5+8; LL sum[N],a[N],ans,s; int n,qwq,qaq; int main(void) { //ios::sync_with_stdio(false); freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); int kase; read(kase); for (int i = 1; i <= kase; i++) { bool flag=false; //printf("Case #%d: ", i); read(n); read(s); qwq=qaq=0; for(int u,i=1;i<=n;++i){ read(u); if (flag) continue; if (s>=0&&s-u<0) {if (u>qwq+s-u) qaq=0; flag=true;} s-=u; if (u>qwq){ qwq=u; qaq=i; } } if (s>=0&&flag==false) qaq=0; printf("%d\n",qaq); } return 0; }
C. Stack of Presents (CF 1279 C)
题目大意
给定个礼物,从左到右标号。现在要依次给小朋友送礼物,共个礼物序号分别为,如果当前要送的礼物不在第一个,那么圣诞老人要依次把前面的礼物放到一边,直到放了个礼物后,的礼物在第一个位置,然后送了礼物后再把放出来的礼物放回去,此时放回去的顺序可以自己决定,此时会耗个体力值。问送完个礼物最少消耗的体力值是多少。
解题思路
对于一个送出去的礼物,送出去后整理前面的礼物时,按照要送的礼物的顺序(如果在这里面的话)排好,这样总消耗的体力值最小。
神奇的代码
#include <bits/stdc++.h> #define MIN(a,b) ((((a)<(b)?(a):(b)))) #define MAX(a,b) ((((a)>(b)?(a):(b)))) #define ABS(a) ((((a)>0?(a):-(a)))) #define MP(a,b) make_pair((a),(b)) #define PB push_back using namespace std; typedef long long LL; typedef vector<int> VI; typedef pair<int,int> PII; typedef vector<PII> VPII; typedef vector<LL> VL; typedef pair<LL,LL> PLL; typedef vector<PLL> VPLL; template <typename T> void read(T &x) { int s = 0, c = getchar(); x = 0; while (isspace(c)) c = getchar(); if (c == 45) s = 1, c = getchar(); while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); if (s) x = -x; } template <typename T> void write(T x, char c = ' ') { int b[40], l = 0; if (x < 0) putchar(45), x = -x; while (x > 0) b[l++] = x % 10, x /= 10; if (!l) putchar(48); while (l) putchar(b[--l] | 48); putchar(c); } int main(void) { //ios::sync_with_stdio(false); freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); int kase; read(kase); for (int i = 1; i <= kase; i++) { //printf("Case #%d: ", i); int n,m; LL ans; read(n); read(m); vector<int> qwq(n+1); for(int u,i=1;i<=n;++i) { read(u); qwq[u]=i; } ans=0; int l=0; for(int u,i=1;i<=m;++i){ read(u); if (l<qwq[u]) {ans+=2ll*(qwq[u]-i)+1ll;l=qwq[u];} else ++ans; } printf("%lld\n",ans); } return 0; }
D. Santa's Bot (CF 1279 D)
题目大意
给定个孩子喜欢的礼物的序号的清单,然后随机选一个孩子,从这个孩子期望的礼物随机选一个,再随机选一个孩子(可能为同一个),如果的期望礼物里也有,则圣诞老人就可以送礼物出去,否则不可以。问圣诞老人可以送礼物出去的概率是多少。
解题思路
概率题,由于按题目考虑计算的话会在找哪些孩子会期望该礼物耗很大时间,我们考虑枚举礼物,然后考虑该礼物送出去的概率。
我们枚举了一个礼物,考虑枚举的两个人,对于第一个人,设他期望的礼物数为,则选他的概率应该是,对于第二个人,由于的礼物清单里要有,设选的人数有,则选上的概率为。由此,对于一个礼物,它能送出去的概率即为,由于各礼物都是等概率抽到,则答案就是,其中是礼物种类,是期望礼物的人数,是孩子期望的礼物数。
神奇的代码
#include <bits/stdc++.h> #define MIN(a,b) ((((a)<(b)?(a):(b)))) #define MAX(a,b) ((((a)>(b)?(a):(b)))) #define ABS(a) ((((a)>0?(a):-(a)))) #define MP(a,b) make_pair((a),(b)) #define PB push_back using namespace std; typedef long long LL; typedef vector<int> VI; typedef pair<int,int> PII; typedef vector<PII> VPII; typedef vector<LL> VL; typedef pair<LL,LL> PLL; typedef vector<PLL> VPLL; template <typename T> void read(T &x) { int s = 0, c = getchar(); x = 0; while (isspace(c)) c = getchar(); if (c == 45) s = 1, c = getchar(); while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); if (s) x = -x; } template <typename T> void write(T x, char c = ' ') { int b[40], l = 0; if (x < 0) putchar(45), x = -x; while (x > 0) b[l++] = x % 10, x /= 10; if (!l) putchar(48); while (l) putchar(b[--l] | 48); putchar(c); } const int N=1e6+8; const LL mo=998244353; LL sum[N]; int cnt[N]; int n,ma; LL invn,invk,ans; LL kuai(int a,LL b){ LL qwq=1; LL aa=a; while(b){ if (b&1) qwq=qwq*aa%mo; aa=aa*aa%mo; b>>=1; } return qwq; } int main(void) { //ios::sync_with_stdio(false); freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); read(n); invn=kuai(n,mo-2); ma=0; for(int k,i=1;i<=n;++i){ read(k); invk=kuai(k,mo-2); for(int u,j=1;j<=k;++j){ read(u); ma=MAX(ma,u); sum[u]=(sum[u]+invk)%mo; ++cnt[u]; } } ans=0; for(int i=1;i<=ma;++i){ if (cnt[i]==0) continue; ans=(ans+sum[i]*cnt[i]%mo*invn%mo)%mo; } ans=(ans*invn)%mo; printf("%lld\n",ans); return 0; }
本文作者:~Lanly~
本文链接:https://www.cnblogs.com/Lanly/p/12121532.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现