2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)

本文解析了四道算法题目,包括简单的数学运算、前后缀加位运算、贪心算法及数学题结合公式的应用。通过实际代码展示了如何高效解决这些问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

点击打开链接

A.水题

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long LL;
int main()
{
    LL a[20];
    for(int i=1;i<=15;i++)
    {
        a[i]=1;
        for(int j=1;j<=i;j++)
            a[i]*=i;
        //cout<<a[i]<<endl;
    }
    LL k;
    while(scanf("%lld",&k)==1)
    {
        int ans=0;
        for(int i=1;i<=15;i++)
            if(k>=a[i]) ans++;
            else break;
        printf("%d\n",ans);
    }
    return 0;
}

E.前后缀+位运算

#include<iostream>
#include<cstdio>
using namespace std;
const int maxn=1e5+5;
int a[maxn];
int main()
{
    int n,q;
    while(scanf("%d%d",&n,&q)==2)
    {
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        int x[maxn],y[maxn],z[maxn];
        int x2[maxn],y2[maxn],z2[maxn];
        x[1]=y[1]=z[1]=a[1];
        x2[n]=y2[n]=z2[n]=a[n];
        for(int i=2;i<=n;i++)
        {
            x[i]=x[i-1] & a[i];
            y[i]=y[i-1] | a[i];
            z[i]=z[i-1] ^ a[i];
        }
        for(int i=n-1;i>=1;i--)
        {
            x2[i]=x2[i+1] & a[i];
            y2[i]=y2[i+1] | a[i];
            z2[i]=z2[i+1] ^ a[i];
        }
        while(q--)
        {
            int p;
            scanf("%d",&p);
            if(p==1) printf("%d %d %d\n",x2[2],y2[2],z2[2]);
            else if(p==n) printf("%d %d %d\n",x[n-1],y[n-1],z[n-1]);
                    else printf("%d %d %d\n",x[p-1] & x2[p+1],y[p-1] | y2[p+1],z[p-1] ^ z2[p+1]);
        }
    }
    return 0;
}

G.贪心

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=1e6+5;
int done[maxn];
int main()
{
    int n;
    while(scanf("%d",&n)==1)
    {
        memset(done,0,sizeof(done));
        for(int i=0;i<n;i++)
        {
            int k;
            scanf("%d",&k);
            done[k]++;
        }
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            ans+=(done[i]/2);
            done[i]%=2;
            if(i+1<n) {
                if(done[i]&&done[i+1]%2&&done[i+2])
                {
                    ans++;
                    done[i]--;
                    done[i+1]--;
                    done[i+2]--;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

H.数学题+推公式

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long LL;
LL pow_mod(LL a,LL b,LL MOD)
{
    LL ans=1;
    while(b)
    {
        if(b&1) ans=ans*a%MOD;
        b>>=1,a=a*a%MOD;
    }
    return ans;
}
int main()
{
    LL n,a;
    while(scanf("%lld%lld",&n,&a)==2)
    {
        LL MOD=1<<n,pos=ceil((double)n/a);
        if(a&1) printf("1\n");
        else {
            //b<n
            LL ans=0;
            for(int i=1;i<=n;i++)
                if(pow_mod(a,i,MOD)==pow_mod(i,a,MOD)) ans++;
            //b>n    xa>=n
            LL res,p=1<<pos;
            res=MOD/p-n/p;
            ans+=res;
            printf("%lld\n",ans);
        }
    }
    return 0;
}

### 关于陕西省 CCPC 历年比题目下载 要获取陕西省 CCPC(中国大学生程序设计竞)历年比的题目,可以通过以下几种途径实现: #### 1. **官方渠道** 许多省级或区域性的程序设计竞会通过官方网站发布历年的题目和解题报告。对于陕西省 CCPC 的情况,可以访问其官网或者主办单位的相关页面寻找资源[^1]。 如果无法找到特定的比网站,则可尝试联系事主办方,例如高校计算机学院或其他承办机构,询问是否有公开的历史资料库可供查阅。 #### 2. **在线平台** 一些知名的编程竞技学习平台上也可能收录了部分历史题。以下是几个可能包含这些资源的地方: - **Codeforces Gym**: Codeforces 是国际知名算法训练平台之一,在它的Gym模块里经常会有各国各地区的ACM/ICPC系列事重制版供选手练习。 - **洛谷 (Luogu)**: 这是国内非常流行的OI&ACM风格试题分享站点,其中也整理了不少国内重要比如CCPC、蓝桥杯等的经典真题集锦。 注意:并非所有比都会被上传到此类第三方服务中;即使存在对应标签下的某些场次记录,仍需确认具体哪一年份属于陕西区范围内的正式活动而非其他省份邀请性质加试版本。 #### 3. **社区论坛与博客文章** 除了专门针对某项比设立固定存档外,还有不少个人爱好者会在技术交流圈子里发表关于自己参经历的文章并附带原题链接地址。比如优快云博文区就有大量程序员撰写的经验贴子提到过如何准备以及回顾过往挑战过程中的经典案例分析。 另外还可以关注像牛客网这样的职业发展型社交网络,在这里聚集了许多对未来从事软件开发感兴趣的学生群体他们之间互相讨论解答疑惑的同时也会不定期推出模拟测试环节重现真实考场环境帮助大家积累实战经验从而提高竞争力水平。 --- ```python import requests from bs4 import BeautifulSoup def fetch_contest_problems(contest_url): """ A function to scrape and download contest problems from a given URL. Args: contest_url (str): The web address of the target competition page. Returns: list[str]: List containing problem statements as strings. """ try: response = requests.get(contest_url) soup = BeautifulSoup(response.text, 'html.parser') # Assuming that each problem is inside an element with class `problem-statement` problems = [] for elem in soup.find_all(class_='problem-statement'): problems.append(elem.get_text(strip=True)) return problems except Exception as e: print(f"Error fetching data: {e}") return [] # Example usage contest_link = "https://example.com/shaanxi_ccpc_2022" problems_list = fetch_contest_problems(contest_link) if problems_list: for idx, prob in enumerate(problems_list[:5], start=1): print(f"{idx}. Problem Statement:\n{prob}\n{'-'*80}") else: print("No problems found or unable to retrieve them.") ``` 此脚本展示了如何利用Python爬虫抓取指定网页上的竞题目内容作为示例代码提供给提问者参考使用以便自行探索更多潜在可用的数据源位置。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值