2021年YCU蓝桥杯程序设计竞赛选拔赛题解


可能是在集训队的最后一次参与出题啦~

A:朴实无华的签到题

题意
在这里插入图片描述
做法:有两种情况,奇数位置都是奇数以及偶数位置都是奇数。那么暴力判断一下。嗯…本来想反手一个统计奇数结束这题的,结果假签到一发,有一种情况0 1 0 1 1,这种情况只有一种情况,就是排成1 0 1 0 1,所以还要判断一下奇数个数的数量以此决断选择哪个。

代码

#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
int main() {
   
  int n; scanf("%d", &n);
  int x = 0, y = 0, cntj = 0;
  for(int i = 1, a; i <= n; ++i) {
   
    scanf("%d", &a); 
    if(a & 1) {
   
      ++cntj;
      if(i&1) ++x;
      else ++y;
    }
  } 
  int res;
  if(cntj * 2 == n) res = min(x, y);
  else if(cntj * 2 < n) res = x;
  else res = y;
  printf("%d\n", res);
  return 0;
} 

B:炒鸡简单加法

题意
在这里插入图片描述
做法:小范围可暴力,直接送出70分。对于1e18的数据隔板法,分为1e18个1,用两块板子分隔,这两个板子分隔的方案数就是答案啦。第一块板子一共有(n+1)种可以放的位置,第二块板子基于第一个板子的基础上有(n+2)种可以放的位置,再除以2(第一块板子和第二块板子放的先后可能会重复)。可以发现答案就是 C n + 2 2 = ( n + 1 ) ( n + 2 ) 2 C_{n+2}^2=\frac{(n+1)(n+2)}{2} Cn+22=2(n+1)(n+2),不过最多还是找规律推公式叭,中途得小心爆精度嗷~

代码

#include<bits/stdc++.h>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-5
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {
   
  int f = 1; res = 0;
  char c = getchar();
  while(c < '0' || c > '9') {
    if(c == '-') f = -1; c = getchar(); }
  while(c >= '0' && c <= '9') {
    res = res * 10 + c - '0'; c = getchar(); }
  res *= f;
}
const int N = 1003;
const LL Mod = 998244353;
int main() {
   
  LL n; scanf("%lld", &n);
  LL x = n + 1, y =  n + 2;
  if(x&1) y /= 2;
  else x /= 2;
  x %= Mod; y %= Mod;
  printf("%lld\n", x * y % Mod);
  return 0;
}

C:蓝桥杯这次还是躲不过日期问题吗

题意
在这里插入图片描述
做法:直接暴力找。

代码

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const double Pi = acos(-1);
namespace io{
   
  template <typename T> inline void read(T &x) {
   
    x = 0; T f = 1;char s = getchar();
    for(; !isdigit(s); s = getchar()) if(s == '-') f = -1;
    
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值