首页 > 其他分享 >2024 上海CCPC

2024 上海CCPC

时间:2024-09-12 18:48:43浏览次数:1  
标签:cnt hash 荷叶 int 上海 CCPC 2024 ++ hi

The 2024 Shanghai Collegiate Programming Contest
补题连接:https://codeforces.com/gym/105229


M. 不共戴天

观察样例2,注意到6个荷叶两两分成一组,共分为3组
(1,2)(3,4)(5,6)
其中对于青蛙的策略是组内全部连接,即:
m = 3:1->2,3->4,5->6
鸟的策略是,相邻组相连,即:
m = 4:1->3,2->4,3->5,4->6

猜想均匀分组(每组荷叶数量相同)是最优解。
设共有n个荷叶,每组包含k个荷叶,则共分为 t = ⌈n / k⌉ 组

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int fk = 0, ff = 0;
    for(int k = 2; k < n; ++ k)
    {
        int t = (n + k - 1) / k; // t blocks
        int l = (n % k == 0 ? k : n % k); // last block
        int frog = (t - 1) * (k - 1) + (l - 1);
        int bird = (t >= 2 ? (t - 2) * k : 0) + l;
        if(bird >= frog) fk = k, ff = frog;
        else break;
    }
    if(fk == 0)
    {
    	cout << 0 << endl;
    	return 0;
	}
    cout << ff << endl;
    // print
    int t = (n + fk - 1) / fk;
    int l = (n % fk == 0 ? fk : n % fk);
    for(int i = 1; i <= t - 1; ++ i)
        for(int j = 1; j < fk; ++ j)
        {
            int fir = (i - 1) * fk + j;
            cout << fir << " " << fir + 1 << endl;
        }
    for(int j = 1; j < l; ++ j)
    {
        int fir = (t - 1) * fk + j;
        cout << fir << " " << fir + 1 << endl;
    }
    
    int cnt = 1;
    for(int i = 1; i <= t - 2 && cnt <= ff; ++ i)
        for(int j = 1; j <= fk && cnt <= ff; ++ j, ++ cnt)
        {
            int fir = (i - 1) * fk + j;
            cout << fir << " " << fir + fk << endl;
        }
    for(int j = 1; j <= l && cnt <= ff; ++ j, ++ cnt)
    {
        int fir = (t - 2) * fk + j;
        cout << fir << " " << fir + fk << endl;
    }
    
    return 0;
}

E. 无线软件日

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    map<char,int> hash;
    for(char hi : s)
    {
        if(hi == 's' || hi == 'S') hash['s']++;
        if(hi == 'h' || hi == 'H') hash['h']++;
        if(hi == 'a' || hi == 'A') hash['a']++;
        if(hi == 'n' || hi == 'N') hash['n']++;
        if(hi == 'g' || hi == 'G') hash['g']++;
        if(hi == 'i' || hi == 'I') hash['i']++;
    }
    int cnt = 9999999;
    for(auto hi : hash)
    {
        if(hi.first == 'h' || hi.first == 'a') cnt = min(cnt,hi.second/2);
        else cnt = min(cnt,hi.second);
    }
    cout << (cnt == 9999999 ? 0 : cnt) << endl;
    return 0;
}

J. 极简合数序列
前缀和暴力

#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int arr[N], s[N];
inline bool is_heshu(int x)
{
    if(x <= 2) return false;
    for(int i = 2; i <= x / i; ++ i)
        if(x % i == 0) return true;
    return false;
}
void solve()
{
    int n;
    scanf("%d",&n);
    for(int i = 1; i <= n; ++ i)
    {
        scanf("%d",&arr[i]);
        s[i] = s[i - 1] + arr[i];
    }
    for(int k = 1; k <= n; ++ k)
        for(int i = 1; i <= n - k + 1; ++ i)
            if(is_heshu(s[i + k - 1] - s[i - 1]))
            {
                printf("%d\n",k-1);
                return;
            }
    printf("-1\n");
}
int main()
{
    int t;
    cin >> t;
    while(t --){
        solve();
    }
    return 0;
}

