2020天梯赛部分代码

这次天梯赛打的总的来说十分不满意。。。还不如平时训练的好,l2的那道树都把我给卡了。。。而且这次总有莫名其妙的点wa掉了,如果这是acm赛制,怕是全部过不了哦。。。 自己还是太菜了 摸鱼也略多 昨晚愣是打了一个晚上的酒馆战旗。。。 还是加紧训练吧
找不到题面。。。 以后再补吧 顺便把思路补了。。。
1-1 比a+b还要简单 不上代码了
1-2 简单计算体积
1-3

#include<bits/stdc++.h>
using namespace std;
int main()
{
    double a,c;
    int b;
    cin >> a >> b >> c;
    if(b==1)
    {
        a *= 1.26;
    }
    else
        a *= 2.455;
    printf("%.2f ", a);
    if(a>c)
        cout << "T_T";
    else
        cout << "^_^";
    return 0;
}

1-4

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5 + 5;
double x[maxn];
int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n;i++)
    {
        double t;
        cin >> t;
        x[i] = 1 / t;
    }
    double ans = 0;
    for (int i = 1; i <= n;i++)
    {
        ans += x[i];
    }
    ans /= n;
    printf("%.2f", 1 / ans);
    return 0;
}

1-5

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5 + 5;
int x[5];
int main()
{
    int max1 = -1;
    for (int i = 1; i <= 4;i++)
    {
        cin >> x[i];
        max1 = max(x[i], max1);
    }
    int e, f;
    cin >> e >> f;
    int ans = 0;
    for (int i = 1; i <= 4;i++)
    {
        if(x[i]<e)
            ans++;
        if(abs(x[i]-max1)>f)
            ans++;
    }
    if(ans==0)
        cout << "Normal";
    else if(ans>=2)
    {
        cout << "Warning: please check all the tires!";
    }
    else 
    {
        cout << "Warning: please check #";
        for (int i = 1; i <= 4;i++)
        {
            if(x[i]<e)
            {
                cout << i;
                break;
            }
            if(abs(x[i]-max1)>f)
            {
                cout << i;
                break;
            }
        }
        cout << "!";

    }
        return 0;
}

1-6 wa一个点 离谱

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5 + 5;
int main()
{
    string s;
    getline(cin, s);
    int ans1 = 0, sum = 0, m = 0;
    while(s!=".")
    {
        ans1++;
        string s1 = "chi1 huo3 guo1";
        for (int i = 0; i < s.size();i++)
        {
            if(s[i]=='c')
            {
                int ans = 0, f = 0;
                for (int j = i; j < s.size();j++)
                {
                    if(s[j]==s1[ans])
                    {
                        ans++;
                    }
                    else 
                    {
                        break;
                    }
                    if(ans==s1.size())
                    {
                        f = 1;
                        break;
                    }
                }
                if(f==1)
                {
                    if(sum==0)
                    {
                        m = ans1;
                        sum++;
                    }
                    else
                        sum++;
                }
            }
        }
        getline(cin, s);
    }
    cout << ans1 << endl;
    if(sum==0)
    {
        cout << "-_-#";
        return 0;
    }
    cout << m << " " << sum;
    return 0;
}

1-7 wa一个点

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5 + 5;
int main()
{
    int n, m;
    cin >> n >> m;
   
    for (int i = 1; i <= m;i++)
    { getchar();
        string s;
        cin >> s;
        ll ans = 1;
        for (int j = 0; j < s.size();j++)
        {
            if(s[j]=='y')
                ans *= 2;
            else
                ans *= 2, ans++;
        }
        cout << ans-pow(2,n)+1 << endl;
    }
    //cout << pow(2, 31);
    return 0;
}

