2023团体程序设计天梯赛赛时代码

L1

最好的文档

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

#define io ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define m_p make_pair
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;

#define MAX 300050

int n, m, x, y, z, p;
int tr[MAX];
string s;

void work()
{
    cout <<"Good code is its own best documentation.";
}
int main()
{
    io;
    //int t;cin >> t;while(t--)
    work();
    return 0;
}

什么是机器学习

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

#define io ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define m_p make_pair
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;

#define MAX 300050

int n, m, x, y, z, p;
int tr[MAX];
string s;

void work()
{
    cin >> n>>m;
    n += m;
    cout <<n-16<<endl <<n-3<<endl<<n-1<<endl<<n<<endl;
}

int main()
{
    io;
    //int t;cin >> t;while(t--)
    work();
    return 0;
}

程序员买包子

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

#define io ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define m_p make_pair
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;

#define MAX 300050

int n, m, x, y, z, p, k;
int tr[MAX];
string s;

void work()
{
    cin >> n>>s>>m>>k;
    if(n == k)cout <<"mei you mai "<<s<<" de\n";
    else if(k == m)cout <<"kan dao le mai "<<s<<" de\n";
    else cout <<"wang le zhao mai "<<s<<" de\n";
}
int main()
{
    io;
    //int t;cin >> t;while(t--)
    work();
    return 0;
}

进化论

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

#define io ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define m_p make_pair
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;

#define MAX 300050

int n, m, x, y, z, p, k;
int tr[MAX];
string s;

void work()
{
    cin >> x >>y >>z;
    if(z == x*y)cout<<"Lv Yan\n";
    else if(z == x +y)cout <<"Tu Dou\n";
    else cout <<"zhe du shi sha ya!\n";
}

int main()
{
    io;
    int t;cin >> t;while(t--)
    work();
    return 0;
}

猜帽子游戏

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

#define io ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define m_p make_pair
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;

#define MAX 300050

int n, m, x, y, z, p, k;
int tr[MAX];
string s;
int ar[MAX];

void work()
{
    cin>>n;
    for(int i = 1; i <= n; ++i)cin >> ar[i];
    cin >> k;
    while(k--)
    {
        int num = 0;
        bool ans = 1;
        for(int i= 1; i <= n; ++i)
        {
            cin >> x;
            if(!x)++num;
            if(x != 0 &&x != ar[i])
            {
                ans = 0;
            }
        }
        if(ans&&num!=n)cout <<"Da Jiang!!!\n";
        else cout<<"Ai Ya\n";
    }
}

int main()
{
    io;
    //int t;cin >> t;while(t--)
    work();
    return 0;
}

剪切粘贴

这个题一开始没看到找不到就放在最后,所以调了小一会

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

#define io ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define m_p make_pair
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;

#define MAX 300050

int n, m, x, y, z, p, k;
int tr[MAX];
string s, a, b, t;

string fuck(string s, int l, int r)
{
    string pp = "";
    for(int i = l ;i <= r;++i)
    {
        pp += s[i];
    }
    return pp;
}

string ges(int l, int r)
{
    string ans = fuck(s, 0, l-1) + fuck(s, r+1, (int)s.size()-1);
    return ans;
}

void work()
{
    cin >> s >> n;
    while(n--)
    {
        cin >> x >> y >>a >>b;
        --x;--y;
        t = fuck(s, x, y);
        s = ges(x, y);
        string c = a + b;
        int id = s.find(c);
        if(id == -1)s = s + t;
        else s = fuck(s, 0, id+(int)a.size()-1) + t + fuck(s, id+a.size(), s.size()-1);
    }
    cout << s<<endl;
}

int main()
{
    //io;
    //int t;cin >> t;while(t--)
    work();
    return 0;
}

分寝室

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

#define io ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define m_p make_pair
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;

#define MAX 300050

int n, m, x, y, z, p, k;
int tr[MAX];
string s;
int a, b, c;

void work()
{
    cin >> x >>y>>n;
    int p = -1, q = -1;
    k = 1e9;
    for(int i = 1; i < n; ++i)
    {
        int j = n - i;
        if(x % i || y % j)continue;
        a = x / i;
        b = y / j;
        if(a == 1||b==1)continue;
        if(abs(a-b)<k)
        {
            k = abs(a-b);
            p = i;q=j;
        }
    }
    if(k == 1e9)cout<<"No Solution\n";
    else cout <<p <<" " <<q<<endl;
}

int main()
{
    //io;
    //int t;cin >> t;while(t--)
    work();
    return 0;
}

谁管谁叫爹

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

#define io ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define m_p make_pair
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;

#define MAX 300050

int n, m, x, y, z, p, k;
int tr[MAX];
string s;
int a, b, c;

int getsum(int x)
{
    int sum = 0;
    while(x)
    {
        sum += x %10;
        x /= 10;
    }
    return sum;
}

