2021辽宁省大学生程序设计竞赛 C D E F G I L

WAWA大哭, 弱鸡七题摘银准备退役...

感谢队友方大师和棋兄的鼎力相助👍


C传染病统计https://ac.nowcoder.com/acm/contest/22352/C

题目描述

阿强来到大街上,街上有 N 个人,编号为 1 ∼N 。简单起见,我们把每个人都看成一条线上的一个点。对每个合法的 i,第 i 个人的位置是 xi。

这些人当中恰好有一个感染了 COVID-19,但我们不知道是哪一个。当一个被感染的人和一个未被感染的人之间的距离不超过 2 时,病毒会从前者传播到后者。如果我们等待足够长的时间,会有一些人(这些人由第一个感染者确定)被感染;这些人的数量被称作最终被感染的人数。

阿强希望求出最终被感染的人数的最小和最大可能的值,也就是最好和最坏情况下这个数的值。

输入描述:

第一行包含一个整数T(1≤T≤2,000),表示数据组数。接下来是T组数据。
•每组数据的第一行包含一个整数N(2≤N≤8)。
•第二行包含N个整数x1,x2,…,xn(0≤xi≤10)用空格隔开。

输出描述:

对于每组数据,输出一行包含两个整数,用空格隔开,表示最终被感染的人数的最小值和最大值。

示例1

输入

3
2
3 6
3
1 3 5
5
1 2 5 6 7

输出

1 1
3 3
2 3
#include <bits/stdc++.h>

using namespace std;

int a[10],d[10];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t,n;
    cin >> t;
    while(t--)
    {
        cin>>n;
        cin>>a[0];
        
        for(int i=1;i<n;i++){
            cin>>a[i];
            d[i-1]=a[i]-a[i-1];
        }
        
        int resMax=-1,resMin=8,cnt=0;
        for(int i=0;i<n-1;i++){
            cnt=0;
            while(d[i]<=2&&i<n-1){
                cnt++;
                i++;
            }
            resMax=max(resMax,cnt);
            resMin=min(resMin,cnt);
        }
        cout<<resMin+1<<' '<<resMax+1<<'\n';
    }


    return 0;
}


D阿强与网格https://ac.nowcoder.com/acm/contest/22352/D

题目描述

阿强在一个N行M列的网格中。
阿强可以用两种方式移动:
向下、向左、向上或向右移动,每次移动的代价为X。换句话说,如果您位于网格的单元格(i,j),则可以转到任意单元格(i+1,j),(i,j−1) ,(i−1,j)或(i,j+1),代价为X。

沿对角线向左下、向右下、向左上、向右上移动成本为Y。换句话说,如果你在网格的单元格(i,j)上,你可以去任意一个单元格(i+1,j−1) ,(i+1,j+1),(i−1,j−1) 或(i−1,j+1),代价为Y。

请你找到从阿强从左上角(1,1)到右下角(N,M)的最小成本。

阿强不能移出网格。

输入描述:

 

第一行一个整数T(1≤T≤5∗10^5)表示数据组数。

接下来T行每行四个整数N,M,X,Y(1≤N,M,X,Y≤10^6)

输出描述:

对于每组数据一行表示答案。

示例1

输入

3
5 6 2 5
4 7 5 6
7 8 6 5

输出

18
33
36

纯模拟就好

#include <bits/stdc++.h>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--){
        long long  N,M,X,Y;
        long long ans = 0;
        cin >> N >> M >> X >> Y;
        N--,M--;
        long long  MIN = min(N,M);
        long long  MAX = max(N,M);
        long long  len = MAX - MIN;
        if(N && M){
            if(Y >= 2 * X){
                ans += (N + M) * X;
            }else if(Y >= X){
                ans += Y * MIN;
                ans += len * X;
            }else{
                if(len & 1){
                    ans += Y * MIN;
                    ans += Y * (len - 1);
                    ans += X;
                }else{
                    ans += Y * MAX;
                }
            }
        }else{
            ans += X * MAX;
        }
        cout << ans  << '\n';
    }
    return 0;
}


