“九韶杯”河科院程序设计协会第一届程序设计竞赛ABCFDEI

A.6的个数 

问我们1~2021里面一共有几个六?

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string>
#include<map>
using namespace std;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int sum=0;
    for(int i=1;i<=2021;i++)
    {
        string s=to_string(i);
        for(int i=0;i<s.size();i++)
            if(s[i]=='6') sum++;
        s.clear();
    }
    cout<<sum<<endl;
    return 0;
}

B.小明的作业

求警告(wa,aw)和错误次数(wawawa...awaw....)。

iawaswapwauawhawdwafwanbiopwanivgbikvblvbwawawawvolyuvgbololvolgbyolgyowagbolgawgbo
 1   2  3  4  5  6  7      8             +1                             9      10
plwawaolgyolwaogblwaygbowawagwabwayawopwawagyowabwaowapjwapcfrtuywawacvujwawawauftt
  +2         11    12     +3   13 14 15  +4      16 17 18  19        +5       +6
yfuftywawawatifgugbgbyguwawawawayugbigwwwytigwygwgbwyoawawgoghwaogwborgrewabouyhwab
      +7                 +8                             +9       20         21     22
yuhowabhnwawauygbawyawuwaoawfcawaaaahwaywauwagwawefwaafmbawklawjiawihnwanhawawawawi
    23    +10      24 25 26 27   28    29 30 31 32   33    34  35  36   37  +11
jwajiofjeriofgjrefjhwaewarwaowagwahwauwaiwarwaiwaqwarwahwaqwawwaowapfweofbwewafwahwa
 38                 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54         55 56 57
iwaewawwawawawawafwawawawaeiufwepfhnewfwahwajwatwafowawajtokshwawafwaiwahwafwahmgo
 58 59 +12          +13                    60 61 62 63  +14         +15    64 65 66 67
ewawawawafkfjkewnwawafiewhfwawawafjkernhawkrenwawawawafujnrheiowanwakawawawawwanoif
  +16              +17          +18           68     +19               69 70 +20       71
ewajrwaoawawfweojnwawawawawawawafjkwenawawferkwmpwawawawaforeijawawferhfiueorghwuwa
 72  73 +21         +22                   +23          +24             +25                 74
fguwegfwaghrwiufgwahweofgowaidwiweaiwwawieyiwe
       75        76       77         78

嘻嘻嘻嘻嘻··· 

(我这么做风险好大哇感觉,昨晚的找字母就秀没了给我🤯)

#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
    cout<<"78"<<endl;
    cout<<"25"<<endl;
    return 0;
}

C.斐波那契

前13项由斐波那契数列(1,1,2,3,5.......)两两相邻数字相乘取倒数组成,求这13项的和(写成分子分母形式)。

这个题目在天梯赛L1有个超级类似的:) 

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string>
#include<map>
using namespace std;
typedef long long LL;
LL a[200200]={0},b[200200];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    a[1]=1;
    a[2]=1;
    a[3]=2;
    for(LL i=3;i<=20;i++)
        a[i]=a[i-1]+a[i-2];
    for(LL i=1;i<14;i++) b[i]=a[i]*a[i+1];
    LL m=0,n=1;
    LL flag;
    for(LL i=1;i<4;i++)
    {
        //cout<<b[i]<<" ";
        LL t=n;
        n=b[i]*n/__gcd(b[i],n);//底边
        m=m*n/t+1*n/b[i];   //高
        flag=__gcd(m,n);
        m=m/flag;
        n=n/flag;
    }
    flag=__gcd(m,n);
    //cout<<m<<"/"<<n<<endl;
    cout<<m/flag<<"/"<<n/flag<<endl;
    return 0;
}

F.字符串

给定n行字符串,问有几个含有@wyk?

0—n

多留出一行给getline

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string>
#include<map>
using namespace std;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int sum=0;
    int n;
    cin>>n;
    for(int i=0;i<=n;i++)
    {
        string s;
        getline(cin,s);
        for(int i=0;i<s.size();i++)
            if(s[i]=='@'&&s[i+1]=='w'&&s[i+2]=='y'&&s[i+3]=='k')
            {
                sum++;
                break;
            }
        s.clear();
    }
    cout<<sum<<endl;
    return 0;
}

 4题打铁。。。大题不咋会

开始补题:

参考:“九韶杯”河科院程序设计协会第一届程序设计竞赛(C++题解)_河林山的博客-CSDN博客