标签:cnt,hash,荷叶,int,上海,CCPC,2024,++,hi
From: https://www.cnblogs.com/Frodnx/p/18410807

相关文章

  • 2024年9月11日(k8s环境配置)
    编号主机名称ip1k8s-master192.168.8.2022k8s-node1192.168.8.2033k8s-node2192.168.8.204 1、做免密[root@k8s-master~]#ssh-keygen[root@k8s-master~]#[email protected][root@k8s-master~]#[email protected]、yum源(三台主......
  • 2024年9月12日(k8s环境及测试 常用命令)
    一、环境准备及测试1、报错处理:kube-systemcalico-node-5wvln0/1Init:0/3016hkube-systemcalico-node-d7xfb0/1Init:0/3016hkube-system......
  • solidworks案例3-20240910
    使用到的命令:扫描,薄壁特征,等距实体......
  • 2024.08.25拼多多
    1.树中删边多多有一颗n个节点的树,树中每一条边都有一个权值。多多还有一个长度为n的正整数序列:删除树中若干条边之后(或者不删),就会变成一个有x个连通块的图,此时的得分为:剩余边权和+((两个可以互相到达的节点属于同一个连通块,注意一个孤点也是一个连通块)多多可以删除图中......
  • 2024年该怎么写增删改查
    校验总结:快速失败校验放最外层节省内存xml都加条件标签然后其他的校验都根据业务以及具体情况来没有业务的时候要有空指针的校验避免空指针问题校验的细节见 该如何做参数校验-稳健国国王-博客园(cnblogs.com)魔法值问题建枚举类入参问题post请求put请求必须用@RequestBod......
  • 基于Java的共享经济背景下校园闲置物品交易平台(2024最新,原创项目)
    文章目录1.前言2.系统演示录像3.论文参考4.代码运行展示图5.技术框架5.1SpringBoot技术介绍5.2Vue技术介绍6.可行性分析7.系统测试7.1系统测试的目的7.2系统功能测试8.数据库表设计9.代码参考10.数据库脚本11.找我做程序,有什么保障?12.联系我们1.前......
  • 2024.09.12 1749版
    起于《海奥华预言》的思考◆地球管理结构和参考持续更新中...... 英文地址:https://github.com/zhuyongzhe/Earth/tags中文地址:https://www.cnblogs.com/zhuyongzhe85作者:朱永哲 ---------------------------------------------------------------------------------......
  • 2024最详细pycharm安装教程+最新pycharm专业版激活码
    一、Pycharm激活激活码(复制粘贴即可)KQ8KMJ77TY-eyJsaWNlbnNlSWQiOiJLUThLTUo3N1RZIiwibGljZW5zZWVOYW1lIjoiVW5pdmVyc2l0YXMgTmVnZXJpIE1hbGFuZyIsImxpY2Vuc2VlVHlwZSI6IkNMQVNTUk9PTSIsImFzc2lnbmVlTmFtZSI6IkpldOWFqOWutuahtiDorqTlh4blupflkI0iLCJhc3NpZ25lZUVtYWlsIjoibm......
  • KubeSphere 社区双周报| 2024.08.30-09.12
    KubeSphere社区双周报主要整理展示新增的贡献者名单和证书、新增的讲师证书以及两周内提交过commit的贡献者,并对近期重要的PR进行解析,同时还包含了线上/线下活动和布道推广等一系列社区动态。本次双周报涵盖时间为:2024.08.30-09.12。贡献者名单近期重要更新KubeSphereK......
  • 【2024-09-11】娃有诉求
    20:00天可补,海可填,南山可移。日月既往,不可复追。                                              ——曾国藩昨晚下班回到家已经晚上11点了,客厅灯是关着的,说明孩子们跟奶奶都......