2019-12-30 20:21阅读: 282评论: 0推荐: 0

Educational Codeforces Round 79 (Rated for Div. 2)

A. New Year Garland (CF 1279 A)

题目大意

给定红绿蓝三种颜色灯的数量,问能否摆成一排,使得相邻颜色不相同。

解题思路

植树问题。考虑数量最多为n的颜色的灯俩俩不相邻,那么其他颜色的灯的数量和要大于n1即可,大过n1的灯直接插到里面就好了。

神奇的代码
#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)

题目大意

给定n,s,以及n个数的数组,问数组从第一个数开始加,其中可以跳过一个数,和不超过s,问加的个数最多时应该跳过第几个数(不跳过输出0)。

解题思路

很显然如果我们跳过的话自然是跳过前面最大的那个,是否跳过就看跳过的话增加的时间能不能再增加一个数甚至更多。

神奇的代码
#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)

题目大意

给定n个礼物,从左到右标号。现在要依次给小朋友送礼物,共k个礼物序号分别为x1,x2,...,xk,如果当前要送的礼物xi不在第一个,那么圣诞老人要依次把前面的礼物放到一边,直到放了m个礼物后,xi的礼物在第一个位置,然后送了礼物后再把放出来的礼物放回去,此时放回去的顺序可以自己决定,此时会耗2m+1个体力值。问送完k个礼物最少消耗的体力值是多少。

解题思路

对于一个送出去的礼物xi,送出去后整理前面的礼物时,按照要送的礼物的顺序(如果在这里面的话)排好,这样总消耗的体力值最小。

神奇的代码
#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)

题目大意

给定n个孩子喜欢的礼物的序号的清单,然后随机选一个孩子a,从这个孩子期望的礼物随机选一个k,再随机选一个孩子b(可能为同一个),如果b的期望礼物里也有k,则圣诞老人就可以送礼物出去,否则不可以。问圣诞老人可以送礼物出去的概率是多少。

解题思路

概率题,由于按题目考虑计算的话会在找哪些孩子会期望该礼物耗很大时间,我们考虑枚举礼物,然后考虑该礼物送出去的概率。
我们枚举了一个礼物gifti,考虑枚举的两个人,对于第一个人a,设他期望的礼物数为numa,则选他的概率应该是1numa,对于第二个人b,由于b的礼物清单里要有gifti,设选gifti的人数有cntgifti,则选上b的概率为1cntgifti。由此,对于一个礼物,它能送出去的概率即为a wish gifti1numa1cntgifti,由于各礼物都是等概率抽到,则答案就是1kkia wish gifti1numa1cntgifti,其中kk是礼物种类,cnti是期望礼物i的人数,numi是孩子i期望的礼物数。

神奇的代码
#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 中国大陆许可协议进行许可。

posted @   ~Lanly~  阅读(282)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.