E生活大爆炸https://ac.nowcoder.com/acm/contest/22352/E

题目描述

有n个男孩和m个女孩参加戏剧俱乐部。要制作一部戏剧《生活大爆炸》,他们需要选择一组由t个演员组成的剧组,其中包括不少于4名男孩和不少于1名女孩。有多少种方法可以组成一个小组?当然,只有剧团组成不同的变体才被认为是不同的。

输入描述:

一行包含三个整数n,m,t (4 ≤n≤30, 1 ≤m≤ 30, 5 ≤t≤n+m)

输出描述:

一行表示答案。

示例1

输入

5 2 5

输出

10

#include <bits/stdc++.h>

using namespace std;

long long C[65][65];

void solve(){
    for(int i = 0;i <= 65;i++){
        for(int j = 0;j <= i;j++){
            if(!j){
                C[i][j] = 1;
            }else
            C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m,t;
    solve();
    cin >> n >> m >> t;
    long long ans = 0;
    for(int i = 4;i <= n;i++){
        for(int j = 1;j <=m;j++){
            if(i + j == t){
                ans += C[n][i] * C[m][j];
            }
        }
    }
    cout << ans << '\n';

    return 0;
}


FCapslockhttps://ac.nowcoder.com/acm/contest/22352/F


 

题目描述

Caps lock是一种计算机键盘键。按此键可设置输入模式,默认情况下,键入的字母为大写。如果它是偶然按下的,它就会产生一些事故。

让我们考虑键入一个字符时Caps lock键意外打开的情况,如果:

1、它只包含大写字母;

2、除第一个字母外,所有字母都是大写的。

在这两种情况下,我们应该更改所有字母的大小写。例如,单词“hELLO”、“HTTP”、“z”的单词大小写应该改变。

编写一个应用上述规则的程序。如果无法应用规则,程序应保持单词不变。

输入描述:

第一行包含一个由大写和小写字母组成的单词。单词的长度小于等于100。

输出描述:

打印单词的处理结果。

示例1

输入

cAPS

输出

Caps

示例2

输入

Lap

输出

Lap

#include <bits/stdc++.h>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int len = s.size();
    bool ok = true;
        for(int i=1; i<len ;i++){
            if(s[i] > 'Z'){
                ok = false;
                break;
            }
        }
    string a;
    if(ok){
        if(s[0] >= 'A' && s[0] <= 'Z'){
            cout << (char)(s[0] + 32);
        }else{
            cout << (char)(s[0] - 32);
        }
        for(int i=1;i<len;i++){
            cout << (char)(s[i] + 32);
        }
    }else{
        cout << s << '\n';
    }
    return 0;
}


G字节类型https://ac.nowcoder.com/acm/contest/22352/G

题目描述

阿强参加了一个编程大赛。他想要选用一个语言作为自己的主要编程语言。因为他喜欢非常大的数,所以他选用了java。它有一个非常大的整数数据类型,称为BigInteger。
但是写了几道题后,Petya意识到并非所有任务都需要使用BigInteger类型。实际上有时候小范围的数更利于编程。这就是为什么会出现一个问题:“如果要存储正整数n,应该使用哪种整数类型?”
阿强只知道5种整数类型:
1) byte占用1个字节,允许存储来自 - 128至127
2) short占用2个字节,允许存储来自的数字 - 32768至32767
3) int占用4个字节,允许从中存储数字 - 2147483648至2147483647
4) long占用8个字节,允许存储来自 - 9223372036854775808至9223372036854775807
5) BigInteger可以存储任何整数,但它不是一个基元类型,使用它的操作要慢得多。
对于上面给出的所有类型,边界值都包含在值范围内。
从这个列表中,阿强想存储整数n,并且想选择占用字节数最小的类型。由于BigInteger的工作速度慢得多,阿强认为它是占用最多的一个。

输入描述:

第一行包含一个正数n。它由不超过100位数字组成,不包含任何前导零。数字n不能表示为空字符串。