1-8

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5 + 5;
int x[5][5];
int y[5][5];
int f[11] = {0};
int z[19] = {10000, 36, 720, 360, 80, 252, 108, 72, 54, 180, 72, 180, 119, 36, 306, 1080, 144, 1800, 3600};
int main()
{
    for (int i = 1; i <= 3;i++)
    {
        for (int j = 1; j <= 3;j++)
        {
            cin >> x[i][j];
            f[x[i][j]] = 1;
        }
    }
    for (int i = 1; i <= 3;i++)
    {
        for (int j = 1; j <= 3;j++)
        {
            if(x[i][j]==0)
            {
                for (int k = 1; k <= 9;k++)
                {
                    if(f[k]==0)
                    {
                        x[i][j] = k;
                        y[i][j] = 1;
                    }
                }
            }
        }
    }
    for (int i = 1; i <= 3;i++)
    {
        int a, b;
        cin >> a >> b;
        y[a][b] = 1;
        cout << x[a][b] << endl;
    }
    int k;
    cin >> k;
    for (int i = 1; i <= 3;i++)
    {
        for (int j = 1; j <= 3;j++)
        {
            y[i][j] = 1;
        }
    }
        if (k == 1 || k == 2 || k == 3)
        {
            int ans = 0;
            for (int i = 1; i <= 3; i++)
            {
                if (y[k][i] == 1)
                {
                    ans += x[k][i];
                }
            }
            // cout << ans;
            cout << z[ans - 6];
        }
        else if (k == 4 || k == 5 || k == 6)
        {
            k -= 3;
            int ans = 0;
            for (int i = 1; i <= 3; i++)
            {
                if (y[i][k] == 1)
                {
                    ans += x[i][k];
                }
            }
            //cout << ans;
            cout << z[ans - 6];
        }
        else if (k == 7)
        {
            int ans = 0;
            for (int i = 1; i <= 3; i++)
            {
                if (y[i][i] == 1)
                {
                    ans += x[i][i];
                }
            }
            //cout << ans;
            cout << z[ans - 6];
        }
        else
        {
            int ans = 0;
            if (y[3][1] == 1)
                ans += x[3][1];
            if (y[2][2] == 1)
                ans += x[2][2];
            if (y[1][3] == 1)
                ans += x[1][3];
            //cout << ans;
            cout << z[ans - 6];
        }
    return 0;
}

2-1

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5 + 5;
int x[5][5];
int y[5][5];
int f[11] = {0};
int z[19] = {10000, 36, 720, 360, 80, 252, 108, 72, 54, 180, 72, 180, 119, 36, 306, 1080, 144, 1800, 3600};
int main()
{
    for (int i = 1; i <= 3;i++)
    {
        for (int j = 1; j <= 3;j++)
        {
            cin >> x[i][j];
            f[x[i][j]] = 1;
        }
    }
    for (int i = 1; i <= 3;i++)
    {
        for (int j = 1; j <= 3;j++)
        {
            if(x[i][j]==0)
            {
                for (int k = 1; k <= 9;k++)
                {
                    if(f[k]==0)
                    {
                        x[i][j] = k;
                        y[i][j] = 1;
                    }
                }
            }
        }
    }
    for (int i = 1; i <= 3;i++)
    {
        int a, b;
        cin >> a >> b;
        y[a][b] = 1;
        cout << x[a][b] << endl;
    }
    int k;
    cin >> k;
    for (int i = 1; i <= 3;i++)
    {
        for (int j = 1; j <= 3;j++)
        {
            y[i][j] = 1;
        }
    }
        if (k == 1 || k == 2 || k == 3)
        {
            int ans = 0;
            for (int i = 1; i <= 3; i++)
            {
                if (y[k][i] == 1)
                {
                    ans += x[k][i];
                }
            }
            // cout << ans;
            cout << z[ans - 6];
        }
        else if (k == 4 || k == 5 || k == 6)
        {
            k -= 3;
            int ans = 0;
            for (int i = 1; i <= 3; i++)
            {
                if (y[i][k] == 1)
                {
                    ans += x[i][k];
                }
            }
            //cout << ans;
            cout << z[ans - 6];
        }
        else if (k == 7)
        {
            int ans = 0;
            for (int i = 1; i <= 3; i++)
            {
                if (y[i][i] == 1)
                {
                    ans += x[i][i];
                }
            }
            //cout << ans;
            cout << z[ans - 6];
        }
        else
        {
            int ans = 0;
            if (y[3][1] == 1)
                ans += x[3][1];
            if (y[2][2] == 1)
                ans += x[2][2];
            if (y[1][3] == 1)
                ans += x[1][3];
            //cout << ans;
            cout << z[ans - 6];
        }
    return 0;
}

2-2 16分 大模拟写的头疼。。。