这位佬写的是真不错哇!

D.数列重组

小明同学最近喜欢上了排列组合,但是现在有这样的一道题把他难住了,已知有一组数字(2,5,3,6,3,6,7,3,7,8)共10个,对于这组数字进行排列后,可以将排列好的数字分为三个部分,且三个部分都是分别有序的(升序或逆序),小明想知道能够有满足条件的多少种排列方式?

//(2, 3, 3, 3, 5, 6, 6, 7, 7, 8)
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string>
using namespace std;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int a[20];
    a[1]=2;
    a[2]=3;
    a[3]=3;
    a[4]=3;
    a[5]=5;
    a[6]=6;
    a[7]=6;
    a[8]=7;
    a[9]=7;
    a[10]=8;
    int sum=0;
    //int ans=0;
    do
    {
        //ans++;
        int flag=0;//0表示转折点,可以上升也可以下降
        int idx=0;//一定要在此处划分的个数
        for(int i=2;i<=10;i++)
        {
            if(a[i]>a[i-1])//升序的时候
            {
                if(flag==-1)//如果刚刚是从降序来的,eg:7 6 5 7
                {
                    idx++;
                    flag=0;
                }
                else flag=1;//如果是转折点或者升序上来的
            }
            else if(a[i]<a[i-1])//降序
            {
                if(flag==1)//如果是从升序上来的时候
                {
                    idx++;
                    flag=0;
                }
                else flag=-1;//如果是从转折点或者降序上来的时候
            }
        }
        if(idx<=2) sum++;//超过2段必须划分的时候,那就不符合题意了

    }while(next_permutation(a+1,a+1+10));
    //cout<<ans<<endl;
    cout<<sum<<endl;
    return 0;
}

E.三角形个数

坤坤给你一个边长为n的等边三角形图形,请你查出图形内等边三角形的个数。

因为数据过大,所以要求答案对1e9+7取模。

n=2的三角形阵列时,我们可以看出有5个三角形。

请输出n为20210411时的三角形的个数。

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long LL;
const LL mod=1e9+7;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    //正三角形的个数
    LL sum1=0;
    for(LL i=1;i<=20210411;i++)//因为正三角形它从第一行到最后一行都有构成,所以必须一直加上
        sum1+=(i+1)*i/2%mod;//符合等差数列公式n*(1+n)/2
    //倒三角形的个数
    LL sum2=0;
    for(LL i=2;i<=20210411;i+=2)//因为倒三角形在三角形顶端的时候只存在一个正三角形,所以倒三角形回比正三角形少一个
        sum2+=(i+1)*i/2%mod;
    cout<<(sum1+sum2)%mod<<endl;
    return 0;
}

G.最强对手矩阵

4个for卡的太狠了,代码都跑不动了,还需要再优化优化

H.没整出来呜呜,下午再来补

I.传送门

一共N个城市,要求建设M条道路。求N的点都可以相互传送的时侯的最短时间。

如果无法完成任务,则输出-1。

注意:A市与B可以利用C中转,可以算互相传送。只要达到N座城市可以互相传送的目的就可以,所以规划资料不一定全部建设。

竟然是Kruskal模板题欸!为嘛写的时候没看到

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
using namespace std;
int father[200200];
int n,m;
int sum=0;
struct node
{
    int x,y,z;
}a[200200];
bool cmp(node l,node r)
{
    return l.z<r.z;
}
int find(int x)
{
    if(father[x]!=x) father[x]=find(father[x]);
    return father[x];
}
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=1;i<=m;i++)
        cin>>a[i].x>>a[i].y>>a[i].z;
    sort(a+1,a+1+m,cmp);
    //for(int i=1;i<=m;i++) cout<<a[i].x<<" "<<a[i].y<<" "<<a[i].z<<endl;
    //并查集初始化
    for(int i=1;i<=n;i++)
        father[i]=i;
    for(int i=1;i<=m;i++)
    {
        if(find(a[i].x)!=find(a[i].y))
        {
            sum++;
            father[find(a[i].x)]=find(a[i].y);
        }
        if(sum==n-1)
        {
            cout<<a[i].z<<endl;
            break;
        }
    }
    if(sum!=n-1) cout<<"-1"<<endl;
    //for(int i=1;i<=n;i++) cout<<father[i]<<" ";
    return 0;
}

J好难哦,弃了弃了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Vijurria

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值