void work()
{
    cin >> n;
    while(n--)
    {
        cin >> x >>y;
        a  = getsum(x);
        b = getsum(y);
        if(x % b==0 && y % a)
        {
            cout << "A\n";
        }
        else if(y % a == 0 && x % b)
        {
            cout <<"B\n";
        }
        else
        {
            if(x>y)cout<<"A\n";
            else cout<<"B\n";
        }
    }
}

int main()
{
    //io;
    //int t;cin >> t;while(t--)
    work();
    return 0;
}

 

L1还是和一如既往的简单,都是要求什么写什么就行,时间主要是花在了剪切粘贴那个题上面,写完L1差不多过了45分钟

 

L2

堆宝塔

写这个题的时候以为和松针一样恶心,后来发现还好,时间主要花在了手动模拟上面,一开始没算出样例,想明白样例以后随便写写就1A了,主要是样例解释里面的第四个宝塔顺序其实很恶心,A塔从底往上是逐渐减少的,B塔从底往上是逐渐增大的,而它的样例解释写的时候都是从大到小写出的,很无语

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

#define io ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define m_p make_pair
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;

#define MAX 300050

int n, m, x, y, z, p, k;
int tr[MAX];
string s;
stack<int>a, b;

void work()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)cin>> tr[i];
    a.push(tr[1]);
    int num = 1, maxn = 1;
    for(int i = 2; i <= n; ++i)
    {
        int c = tr[i];
        if(a.top() > c)
        {
            a.push(c);
            maxn = max(maxn, (int)a.size());
        }
        else
        {
            if(b.empty()||c>b.top())
            {
                b.push(c);
            }
            else
            {
                maxn = max(maxn, (int)a.size());
                while(!a.empty())a.pop();
                ++num;
                while(!b.empty() && b.top() > c)
                {
                    a.push(b.top());
                    b.pop();
                }
                a.push(c);
            }
        }
    }
    if(b.size())++num;
    cout << num<<" "<<maxn<<endl;
}

int main()
{
    //io;
    //int t;cin >> t;while(t--)
    work();
    return 0;
}

天梯赛的赛场安排

也就是个简单的模拟题,用的是优先队列,学会优先队列的重载运算符就行

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

#define io ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define m_p make_pair
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;

#define MAX 300050

int n, m, x, y, z, p, k;
struct ran
{
    string s;
    int num;
    bool operator < (const ran&x)const{
        return num < x.num;
    }
}tr[MAX], ar[MAX];
map<string, int>fuck;
int c;

void work()
{
    cin >> n>>c;
    priority_queue<ran>q;
    for(int i =1; i <= n; ++i)
    {
        cin >> tr[i].s >> tr[i].num;
        q.push(tr[i]);
        ar[i] = tr[i];
    }
    int chang = 0;
    vector<int>v;
    while(!q.empty())
    {
        auto [s, num] = q.top();q.pop();
        //cout << s<<" "<<num<<endl;
        if(num >= c)
        {
            ++chang;
            num-=c;
        }
        else
        {
            bool p = 0;
            for(int i = 0; i < v.size(); ++i)
            {
                if(v[i] >= num)
                {
                    p = 1;
                    v[i] -= num;
                    num = 0;
                    break;
                }
            }
            if(!p)
            {
                ++chang;
                v.push_back(c-num);
                num = 0;
            }
        }
        if(num)
        {
            q.push({s,num});
        }
    }
    for(int i = 1; i <= n; ++i)
    {
        cout << ar[i].s <<" "<<(ar[i].num +c-1)/ c<<endl;
    }
    cout<<chang<<endl;
}


int main()
{
    //io;
    //int t;cin >> t;while(t--)
    work();
    return 0;
}

锦标赛

思路没问题,但是不知道为什么只有16分,以后再补吧,先放个赛时代码

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

#define io ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define m_p make_pair
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;

#define MAX 1000050

int n, m, x, y, z, p, k;
int tr[MAX];
int tot, a, b;
int ans[MAX];
vector<pii>v[30];
void work()
{
    cin >> n;
    if(n == 1)
    {
        cin >> a >> b;
        cout << a <<" "<<b<<endl;
        return;
    }
    tot = (1<<n);
    k = (1<<(n-1));
    for(int i = 1; i <= k; ++i)
    {
        cin >> tr[i*2-1];
        ans[i*2-1] = tr[i*2-1];
        v[1].push_back(m_p(tr[i*2-1],i*2));
    }
    for(int i = 2; i <= n; ++i)
    {
        k = (1<<(n-i));
        for(int j = 0; j < k; ++j)
        {
            cin >> x;
            auto [a, i1] = v[i-1][j*2];
            auto [b, i2] = v[i-1][j*2+1];
            if(x >= a)
            {
                ans[i1] = x;
                v[i].push_back(m_p(x, i2));
            }
            else if(x >= b)
            {
                ans[i2] = x;
                v[i].push_back(m_p(x, i1));
            }
            else
            {
                cout <<"No Solution\n";
                return;
            }
        }
    }
    cin >> x;
    if(x < v[n-1][1].first){
        cout << "No Soultion\n";
        return;
    }
    ans[v[n-1][1].second] = x;
    for(int i = 1; i <= tot; ++i)cout << ans[i]<<" ";
    cout<< endl;
}