#include<bits/stdc++.h>
#define ll long long
#define pr pair<string,int> 
using namespace std;
const int maxn = 1e5 + 5;
struct node
{
    string s, s1;
    int a, b, c;
} e[maxn];
node ren[maxn];
int ans1 = 0;
vector<pr> q;
bool cmp(node a,node b)
{
    if(a.b!=b.b)
        return a.b < b.b;
    return a.c < b.c;
    
}
int main()
{
    int n, p;
    cin >> n >> p;
    for (int i = 1; i <= n;i++)
    {
        int a, b;
        cin >> a >> b;
        for (int j = 1; j <= a;j++)
        {
            getchar();
            cin >> e[j].s >> e[j].s1;
            scanf("%d %d:%d", &e[j].a, &e[j].b, &e[j].c);
        }
        sort(e + 1, e + 1 + a, cmp);
        int ans = 0;
        for (int j = 1; j <= a;j++)
        {
            if(e[j].s1.size()==18&&e[j].a==1)
            {
                int f1 = 1;
                for (int k = 0; k < ans1;k++)
                {
                    if(ren[k].s1==e[j].s1)
                    {
                        f1 = 0;
                    }
                }
                if(f1)
                {
                    ren[ans1].s = e[j].s;
                    ren[ans1++].s1 = e[j].s1;
                }
            }
            int f = 1;
            for (int k = 0; k < q.size();k++)
            {
                string t = q[k].first;
                if(t==e[j].s1)
                {
                    //cout << e[j].s1 << " 111" << endl;
                    if(i-q[k].second>p)
                    {
                        f = 1;
                    }
                    else 
                    {
                        f = 0;
                    }
                }
            }
            if(f&&e[j].s1.size()==18)
            {
                cout << e[j].s << " " << e[j].s1 << endl;
                q.push_back({e[j].s1, i});
                
                ans++;
            }
            if(ans==b)
            {
                break;
            }
        }
    }
    for (int i = 0; i < ans1;i++)
    {
        cout<<ren[i].s<<" "<<ren[i].s1<<endl;
    }
    return 0;
}

2-3 膜拜龙哥 orz

#include<bits/stdc++.h>
#define ll long long
#define pr pair<string,int> 
using namespace std;
const int maxn = 1e5 + 5;
int x[maxn];
int y[maxn];
int z[maxn];
int n, cnt = 1;
void dfs(int t)
{
    if(t>n) return ;
    int l = t * 2;
    int r = t * 2 + 1;
    dfs(l);
    dfs(r);
    y[t] = x[cnt++];

}
int main()
{
    cin >> n;
    for (int i = 1; i <= n;i++)
    {
        cin >> x[i];
    }
    dfs(1);
    for (int i = 1; i < n;i++)
    {
        cout << y[i] << " ";
    }
    cout << y[n];
    return 0;
}

2-4 22分 wa了一个点 有一说一 我把这道题想复杂了 就很烦 最后纯暴力写的。。。

#include<bits/stdc++.h>
#define ll long long
#define pr pair<string,int> 
using namespace std;
const int maxn = 1e5 + 5;
int x[205][205];
int z[205];
int y[20005];
int n, m;
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        x[a][b] = c;
        x[b][a] = c;
    }
    int t;
    cin >> t;
    int min1 = 1e9 + 5, sum = 0, ans1 = 0;
    for (int k = 1; k <= t;k++)
    {
        int p;
        cin >> p;
        int f = 1;
        memset(z, 0, sizeof(z));
        for (int i = 1; i <= p;i++)
        {
            cin >> y[i];
            z[y[i]]++;
        }
        for (int i = 1; i <= n;i++)
        {
            if(z[i]!=1)
            {
                f = 0;
                break;
            }
        }
        if(!f)
            continue;
        int ans = 0;
        int t = 0;
        
        for (int i = 1; i <= p;i++)
        {
            ans += x[t][y[i]];
            t = y[i];
        }
        if(x[t][0]==0)
        {
            continue;
        }
        ans += x[t][0];
        //cout << k << endl;
        sum++;
        if(ans<min1)
        {
            min1 = ans;
            ans1 = k;
        }
    }
    cout << sum << endl;
    cout << ans1 <<" "<< min1;
    return 0;
}

3-1 骗了下分 15 奈何没算进去。。。

#include<bits/stdc++.h>
#define ll long long
#define pr pair<string,int> 
using namespace std;
const int maxn = 1e5 + 5;
int x[505][505];
int n, m, a, b, ans = 0;
int f[505] = {0};
void dfs(int t)
{
    f[t] = 1;
    if(t==b)
    {
        ans++;
        return;
    }
    for (int i = 1; i <= n;i++)
    {
        if(x[t][i])
        {
            //cout << i << endl;
            dfs(i);
        }
    }
}
int main()
{
    
    cin >> n >> m;
    for (int i = 1; i <= m;i++)
    {
        int a, b;
        cin >> a >> b;
        x[a][b] = 1;
    }
    cin >> a >> b;
    dfs(a);
    cout << ans<<" Yes";
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值