首页 > 其他分享 >上海月赛2020年5月

上海月赛2020年5月

时间:2024-07-12 10:21:09浏览次数:7  
标签:月赛 cnt return int 上海 else 2020 ans include

丙组T1:https://www.iai.sh.cn/problem/52

#include <bits/stdc++.h>
using namespace std;

//枚举法
int main()
{
    int n;
    cin >> n;
    int cnt = 10;
    int day = 3; //星期
    for(int i = 1; ; i++) //枚举天
    {
        cnt--; //每天消耗一个口罩
        if(day == 1 || day == 2) cnt += 7; //周一周二都会新增7个口罩
        if(cnt == n)
        {
            cout << i;
            break;
        } 
        day = (day + 1) % 7;
    }
    return 0;
}

丙组T2:https://www.iai.sh.cn/problem/51

#include <bits/stdc++.h>
using namespace std;

double point(char c)
{
    if(c == 'A') return 4;
    else if(c == 'B') return 3;
    else if(c == 'C') return 2;
    else if(c == 'D') return 1;
    else if(c == '+') return 0.3;
    else if(c == '-') return -0.3;
}

double ans;
int cnt;

int main()
{
    char c;
    while(cin >> c)
    {
        ans += point(c);
        if(c >= 'A' && c <= 'D') cnt++;
    }
    printf("%.2f", ans / cnt);
}

丙组T3:https://www.iai.sh.cn/problem/32

#include <bits/stdc++.h>
using namespace std;

int n, m;
char c[105][105];

int dx[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy[8] = {-1, -1, -1, 0, 1, 1, 1, 0};

int main()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            cin >> c[i][j];
    
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            int cnt = 0;
            for(int k = 0; k < 8; k++)
            {
                int nx = i + dx[k];
                int ny = j + dy[k];
                if(nx < 1 || nx > n || ny < 1 || ny > m) continue;
                if(c[nx][ny] == '*') cnt++;
            }
            if(c[i][j] == '*') cout << '*';
            else cout << cnt;
        }
        cout << endl;
    }
    return 0; 
}

丙组T4:https://www.iai.sh.cn/problem/31

#include <bits/stdc++.h>
using namespace std;

int s, t, ans;

int main()
{
    cin >> s >> t;
    //正着做不好做,因为s不一定每次都是乘2更好,有可能+1再乘2更好,比如样例2
    //倒过来做,从t减1或除以2变成s
    while(s < t)
    {
        if(t % 2 == 1) t--, ans++; //如果t是奇数,只能减1
        else if(t / 2 >= s) t /= 2, ans++; //如果t/2还不小于s,就除以2
        else break; //t距离s不能除以2,只能一个个减,循环减有可能会超时
    }
    ans += t - s; //加上最后要减1的次数
    cout << ans;

    return 0;
}

丙组T5:https://www.iai.sh.cn/problem/44

#include <bits/stdc++.h>
using namespace std;

const int N = 100005;
int n;
int a[N];
int maxa[N]; //maxa[i]存a[1]~a[i]的最大值
int mina[N]; //mina[i]存a[n]~a[i]的最小值
int ans;

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];

    maxa[1] = a[1];
    for(int i = 2; i <= n; i++) 
        maxa[i] = max(maxa[i - 1], a[i]);
    
    mina[n] = a[n];
    for(int i = n - 1; i >= 1; i--)
        mina[i] = min(mina[i + 1], a[i]);
    
    for(int i = 1; i <= n; i++)
    {
        ans = max(ans, maxa[i] - mina[i]);
    }

    cout << ans;
    
    return 0;
}

 

标签:月赛,cnt,return,int,上海,else,2020,ans,include
From: https://www.cnblogs.com/jcwy/p/18297716

相关文章

  • 上海月赛2020年4月
    丙组T1:https://www.iai.sh.cn/problem/24#include<bits/stdc++.h>usingnamespacestd;intmain(){inta,b,c,d;cin>>a>>b>>c>>d;intcnt=0;if(a>=90)cnt++;if(b>=90)cnt++;if(c......
  • 上海月赛2020年3月
    丙组T1:https://www.iai.sh.cn/problem/17#include<bits/stdc++.h>usingnamespacestd;intmain(){intn;cin>>n;n%=5;if(n>=1&&n<=3)cout<<"Fishing";elsecout<<"Lying......
  • 信息学奥赛初赛天天练-43-CSP-J2020基础题-链表、连通图、2进制转10进制、栈、队列、
    PDF文档公众号回复关键字:202407102020CSP-J选择题单项选择题(共15题,每题2分,共计30分:每题有且仅有一个正确选项)7.链表不具有的特点是()A.可随机访问任一元素B.不必事先估计存储空间C.插入删除不需要移动元素D.所需空间与线性表长度成正比8.有10个顶点的无向图至少......
  • 利用 ECharts 地图:实现纹理和图像的效果(上海json)
    注:shanghaiGeoJSON换为你需要的区域json<template><divref="mapContainer"style="width:100%;height:500px"></div></template>import*asechartsfrom'echarts';importshanghaiGeoJSONfrom'@/assets......
  • Matebook14 2020款 更换固态(全流程)
    Matebook142020款更换固态全流程因为工作的原因需要升级存储,我的老款的Matebook14只有512G。网络上的中文教程普遍比较古老。特此写下这篇笔记希望能帮助到有需要的朋友。工具螺丝刀(四花00和六花T4)新的固态硬盘U盘(容量不小于1G)移动硬盘(容量不能小于你的系统镜像)操作流......
  • Xilinx Vitis 2020工程源目录修改
    目录1背景2分析3解决4使用4.1修改路径4.2编译工程4.2.1清理工程4.2.2编译工程1背景  XilinxVitis可以做standalone程序开发,不过其工程中使用的路径为绝对路径。工程更换位置后编译将会显示错误。例如:源目录为D:/work,复制到同事电脑上放到C:/work(同......
  • 阅读笔记《GB/T 22240-2020信息安全技术 网络安全等级保护定级指南》
    等级保护对象:网络安全等级保护工作直接作用的对象。主要包括信息系统、通信设施和数据资源等。定级流程:确定定级对象、初步确定等级、专家评审、主管部门核准、备案审核作为定级对象的信息系统应具有如下基本特征:(1)具有确定的主要安全责任主体;(2)承载相对独立的业务系统;(3)包含相互......
  • c9024 上海
    ![](https://img2024.cnblogs.com/blog/2915477/202407/2915477-20240707135003574-1982592306.png)      网络安全C4期课程                                     ......
  • 沪越联赛 - 2024年6月月赛Div2 题解
    问题A:替换题目描述小明每次注释的时候都写\(n\)个/。小红看了小明的程序,觉得太难看了,那么多/,所以决定把这些没用的/都去掉。小红定义了一个宏命令,每次可以将所有连续的\(m\)个/替换成空(注意不是空格)小明得知了小红的企图后非常着急,因为他知道光把/都去掉,那么原......
  • 上海网站建设如何做
    上海是中国最繁华的城市之一,作为全国的经济、文化和科技中心,网站建设在上海变得越来越重要。如何做好上海网站建设,让网站更加吸引人,成为企业和个人宣传自身的重要平台呢?首先,要有清晰的定位和目标。在进行上海网站建设之前,要明确网站的定位和目标受众。是为了企业宣传品牌,还是......