int main()
{
    //io;
    //int t;cin >> t;while(t--)
    work();
    return 0;
}

寻宝图

#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define inf 0x3f3f3f3f
#define mod7 1000000007
#define mod9 998244353
#define m_p(a,b) make_pair(a, b)
#define mem(a,b) memset((a),(b),sizeof(a))
#define io ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef pair <int,int> pii;

#define MAX 300000 + 50
int n, m, k, x;
string tr[MAX];
string vis[MAX];

bool judge(int x, int y){
    if(x>n || x<1 || y>m || y<1)return false;
    else if(vis[x][y]=='1')return false;
    else if(tr[x][y]=='0')return false;
    return true;
}
bool fuck;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
void dfs(int x, int y){
    vis[x][y] = '1';
    if(tr[x][y] > '1')fuck = 1;
    for(int i = 0; i < 4; ++i){
        int xx = x + dx[i];
        int yy = y + dy[i];
        if(judge(xx, yy)){
            dfs(xx, yy);
        }
    }
}


void work(){
    cin >> n >>m;
    string p = "";
    for(int i = 1; i <= m; ++i)p+="0";
    for(int i = 1; i <= n; ++i)cin >>tr[i], tr[i] = " " + tr[i], vis[i] = p;
    int num = 0, ans = 0;
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= m; ++j){
            if(judge(i, j)){
                fuck = 0;
                dfs(i, j);
                ++num;
                if(fuck)++ans;
            }
        }
    }
    cout << num << " " <<ans << endl;
}

int main(){
    io;
    work();
    return 0;
}

 

先写的L2-1,L2-2,看了一眼榜,发现L2-3过的多,就去做L2-3,看到L2-3的时候直接骂了一句傻逼题,然后就秒了,这个时候比赛才开始一个半小时,已经175分了,就闲的没事开始看榜,发现学校目前的最高分,大家人均一百多点,然后心态就放平了,毕竟国三打底,就开始看L2-3,读的慢,写的也挺慢的,感觉思路没问题,但是不知道为什么没满分,也懒得思考,就去看L3了,那个时候L3-1过了2个人,L3-3过了0个人,果断去看L3-2了

 

L3

完美树

看了一眼发现是个树形dp,又思路但是憋了半天没写出来,遂写了个小范围的二进制枚举,过了15分,然后把二进制枚举换成了二进制的随机枚举,骗了17分,下班

后来听说输出20就能得15分,好离谱

放个随机枚举的暴力吧

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

#define io ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define m_p make_pair
#define endl '\n'
#define int long long
typedef long long ll;
typedef pair<int,int> pii;

#define MAX 1000050

int n, m, x, y, z, p, k;
int tr[MAX];
vector<int>G[MAX];
int col[MAX];
int cost[MAX];
int cc[MAX];
bool cao;
int dfs(int u)
{
    if(cao)return -2;
    int num = cc[u] == 0 ? 1 : -1;
    for(auto v : G[u])
    {
        int p = dfs(v);
        if(cao)return -2;
        num += p;
    }
    if(num >= -1 && num <= 1)return num;
    else {
        cao = 1;
        return -2;
    }
}

void work()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
    {
        cin >> col[i] >> cost[i]>>k;
        while(k--)
        {
            cin >> x;
            G[i].push_back(x);
        }
    }
    set<int>se;
    int caonim = 100000;
    int ans = 1e9;
    while(caonim--)
    {
        int i = rand()%1000000000000000ll;
        if(se.count(i))continue;
        else
        {
            se.insert(i);
            int hua = 0;
            for(int j = 0; j < n; ++j)
            {
                if((i>>j)&1)
                {
                   // cout << j+1 <<" " << cost[j+1]<<endl;
                    hua+=cost[j+1], cc[j+1] = (col[j+1] ^ 1);

                }
                else cc[j+1] = col[j+1];
                   // cout<<j<<" ";
            }
            cao = 0;
            dfs(1);;
            if(cao)continue;
            else ans = min(ans, hua);
        }
    }
    if(ans == 1e9)cout << 0 << endl;
    else cout << ans << endl;
}


signed   main()
{
    io;
    //int t;cin >> t;while(t--)
    work();
    return 0;
}


 

博客内容均系原创,未经允许严禁转载!
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