输出描述:

一行包含一个字符串,字符串在"byte,short,int,long,BigInteger”中产生,表示能存储下n的占用字节数最小的类型

示例1

输入

127

输出

byte

示例2

输入

123456789101112131415161718192021222324

输出

BigInteger

这题笑死,硬核判断,居然没有TLE,早知道用Python了....

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, a;
  int rua = 0;
  cin >> s;
  bool ok = true;
  if (s[0] == '-') {
    a = s.substr(1, s.size());
    rua = 1;
  } else {
    a = s;
  }
  int len = a.size();

  if (len < 3) {
    cout << "byte"
         << "\n";
  } else if (len == 3) {
    if (a[0] - '0' <= 1)
      if (a[1] - '0' <= 2)
        if (a[2] - '0' <= 7 + rua){
          cout << "byte"
               << "\n";
               ok = false;
        }
    if(ok)
          cout << "short"
               << "\n";
  } else if (len < 5) {
    cout << "short"
         << "\n";
  } else if (len == 5) {
    if (a[0] - '0' <= 3)
      if (a[1] - '0' <= 2)
        if (a[2] - '0' <= 7)
          if (a[3] - '0' <= 6)
            if (a[4] - '0' <= 7 + rua){
              cout << "short"
                   << "\n";
                   ok = false;
            }
    if(ok)
              cout << "int"
                   << "\n";
  } else if (len < 10) {
    cout << "int"
         << "\n";
  } else if (len == 10) {
    if (a[0] - '0' <= 2)
      if (a[1] - '0' <= 1)
        if (a[2] - '0' <= 4)
          if (a[3] - '0' <= 7)
            if (a[4] - '0' <= 4)
              if (a[5] - '0' <= 8)
                if (a[6] - '0' <= 3)
                  if (a[7] - '0' <= 6)
                    if (a[8] - '0' <= 4)
                      if (a[9] - '0' <= 7 + rua){
                        cout << "int"
                             << "\n";
                             ok = false;
                      }
                      if(ok)
                        cout << "long"
                             << "\n";
  } else if (len < 19) {
    cout << "long"
         << "\n";
  } else if (len == 19) {
    if (a[0] - '0' <= 9)
      if (a[1] - '0' <= 2)
        if (a[2] - '0' <= 2)
          if (a[3] - '0' <= 3)
            if (a[4] - '0' <= 3)
              if (a[5] - '0' <= 7)
                if (a[6] - '0' <= 2)
                  if (a[7] - '0' <= 0)
                    if (a[8] - '0' <= 3)
                      if (a[9] - '0' <= 6)
                        if (a[10] - '0' <= 8)
                          if (a[11] - '0' <= 5)
                            if (a[12] - '0' <= 4)
                              if (a[13] - '0' <= 7)
                                if (a[14] - '0' <= 7)
                                  if (a[15] - '0' <= 5)
                                    if (a[16] - '0' <= 8)
                                      if (a[17] - '0' <= 0)
                                        if (a[18] - '0' <= 7 + rua){
                                          cout << "long"
                                               << "\n";
                                               ok = false;
                                        }
                                        if(ok)
                                          cout << "BigInteger"
                                               << "\n";
  } else
    cout << "BigInteger"
         << "\n";

  return 0;
}


I完美主义https://ac.nowcoder.com/acm/contest/22352/I

题目描述

阿强采摘了一些苹果,并把他们分堆排成了一行,从左往右编号为第 1 … 𝑛 堆,其中第𝑖堆苹果有ai个。

完美主义者阿珍看到这些苹果,觉得他们摆放的非常杂乱。她要求阿强进行如下的操作。

对某堆苹果进行调整:阿强将会将第𝑖堆苹果调整成bi个;

对阿珍询问做出答复:其中每次询问表示为[𝑙, 𝑟],表示询问第𝑙堆到第𝑟堆之间的苹果数量是否满足al≤al+1≤⋯≤ar−1≤ar​,如果满足则称为完美。

输入描述:

第一行两个整数n, q (1≤n,q≤3∗10^5),表示苹果的堆数和操作的个数;

第二行n个整数表示ai。

以下𝑞行,每行3个整数,第一个整数为opt;

若opt = 1,之后两个整数i, bi,表示将第𝑖堆苹果调整为bi个;

若opt = 2,之后两个整数𝑙, 𝑟,表示对[𝑙, 𝑟]之间的苹果堆进行询问。

(1≤ai,bi≤10^9)

输出描述:

输出一共𝑞行,每行一个 Yes 或者 No,表示每个询问对应区间是否完美。

示例1

输入

7 4
1 2 2 4 3 4 5
1 1 4
2 1 7
2 6 7
2 4 7

输出

No
Yes
No

线段树

#include <bits/stdc++.h>

using namespace std;
const int maxn = 3 * 100005;

int a[maxn];
struct segtree{
    bool ok;
    int l;
    int r;
}tr[maxn << 2];

void pushup(int rt){
    tr[rt].ok = (tr[rt << 1].ok && tr[rt << 1 | 1].ok)&&(tr[rt << 1].r <= tr[rt << 1 | 1].l);
    tr[rt].l = tr[rt << 1].l;
    tr[rt].r = tr[rt << 1 | 1].r;
}

void build(int l,int r,int rt){
    if(l == r){
        tr[rt].l = tr[rt].r = a[l];
        tr[rt].ok = true;
        return ;
    }
    int mid = (l + r) >> 1;
    build(l,mid,rt << 1);
    build(mid + 1,r,rt << 1 | 1);
    pushup(rt);
}

void update(int t,int l,int r,int C,int rt){
    if(l == r){
        tr[rt].l = tr[rt].r = C;
        return ;
    }
    int mid = (l + r) >> 1;
    if(t <= mid)update(t,l,mid,C,rt << 1);
    else update(t,mid + 1,r,C,rt << 1 | 1);
    pushup(rt);
}

bool query(int L,int R,int l,int r,int rt){
    if(L <= l && r <= R){
        return tr[rt].ok;
    }
    bool ok = true;
    int mid = (l + r) >> 1;
    if(L <= mid) ok = (ok && query(L,R,l,mid,rt << 1));
    if(R > mid) ok = (ok && query(L,R,mid + 1,r,rt << 1 | 1));
    if(L <= mid && R > mid){
        ok = (ok && (tr[rt << 1].r <= tr[rt << 1 | 1].l));
    }
    return ok;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,q;
    cin >> n >> q;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    build(1,n,1);
    while(q--){
        int x;
        cin >> x;
        if(x == 1){
            int t,C;
            cin >> t >> C;
            update(t,1,n,C,1);
        }else{
            int l,r;
            cin >> l >> r;
            if(query(l,r,1,n,1)){
                cout << "Yes" << '\n';
            }else{
                cout << "No" << '\n';
            }
        }
    }

    return 0;
}


L神奇的回答https://ac.nowcoder.com/acm/contest/22352/L

题目描述

阿强对年龄问题很敏感。每当被问及年龄的时候,他总想要逃避。于是当他18岁以下的时候,别人问他多少岁,他会如实回答,当他年龄大于18时候,他会回答:18。

他坐着时光机穿越到不同的年份,他知道自己穿越后的年龄。那么当他穿越后别人问他年龄的时候他应该怎么回答呢?

输入描述:

第一行一个整数n(1≤n≤100000)。表示穿越时光机的次数。
接下来n行每行一个整数x(1≤x≤100000)表示穿越后的年龄。

输出描述:

共n行,每行一个整数表示一次穿越后回答的年龄。

示例1

输入

4
19
14
4
122

输出

18
14
4
18

签到题

#include <bits/stdc++.h>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--){
        int x;
        cin >> x;
        if(x >= 18){
            cout << 18 << '\n';
        }else{
            cout << x << '\n';

        }
    }


    return 0;
}

posted @ 2021-10-23 19:08  泥烟  阅读(74)  评论(0编辑  收藏  举报